@@ -51,17 +51,23 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
5151
5252
5353####################################
54+ # Geometric Transforms
55+ # --------------------
56+ # Geometric image transformation refers to the process of altering the geometric properties of an image,
57+ # such as its shape, size, orientation, or position.
58+ # It involves applying mathematical operations to the image pixels or coordinates to achieve the desired transformation.
59+ #
5460# Pad
55- # ---
61+ # ~~~
5662# The :class:`~torchvision.transforms.Pad` transform
5763# (see also :func:`~torchvision.transforms.functional.pad`)
58- # fills image borders with some pixel values.
64+ # pads all image borders with some pixel values.
5965padded_imgs = [T .Pad (padding = padding )(orig_img ) for padding in (3 , 10 , 30 , 50 )]
6066plot (padded_imgs )
6167
6268####################################
6369# Resize
64- # ------
70+ # ~~~~~~
6571# The :class:`~torchvision.transforms.Resize` transform
6672# (see also :func:`~torchvision.transforms.functional.resize`)
6773# resizes an image.
@@ -70,7 +76,7 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
7076
7177####################################
7278# CenterCrop
73- # ----------
79+ # ~~~~~~~~~~
7480# The :class:`~torchvision.transforms.CenterCrop` transform
7581# (see also :func:`~torchvision.transforms.functional.center_crop`)
7682# crops the given image at the center.
@@ -79,46 +85,13 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
7985
8086####################################
8187# FiveCrop
82- # --------
88+ # ~~~~~~~~
8389# The :class:`~torchvision.transforms.FiveCrop` transform
8490# (see also :func:`~torchvision.transforms.functional.five_crop`)
8591# crops the given image into four corners and the central crop.
8692(top_left , top_right , bottom_left , bottom_right , center ) = T .FiveCrop (size = (100 , 100 ))(orig_img )
8793plot ([top_left , top_right , bottom_left , bottom_right , center ])
8894
89- ####################################
90- # Grayscale
91- # ---------
92- # The :class:`~torchvision.transforms.Grayscale` transform
93- # (see also :func:`~torchvision.transforms.functional.to_grayscale`)
94- # converts an image to grayscale
95- gray_img = T .Grayscale ()(orig_img )
96- plot ([gray_img ], cmap = 'gray' )
97-
98- ####################################
99- # Random transforms
100- # -----------------
101- # The following transforms are random, which means that the same transfomer
102- # instance will produce different result each time it transforms a given image.
103- #
104- # ColorJitter
105- # ~~~~~~~~~~~
106- # The :class:`~torchvision.transforms.ColorJitter` transform
107- # randomly changes the brightness, saturation, and other properties of an image.
108- jitter = T .ColorJitter (brightness = .5 , hue = .3 )
109- jitted_imgs = [jitter (orig_img ) for _ in range (4 )]
110- plot (jitted_imgs )
111-
112- ####################################
113- # GaussianBlur
114- # ~~~~~~~~~~~~
115- # The :class:`~torchvision.transforms.GaussianBlur` transform
116- # (see also :func:`~torchvision.transforms.functional.gaussian_blur`)
117- # performs gaussian blur transform on an image.
118- blurrer = T .GaussianBlur (kernel_size = (5 , 9 ), sigma = (0.1 , 5 ))
119- blurred_imgs = [blurrer (orig_img ) for _ in range (4 )]
120- plot (blurred_imgs )
121-
12295####################################
12396# RandomPerspective
12497# ~~~~~~~~~~~~~~~~~
@@ -181,6 +154,45 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
181154resized_crops = [resize_cropper (orig_img ) for _ in range (4 )]
182155plot (resized_crops )
183156
157+ ####################################
158+ # Photometric Transforms
159+ # ----------------------
160+ # Photometric image transformation refers to the process of modifying the photometric properties of an image,
161+ # such as its brightness, contrast, color, or tone.
162+ # These transformations are applied to change the visual appearance of an image
163+ # while preserving its geometric structure.
164+ #
165+ # Except :class:`~torchvision.transforms.Grayscale`, the following transforms are random,
166+ # which means that the same transform
167+ # instance will produce different result each time it transforms a given image.
168+ #
169+ # Grayscale
170+ # ~~~~~~~~~
171+ # The :class:`~torchvision.transforms.Grayscale` transform
172+ # (see also :func:`~torchvision.transforms.functional.to_grayscale`)
173+ # converts an image to grayscale
174+ gray_img = T .Grayscale ()(orig_img )
175+ plot ([gray_img ], cmap = 'gray' )
176+
177+ ####################################
178+ # ColorJitter
179+ # ~~~~~~~~~~~
180+ # The :class:`~torchvision.transforms.ColorJitter` transform
181+ # randomly changes the brightness, contrast, saturation, hue, and other properties of an image.
182+ jitter = T .ColorJitter (brightness = .5 , hue = .3 )
183+ jitted_imgs = [jitter (orig_img ) for _ in range (4 )]
184+ plot (jitted_imgs )
185+
186+ ####################################
187+ # GaussianBlur
188+ # ~~~~~~~~~~~~
189+ # The :class:`~torchvision.transforms.GaussianBlur` transform
190+ # (see also :func:`~torchvision.transforms.functional.gaussian_blur`)
191+ # performs gaussian blur transform on an image.
192+ blurrer = T .GaussianBlur (kernel_size = (5 , 9 ), sigma = (0.1 , 5 ))
193+ blurred_imgs = [blurrer (orig_img ) for _ in range (4 )]
194+ plot (blurred_imgs )
195+
184196####################################
185197# RandomInvert
186198# ~~~~~~~~~~~~
@@ -244,6 +256,11 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
244256plot (equalized_imgs )
245257
246258####################################
259+ # Augmentation Transforms
260+ # -----------------------
261+ # The following transforms are combinations of multiple transforms,
262+ # either geometric or photometric, or both.
263+ #
247264# AutoAugment
248265# ~~~~~~~~~~~
249266# The :class:`~torchvision.transforms.AutoAugment` transform
@@ -261,34 +278,36 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
261278####################################
262279# RandAugment
263280# ~~~~~~~~~~~
264- # The :class:`~torchvision.transforms.RandAugment` transform automatically augments the data .
281+ # The :class:`~torchvision.transforms.RandAugment` is an alternate version of AutoAugment .
265282augmenter = T .RandAugment ()
266283imgs = [augmenter (orig_img ) for _ in range (4 )]
267284plot (imgs )
268285
269286####################################
270287# TrivialAugmentWide
271288# ~~~~~~~~~~~~~~~~~~
272- # The :class:`~torchvision.transforms.TrivialAugmentWide` transform automatically augments the data.
289+ # The :class:`~torchvision.transforms.TrivialAugmentWide` is an alternate implementation of AutoAugment.
290+ # However, instead of transforming an image multiple times, it transforms an image only once
291+ # using a random transform from a given list with a random strength number.
273292augmenter = T .TrivialAugmentWide ()
274293imgs = [augmenter (orig_img ) for _ in range (4 )]
275294plot (imgs )
276295
277296####################################
278297# AugMix
279298# ~~~~~~
280- # The :class:`~torchvision.transforms.AugMix` transform automatically augments the data .
299+ # The :class:`~torchvision.transforms.AugMix` transform interpolates between augmented versions of an image .
281300augmenter = T .AugMix ()
282301imgs = [augmenter (orig_img ) for _ in range (4 )]
283302plot (imgs )
284303
285304####################################
286- # Randomly-applied transforms
305+ # Randomly-applied Transforms
287306# ---------------------------
288307#
289- # Some transforms are randomly-applied given a probability ``p``. That is, the
290- # transformed image may actually be the same as the original one, even when
291- # called with the same transformer instance!
308+ # The following transforms are randomly-applied given a probability ``p``. That is, given ``p = 0.5``,
309+ # there is a 50% chance to return the original image, and a 50% chance to return the transformed image,
310+ # even when called with the same transform instance!
292311#
293312# RandomHorizontalFlip
294313# ~~~~~~~~~~~~~~~~~~~~
0 commit comments