@@ -153,6 +153,18 @@ def get_features_from_image_auto_studio_setings(self, img):
153153 return get_features_from_image_with_studio_mode (img , self .resizeMode , self .dim [0 ], self .dim [1 ], self .isGrayscale )
154154
155155
156+ def resize_image (image , size ):
157+ """Resize an image to the given size using a common interpolation method.
158+
159+ Args:
160+ image: The input image as a NumPy array.
161+ size: A tuple (width, height) specifying the desired output size.
162+
163+ Returns:
164+ The resized image as a NumPy array.
165+ """
166+ return cv2 .resize (image , size , interpolation = cv2 .INTER_AREA )
167+
156168def resize_with_letterbox (image , target_width , target_height ):
157169 """Resize an image while maintaining aspect ratio using letterboxing.
158170
@@ -180,7 +192,7 @@ def resize_with_letterbox(image, target_width, target_height):
180192 right_pad = target_width - new_width - left_pad
181193
182194 # Resize image and add padding
183- resized_image = cv2 . resize (image , (new_width , new_height ))
195+ resized_image = resize_image (image , (new_width , new_height ))
184196 padded_image = cv2 .copyMakeBorder (resized_image , top_pad , bottom_pad , left_pad , right_pad , cv2 .BORDER_CONSTANT , value = 0 )
185197
186198 return padded_image
@@ -225,7 +237,7 @@ def get_features_from_image_with_studio_mode(img, mode, output_width, output_hei
225237 elif mode == 'fit-longest' :
226238 resized_img = resize_with_letterbox (img , output_width , output_height )
227239 elif mode == 'squash' :
228- resized_img = cv2 . resize (img , (output_width , output_height ), interpolation = cv2 . INTER_AREA )
240+ resized_img = resize_image (img , (output_width , output_height ))
229241 else :
230242 raise ValueError (f"Unsupported mode: { mode } " )
231243
0 commit comments