@@ -84,7 +84,7 @@ def threading_data(data=None, fn=None, **kwargs):
84
84
# exit()
85
85
# define function for threading
86
86
def apply_fn (results , i , data , kwargs ):
87
- results [i ] = fn (data , ** kwargs )
87
+ results [i ] = fn (data , ** kwargs )
88
88
89
89
## start multi-threaded reading.
90
90
results = [None ] * len (data ) ## preallocate result list
@@ -236,12 +236,19 @@ def crop(x, wrg, hrg, is_random=False, row_index=0, col_index=1, channel_index=2
236
236
w_offset = int (np .random .uniform (0 , w - wrg ) - 1 )
237
237
# print(h_offset, w_offset, x[h_offset: hrg+h_offset ,w_offset: wrg+w_offset].shape)
238
238
return x [h_offset : hrg + h_offset ,w_offset : wrg + w_offset ]
239
- else :
239
+ else : # central crop
240
+ h_offset = int (np .floor ((h - hrg )/ 2. ))
241
+ w_offset = int (np .floor ((w - wrg )/ 2. ))
242
+ h_end = h_offset + hrg
243
+ w_end = w_offset + wrg
244
+ return x [h_offset : h_end , w_offset : w_end ]
245
+ # old implementation
246
+ # h_offset = (h - hrg)/2
247
+ # w_offset = (w - wrg)/2
248
+ # # print(x[h_offset: h-h_offset ,w_offset: w-w_offset].shape)
249
+ # return x[h_offset: h-h_offset ,w_offset: w-w_offset]
240
250
# central crop
241
- h_offset = (h - hrg )/ 2
242
- w_offset = (w - wrg )/ 2
243
- # print(x[h_offset: h-h_offset ,w_offset: w-w_offset].shape)
244
- return x [h_offset : h - h_offset ,w_offset : w - w_offset ]
251
+
245
252
246
253
def crop_multi (x , wrg , hrg , is_random = False , row_index = 0 , col_index = 1 , channel_index = 2 ):
247
254
"""Randomly or centrally crop multiple images.
0 commit comments