INTER_AREA ) print ( 'Resized Dimensions : ', resized_h. resize ( img, dim, interpolation = cv2. shape # keep original width height = 440 dim = ( width, height ) # resize image resized_h = cv2. imwrite ( 'root/vidhi/resize.png', resized_w ) #resize only height width = img. INTER_AREA ) print ( 'Resized Dimensions : ', resized_w. shape # keep original height dim = ( width, height ) # resize image resized_w = cv2. imwrite ( 'root/vidhi/resize.png', resized_up ) #resize only width width = 440 height = img. INTER_AREA ) print ( 'Resized Dimensions : ', resized_up. shape * scale_percent / 100 ) dim = ( width, height ) # resize image in up scale resized_up = cv2. shape * scale_percent / 100 ) height = int ( img. imwrite ( '/root/vidhi/resize.png', resized ) #upscaling scale_percent = 220 # percent of original size width = int ( img. INTER_AREA ) print ( 'Resized Dimensions : ', resized. shape * scale_percent / 100 ) dim = ( width, height ) # resize image in down scale resized = cv2. shape ) #Downscaling scale_percent = 60 # percent of original size width = int ( img. IMREAD_UNCHANGED ) print ( ‘ Original Dimensions : ’, img. This is the combined output of all the resized Images: Output: The Original dimensions are: (99, 194, 4) The resized dimensions are: (450, 350, 4) Print('Resized Dimensions : ',resized_hw.shape)Ĭv2.imwrite('/root/vidhi/resize_hw.png', resized_hw) Resized_hw = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) Resize to specific width and height: In following code we will providing the specific height and width. Output: The Original dimensions are: (99, 194, 4) The resized dimensions are: (440, 194, 4)ģ. Print('Resized Dimensions : ',resized_h.shape)Ĭv2.imwrite'/root/vidhi/resize_h.png', resized_h) Resized_h = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) Resizing only height: In this code we providing specific amount of height but width is not changed it will remain as it is. Output: The Original dimensions are: (99, 194, 4) The resized dimensions are:(99, 440, 4)ī. Print('Resized Dimensions : ',resized_w.shape)Ĭv2.imwrite('root/vidhi/resize_w.png', resized_w) Resized_w = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) Height = img.shape # keep original height Resizing only width: In this code we providing specific amount of width but height is not changed it will remain as it is. Output: The original dimensions are:(99, 194, 4) The resized dimensions are: (217, 426, 4)Ģ. Print('Resized Dimensions : ',resized_up.shape)Ĭv2.imwrite('root/vidhi/resize_up.png', resized_up) Resized_up = cv2.resize(img, dim, interpolation = cv2.INTER_AREA) Height = int(img.shape * scale_percent / 100)ĭim = (width, height) # resize image in up scale Width = int(img.shape * scale_percent / 100) For that code is given below: scale_percent = 220 # percent of original size In up scalding also the scale_percent is given to find the height and width of the output image. Downscale with resize(): In below code scale_percent is holding the value of percentage by which image has to be scaled. sudo apt-get install geditĬreate a new Python file using editor by following command: gedit filename.pyġ. Install the geditor on your system for installing you need to enable Wi-Fi. Downscale (Decreases the size of image) b. Preserved Aspect Ratio (Height to width ratio) a. Resizing an image can be done in many ways:ġ. To resize the image OpenCV provides the cv2.resize(). The following article will help you to resizing the images in python using OpenCV.Resizing an image means change the dimensions of the image change either width of it or height of it or both at the same time.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |