@@ -209,44 +209,44 @@ def pad(img, padding, fill=0):
209
209
return ImageOps .expand (img , border = padding , fill = fill )
210
210
211
211
212
- def crop (img , x , y , w , h ):
212
+ def crop (img , i , j , h , w ):
213
213
"""Crop the given PIL.Image.
214
214
215
215
Args:
216
216
img (PIL.Image): Image to be cropped.
217
- x: Left pixel coordinate.
218
- y: Upper pixel coordinate.
219
- w: Width of the cropped image.
217
+ i: Upper pixel coordinate.
218
+ j: Left pixel coordinate.
220
219
h: Height of the cropped image.
220
+ w: Width of the cropped image.
221
221
222
222
Returns:
223
223
PIL.Image: Cropped image.
224
224
"""
225
225
if not _is_pil_image (img ):
226
226
raise TypeError ('img should be PIL Image. Got {}' .format (type (img )))
227
227
228
- return img .crop ((x , y , x + w , y + h ))
228
+ return img .crop ((j , i , j + w , i + h ))
229
229
230
230
231
- def scaled_crop (img , x , y , w , h , size , interpolation = Image .BILINEAR ):
231
+ def scaled_crop (img , i , j , h , w , size , interpolation = Image .BILINEAR ):
232
232
"""Crop the given PIL.Image and scale it to desired size.
233
233
234
234
Notably used in RandomSizedCrop.
235
235
236
236
Args:
237
237
img (PIL.Image): Image to be cropped.
238
- x: Left pixel coordinate.
239
- y: Upper pixel coordinate.
240
- w: Width of the cropped image.
238
+ i: Upper pixel coordinate.
239
+ j: Left pixel coordinate.
241
240
h: Height of the cropped image.
241
+ w: Width of the cropped image.
242
242
size (sequence or int): Desired output size. Same semantics as ``scale``.
243
243
interpolation (int, optional): Desired interpolation. Default is
244
244
``PIL.Image.BILINEAR``.
245
245
Returns:
246
246
PIL.Image: Cropped image.
247
247
"""
248
248
assert _is_pil_image (img ), 'img should be PIL Image'
249
- img = crop (img , x , y , w , h )
249
+ img = crop (img , i , j , h , w )
250
250
img = scale (img , size , interpolation )
251
251
return img
252
252
@@ -406,13 +406,13 @@ def get_params(img, output_size):
406
406
output_size (tuple): Expected output size of the crop.
407
407
408
408
Returns:
409
- tuple: params (x, y, w, h ) to be passed to ``crop`` for center crop.
409
+ tuple: params (i, j, h, w ) to be passed to ``crop`` for center crop.
410
410
"""
411
411
w , h = img .size
412
412
th , tw = output_size
413
- x1 = int (round ((w - tw ) / 2. ))
414
- y1 = int (round ((h - th ) / 2. ))
415
- return x1 , y1 , tw , th
413
+ i = int (round ((h - th ) / 2. ))
414
+ j = int (round ((w - tw ) / 2. ))
415
+ return i , j , th , tw
416
416
417
417
def __call__ (self , img ):
418
418
"""
@@ -422,8 +422,8 @@ def __call__(self, img):
422
422
Returns:
423
423
PIL.Image: Cropped image.
424
424
"""
425
- x1 , y1 , tw , th = self .get_params (img , self .size )
426
- return crop (img , x1 , y1 , tw , th )
425
+ i , j , h , w = self .get_params (img , self .size )
426
+ return crop (img , i , j , h , w )
427
427
428
428
429
429
class Pad (object ):
@@ -504,16 +504,16 @@ def get_params(img, output_size):
504
504
output_size (tuple): Expected output size of the crop.
505
505
506
506
Returns:
507
- tuple: params (x, y, w, h ) to be passed to ``crop`` for random crop.
507
+ tuple: params (i, j, h, w ) to be passed to ``crop`` for random crop.
508
508
"""
509
509
w , h = img .size
510
510
th , tw = output_size
511
511
if w == tw and h == th :
512
512
return img
513
513
514
- x1 = random .randint (0 , w - tw )
515
- y1 = random .randint (0 , h - th )
516
- return x1 , y1 , tw , th
514
+ i = random .randint (0 , h - th )
515
+ j = random .randint (0 , w - tw )
516
+ return i , j , th , tw
517
517
518
518
def __call__ (self , img ):
519
519
"""
@@ -526,9 +526,9 @@ def __call__(self, img):
526
526
if self .padding > 0 :
527
527
img = pad (img , self .padding )
528
528
529
- x1 , y1 , tw , th = self .get_params (img , self .size )
529
+ i , j , h , w = self .get_params (img , self .size )
530
530
531
- return crop (img , x1 , y1 , tw , th )
531
+ return crop (img , i , j , h , w )
532
532
533
533
534
534
class RandomHorizontalFlip (object ):
@@ -572,7 +572,7 @@ def get_params(img):
572
572
img (PIL.Image): Image to be cropped.
573
573
574
574
Returns:
575
- tuple: params (x, y, w, h ) to be passed to ``crop`` for a random
575
+ tuple: params (i, j, h, w ) to be passed to ``crop`` for a random
576
576
sized crop.
577
577
"""
578
578
for attempt in range (10 ):
@@ -587,15 +587,15 @@ def get_params(img):
587
587
w , h = h , w
588
588
589
589
if w <= img .size [0 ] and h <= img .size [1 ]:
590
- x = random .randint (0 , img .size [0 ] - w )
591
- y = random .randint (0 , img .size [1 ] - h )
592
- return x , y , w , h
590
+ i = random .randint (0 , img .size [1 ] - h )
591
+ j = random .randint (0 , img .size [0 ] - w )
592
+ return i , j , h , w
593
593
594
594
# Fallback
595
595
w = min (img .size [0 ], img .shape [1 ])
596
- x = (img .shape [0 ] - w ) // 2
597
- y = (img .shape [1 ] - w ) // 2
598
- return x , y , w , w
596
+ i = (img .shape [1 ] - w ) // 2
597
+ j = (img .shape [0 ] - w ) // 2
598
+ return i , j , w , w
599
599
600
600
def __call__ (self , img ):
601
601
"""
@@ -605,5 +605,5 @@ def __call__(self, img):
605
605
Returns:
606
606
PIL.Image: Randomly cropped and scaled image.
607
607
"""
608
- x , y , w , h = self .get_params (img )
609
- return scaled_crop (img , x , y , w , h , self .size , self .interpolation )
608
+ i , j , h , w = self .get_params (img )
609
+ return scaled_crop (img , i , j , h , w , self .size , self .interpolation )
0 commit comments