Some Skills on Image Processing

Image Pre-processing/Transformation

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
train_tfm = transforms.Compose([
    # Resize the images into the fixed size
    transforms.Resize((128, 128)),

    '''
    Do some Image Enhancement
    '''

    # ToTensor() should be the last transformation
    transforms.ToTensor(),
])

Geometric Transformations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
# Rotation
transform_rotate = transforms.RandomRotation(degrees=30)

# Translation
transform_translate = transforms.RandomAffine(degrees=0, translate=(0.1, 0.1))

# Flipping
transform_flip = transforms.RandomHorizontalFlip(p=0.5)

# Scaling
transform_scale = transforms.RandomResizedCrop(size=224, scale=(0.8, 1.0))

# Shearing
transform_shear = transforms.RandomAffine(degrees=0, shear=20)

Color Transformations

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
# Brightness Adjustment
transform_brightness = transforms.ColorJitter(brightness=0.5)

# Contrast Adjustment
transform_contrast = transforms.ColorJitter(contrast=0.5)

# Satuation Adjustment
transform_saturation = transforms.ColorJitter(saturation=0.5)

# Hue Adjustment
transform_hue = transforms.ColorJitter(hue=0.2)

Cropping and Padding

1
2
3
4
5
# Random Cropping
transform_random_crop = transforms.RandomCrop(size=224)

# Padding
transform_padding = transforms.Pad(padding=4)

Image Enhancement

1
2
# Random Erasing
transform_random_erasing = transforms.RandomErasing(p=0.5, scale=(0.02, 0.33), ratio=(0.3, 3.3), value=0)
Built with Hugo
Theme Stack designed by Jimmy