@@ -51,17 +51,23 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
51
51
52
52
53
53
####################################
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
+ #
54
60
# Pad
55
- # ---
61
+ # ~~~
56
62
# The :class:`~torchvision.transforms.Pad` transform
57
63
# (see also :func:`~torchvision.transforms.functional.pad`)
58
- # fills image borders with some pixel values.
64
+ # pads all image borders with some pixel values.
59
65
padded_imgs = [T .Pad (padding = padding )(orig_img ) for padding in (3 , 10 , 30 , 50 )]
60
66
plot (padded_imgs )
61
67
62
68
####################################
63
69
# Resize
64
- # ------
70
+ # ~~~~~~
65
71
# The :class:`~torchvision.transforms.Resize` transform
66
72
# (see also :func:`~torchvision.transforms.functional.resize`)
67
73
# resizes an image.
@@ -70,7 +76,7 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
70
76
71
77
####################################
72
78
# CenterCrop
73
- # ----------
79
+ # ~~~~~~~~~~
74
80
# The :class:`~torchvision.transforms.CenterCrop` transform
75
81
# (see also :func:`~torchvision.transforms.functional.center_crop`)
76
82
# crops the given image at the center.
@@ -79,46 +85,13 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
79
85
80
86
####################################
81
87
# FiveCrop
82
- # --------
88
+ # ~~~~~~~~
83
89
# The :class:`~torchvision.transforms.FiveCrop` transform
84
90
# (see also :func:`~torchvision.transforms.functional.five_crop`)
85
91
# crops the given image into four corners and the central crop.
86
92
(top_left , top_right , bottom_left , bottom_right , center ) = T .FiveCrop (size = (100 , 100 ))(orig_img )
87
93
plot ([top_left , top_right , bottom_left , bottom_right , center ])
88
94
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
-
122
95
####################################
123
96
# RandomPerspective
124
97
# ~~~~~~~~~~~~~~~~~
@@ -181,6 +154,45 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
181
154
resized_crops = [resize_cropper (orig_img ) for _ in range (4 )]
182
155
plot (resized_crops )
183
156
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
+
184
196
####################################
185
197
# RandomInvert
186
198
# ~~~~~~~~~~~~
@@ -244,6 +256,11 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
244
256
plot (equalized_imgs )
245
257
246
258
####################################
259
+ # Augmentation Transforms
260
+ # -----------------------
261
+ # The following transforms are combinations of multiple transforms,
262
+ # either geometric or photometric, or both.
263
+ #
247
264
# AutoAugment
248
265
# ~~~~~~~~~~~
249
266
# The :class:`~torchvision.transforms.AutoAugment` transform
@@ -261,34 +278,36 @@ def plot(imgs, with_orig=True, row_title=None, **imshow_kwargs):
261
278
####################################
262
279
# RandAugment
263
280
# ~~~~~~~~~~~
264
- # The :class:`~torchvision.transforms.RandAugment` transform automatically augments the data .
281
+ # The :class:`~torchvision.transforms.RandAugment` is an alternate version of AutoAugment .
265
282
augmenter = T .RandAugment ()
266
283
imgs = [augmenter (orig_img ) for _ in range (4 )]
267
284
plot (imgs )
268
285
269
286
####################################
270
287
# TrivialAugmentWide
271
288
# ~~~~~~~~~~~~~~~~~~
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.
273
292
augmenter = T .TrivialAugmentWide ()
274
293
imgs = [augmenter (orig_img ) for _ in range (4 )]
275
294
plot (imgs )
276
295
277
296
####################################
278
297
# AugMix
279
298
# ~~~~~~
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 .
281
300
augmenter = T .AugMix ()
282
301
imgs = [augmenter (orig_img ) for _ in range (4 )]
283
302
plot (imgs )
284
303
285
304
####################################
286
- # Randomly-applied transforms
305
+ # Randomly-applied Transforms
287
306
# ---------------------------
288
307
#
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!
292
311
#
293
312
# RandomHorizontalFlip
294
313
# ~~~~~~~~~~~~~~~~~~~~
0 commit comments