Skip to content

Commit 2cc58ed

Browse files
committed
change x,y,w,h -> i,j,h,w
1 parent 47800d4 commit 2cc58ed

File tree

1 file changed

+31
-31
lines changed

1 file changed

+31
-31
lines changed

torchvision/transforms.py

Lines changed: 31 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -209,44 +209,44 @@ def pad(img, padding, fill=0):
209209
return ImageOps.expand(img, border=padding, fill=fill)
210210

211211

212-
def crop(img, x, y, w, h):
212+
def crop(img, i, j, h, w):
213213
"""Crop the given PIL.Image.
214214
215215
Args:
216216
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.
220219
h: Height of the cropped image.
220+
w: Width of the cropped image.
221221
222222
Returns:
223223
PIL.Image: Cropped image.
224224
"""
225225
if not _is_pil_image(img):
226226
raise TypeError('img should be PIL Image. Got {}'.format(type(img)))
227227

228-
return img.crop((x, y, x + w, y + h))
228+
return img.crop((j, i, j + w, i + h))
229229

230230

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):
232232
"""Crop the given PIL.Image and scale it to desired size.
233233
234234
Notably used in RandomSizedCrop.
235235
236236
Args:
237237
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.
241240
h: Height of the cropped image.
241+
w: Width of the cropped image.
242242
size (sequence or int): Desired output size. Same semantics as ``scale``.
243243
interpolation (int, optional): Desired interpolation. Default is
244244
``PIL.Image.BILINEAR``.
245245
Returns:
246246
PIL.Image: Cropped image.
247247
"""
248248
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)
250250
img = scale(img, size, interpolation)
251251
return img
252252

@@ -406,13 +406,13 @@ def get_params(img, output_size):
406406
output_size (tuple): Expected output size of the crop.
407407
408408
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.
410410
"""
411411
w, h = img.size
412412
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
416416

417417
def __call__(self, img):
418418
"""
@@ -422,8 +422,8 @@ def __call__(self, img):
422422
Returns:
423423
PIL.Image: Cropped image.
424424
"""
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)
427427

428428

429429
class Pad(object):
@@ -504,16 +504,16 @@ def get_params(img, output_size):
504504
output_size (tuple): Expected output size of the crop.
505505
506506
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.
508508
"""
509509
w, h = img.size
510510
th, tw = output_size
511511
if w == tw and h == th:
512512
return img
513513

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
517517

518518
def __call__(self, img):
519519
"""
@@ -526,9 +526,9 @@ def __call__(self, img):
526526
if self.padding > 0:
527527
img = pad(img, self.padding)
528528

529-
x1, y1, tw, th = self.get_params(img, self.size)
529+
i, j, h, w = self.get_params(img, self.size)
530530

531-
return crop(img, x1, y1, tw, th)
531+
return crop(img, i, j, h, w)
532532

533533

534534
class RandomHorizontalFlip(object):
@@ -572,7 +572,7 @@ def get_params(img):
572572
img (PIL.Image): Image to be cropped.
573573
574574
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
576576
sized crop.
577577
"""
578578
for attempt in range(10):
@@ -587,15 +587,15 @@ def get_params(img):
587587
w, h = h, w
588588

589589
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
593593

594594
# Fallback
595595
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
599599

600600
def __call__(self, img):
601601
"""
@@ -605,5 +605,5 @@ def __call__(self, img):
605605
Returns:
606606
PIL.Image: Randomly cropped and scaled image.
607607
"""
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

Comments
 (0)