@@ -395,7 +395,10 @@ def pad(img: Tensor, padding: List[int], fill: int = 0, padding_mode: str = "con
395
395
396
396
397
397
def crop (img : Tensor , top : int , left : int , height : int , width : int ) -> Tensor :
398
- """Crop the given PIL Image.
398
+ """Crop the given image at specified location and output size.
399
+ The image can be a PIL Image or a Tensor, in which case it is expected
400
+ to have [..., H, W] shape, where ... means an arbitrary number of leading
401
+ dimensions
399
402
400
403
Args:
401
404
img (PIL Image or Tensor): Image to be cropped. (0,0) denotes the top left corner of the image.
@@ -416,13 +419,13 @@ def crop(img: Tensor, top: int, left: int, height: int, width: int) -> Tensor:
416
419
417
420
def center_crop (img : Tensor , output_size : List [int ]) -> Tensor :
418
421
"""Crops the given image at the center.
419
- The image can be a PIL Image or a torch Tensor, in which case it is expected
422
+ The image can be a PIL Image or a Tensor, in which case it is expected
420
423
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
421
424
422
425
Args:
423
426
img (PIL Image or Tensor): Image to be cropped.
424
427
output_size (sequence or int): (height, width) of the crop box. If int or sequence with single int
425
- it is used for both directions
428
+ it is used for both directions.
426
429
427
430
Returns:
428
431
PIL Image or Tensor: Cropped image.
@@ -469,7 +472,7 @@ def resized_crop(img, top, left, height, width, size, interpolation=Image.BILINE
469
472
470
473
471
474
def hflip (img : Tensor ) -> Tensor :
472
- """Horizontally flip the given PIL Image or torch Tensor.
475
+ """Horizontally flip the given PIL Image or Tensor.
473
476
474
477
Args:
475
478
img (PIL Image or Tensor): Image to be flipped. If img
@@ -531,8 +534,7 @@ def _get_perspective_coeffs(startpoints, endpoints):
531
534
532
535
Args:
533
536
List containing [top-left, top-right, bottom-right, bottom-left] of the original image,
534
- List containing [top-left, top-right, bottom-right, bottom-left] of the transformed
535
- image
537
+ List containing [top-left, top-right, bottom-right, bottom-left] of the transformed image
536
538
Returns:
537
539
octuple (a, b, c, d, e, f, g, h) for transforming each pixel.
538
540
"""
@@ -577,7 +579,7 @@ def vflip(img: Tensor) -> Tensor:
577
579
"""Vertically flip the given PIL Image or torch Tensor.
578
580
579
581
Args:
580
- img (PIL Image or Torch Tensor): Image to be flipped. If img
582
+ img (PIL Image or Tensor): Image to be flipped. If img
581
583
is a Tensor, it is expected to be in [..., H, W] format,
582
584
where ... means it can have an arbitrary number of trailing
583
585
dimensions.
@@ -593,17 +595,18 @@ def vflip(img: Tensor) -> Tensor:
593
595
594
596
def five_crop (img : Tensor , size : List [int ]) -> Tuple [Tensor , Tensor , Tensor , Tensor , Tensor ]:
595
597
"""Crop the given image into four corners and the central crop.
596
- The image can be a PIL Image or a torch Tensor, in which case it is expected
598
+ The image can be a PIL Image or a Tensor, in which case it is expected
597
599
to have [..., H, W] shape, where ... means an arbitrary number of leading dimensions
598
600
599
601
.. Note::
600
602
This transform returns a tuple of images and there may be a
601
603
mismatch in the number of inputs and targets your ``Dataset`` returns.
602
604
603
605
Args:
604
- size (sequence or int): Desired output size of the crop. If size is an
605
- int instead of sequence like (h, w), a square crop (size, size) is
606
- made.
606
+ img (PIL Image or Tensor): Image to be cropped.
607
+ size (sequence or int): Desired output size of the crop. If size is an
608
+ int instead of sequence like (h, w), a square crop (size, size) is
609
+ made. If provided a tuple or list of length 1, it will be interpreted as (size[0], size[0]).
607
610
608
611
Returns:
609
612
tuple: tuple (tl, tr, bl, br, center)
@@ -673,13 +676,13 @@ def adjust_brightness(img: Tensor, brightness_factor: float) -> Tensor:
673
676
"""Adjust brightness of an Image.
674
677
675
678
Args:
676
- img (PIL Image or Torch Tensor): Image to be adjusted.
679
+ img (PIL Image or Tensor): Image to be adjusted.
677
680
brightness_factor (float): How much to adjust the brightness. Can be
678
681
any non negative number. 0 gives a black image, 1 gives the
679
682
original image while 2 increases the brightness by a factor of 2.
680
683
681
684
Returns:
682
- PIL Image or Torch Tensor: Brightness adjusted image.
685
+ PIL Image or Tensor: Brightness adjusted image.
683
686
"""
684
687
if not isinstance (img , torch .Tensor ):
685
688
return F_pil .adjust_brightness (img , brightness_factor )
@@ -691,13 +694,13 @@ def adjust_contrast(img: Tensor, contrast_factor: float) -> Tensor:
691
694
"""Adjust contrast of an Image.
692
695
693
696
Args:
694
- img (PIL Image or Torch Tensor): Image to be adjusted.
697
+ img (PIL Image or Tensor): Image to be adjusted.
695
698
contrast_factor (float): How much to adjust the contrast. Can be any
696
699
non negative number. 0 gives a solid gray image, 1 gives the
697
700
original image while 2 increases the contrast by a factor of 2.
698
701
699
702
Returns:
700
- PIL Image or Torch Tensor: Contrast adjusted image.
703
+ PIL Image or Tensor: Contrast adjusted image.
701
704
"""
702
705
if not isinstance (img , torch .Tensor ):
703
706
return F_pil .adjust_contrast (img , contrast_factor )
@@ -709,13 +712,13 @@ def adjust_saturation(img: Tensor, saturation_factor: float) -> Tensor:
709
712
"""Adjust color saturation of an image.
710
713
711
714
Args:
712
- img (PIL Image or Torch Tensor): Image to be adjusted.
715
+ img (PIL Image or Tensor): Image to be adjusted.
713
716
saturation_factor (float): How much to adjust the saturation. 0 will
714
717
give a black and white image, 1 will give the original image while
715
718
2 will enhance the saturation by a factor of 2.
716
719
717
720
Returns:
718
- PIL Image or Torch Tensor: Saturation adjusted image.
721
+ PIL Image or Tensor: Saturation adjusted image.
719
722
"""
720
723
if not isinstance (img , torch .Tensor ):
721
724
return F_pil .adjust_saturation (img , saturation_factor )
0 commit comments