@@ -37,6 +37,7 @@ def _process_single_image_for_resize(image_data,
3737 target_size ,
3838 correct_size_image_handling ,
3939 unavailable_image_handling ,
40+ no_enlarge_width ,
4041 verbose ):
4142 """
4243 Processes a single image: loads, resizes/copies, updates metadata, and scales annotations.
@@ -83,6 +84,8 @@ def _process_single_image_for_resize(image_data,
8384
8485 image_is_already_target_size = \
8586 (input_w == target_size [0 ]) and (input_h == target_size [1 ])
87+ if no_enlarge_width and (input_w < target_size [0 ]):
88+ image_is_already_target_size = True
8689 preserve_original_size = \
8790 (target_size [0 ] == - 1 ) and (target_size [1 ] == - 1 )
8891
@@ -100,7 +103,8 @@ def _process_single_image_for_resize(image_data,
100103 f'Unrecognized value { correct_size_image_handling } for correct_size_image_handling' )
101104 else :
102105 try :
103- pil_im = resize_image (pil_im , target_size [0 ], target_size [1 ])
106+ pil_im = resize_image (pil_im , target_size [0 ], target_size [1 ],
107+ no_enlarge_width = no_enlarge_width )
104108 output_w = pil_im .width
105109 output_h = pil_im .height
106110 exif_preserving_save (pil_im , output_fn_abs )
@@ -146,6 +150,7 @@ def resize_coco_dataset(input_folder,
146150 unavailable_image_handling = 'error' ,
147151 n_workers = 1 ,
148152 pool_type = 'thread' ,
153+ no_enlarge_width = True ,
149154 verbose = False ):
150155 """
151156 Given a COCO-formatted dataset (images in input_folder, data in input_filename), resizes
@@ -175,6 +180,9 @@ def resize_coco_dataset(input_folder,
175180 Defaults to 1 (no parallelization). If <= 1, processing is sequential.
176181 pool_type (str, optional): type of multiprocessing pool to use ('thread' or 'process').
177182 Defaults to 'thread'. Only used if n_workers > 1.
183+ no_enlarge_width (bool, optional): if [no_enlarge_width] is True, and
184+ [target width] is larger than the original image width, does not modify the image,
185+ but still writes it
178186 verbose (bool, optional): enable additional debug output
179187
180188 Returns:
@@ -221,6 +229,7 @@ def resize_coco_dataset(input_folder,
221229 target_size = target_size ,
222230 correct_size_image_handling = correct_size_image_handling ,
223231 unavailable_image_handling = unavailable_image_handling ,
232+ no_enlarge_width = no_enlarge_width ,
224233 verbose = verbose
225234 )
226235 processed_results .append (result )
@@ -240,6 +249,7 @@ def resize_coco_dataset(input_folder,
240249 target_size = target_size ,
241250 correct_size_image_handling = correct_size_image_handling ,
242251 unavailable_image_handling = unavailable_image_handling ,
252+ no_enlarge_width = no_enlarge_width ,
243253 verbose = verbose )
244254
245255 processed_results = list (tqdm (pool .imap (p_process_image , image_annotation_tuples ),
0 commit comments