@@ -84,7 +84,7 @@ def threading_data(data=None, fn=None, **kwargs):
8484 # exit()
8585 # define function for threading
8686 def apply_fn (results , i , data , kwargs ):
87- results [i ] = fn (data , ** kwargs )
87+ results [i ] = fn (data , ** kwargs )
8888
8989 ## start multi-threaded reading.
9090 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
236236 w_offset = int (np .random .uniform (0 , w - wrg ) - 1 )
237237 # print(h_offset, w_offset, x[h_offset: hrg+h_offset ,w_offset: wrg+w_offset].shape)
238238 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]
240250 # 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+
245252
246253def crop_multi (x , wrg , hrg , is_random = False , row_index = 0 , col_index = 1 , channel_index = 2 ):
247254 """Randomly or centrally crop multiple images.
0 commit comments