reducing_gap: Apply optimization by resizing the image in two steps.(was Resampling.NEAREST prior to version 2.5.0). If omitted, it defaults to Resampling.BICUBIC. This can be one of Resampling.NEAREST, Resampling.BOX, Resampling.BILINEAR, Resampling.HAMMING, Resampling.BICUBIC or Resampling.LANCZOS. size: The requested size in pixels, as a 2-tuple: (width, height).This method modifies the image to contain a thumbnail version of itself, no larger than the given size. Image.thumbnail(size, resample = Resampling. INTER_AREA ) # print the old and new shape print ( f "old shape: " ) Syntaxįor the syntax of cv2.resize() and (), please see the previous tutorial: Python | Resize Image | OpenCV vs Pillow. shrink by max size max_width = 256 max_height = 256 height, width = cv2_img.shape scale_ratio = min (max_width / width, max_height / height, 1 ) # use min(., 1) to disallow enlargement # reuse the code of resizing by scale ratio: new_width = int (cv2_img.shape * scale_ratio) new_height = int (cv2_img.shape * scale_ratio) new_size = (new_width, new_height) cv2_img_thumbnail = cv2.resize(cv2_img, new_size, interpolation = cv2. resize to fit a max size max_width = 256 max_height = 256 height, width = cv2_img.shape scale_ratio = min (max_width / width, max_height / height) # reuse the code of resizing by scale ratio: new_width = int (cv2_img.shape * scale_ratio) new_height = int (cv2_img.shape * scale_ratio) new_size = (new_width, new_height) cv2_img_resized_2 = cv2.resize(cv2_img, new_size, interpolation = cv2. resize by scale ratio scale_ratio = 0.6 new_width = int (cv2_img.shape * scale_ratio) new_height = int (cv2_img.shape * scale_ratio) new_size = (new_width, new_height) cv2_img_resized_1 = cv2.resize(cv2_img, new_size, interpolation = cv2. Import cv2 # read image cv2_img = cv2.imread( " test_images/test1.jpg " ) # 1.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |