We present the different techniques that can be applied to augment a dataset of images. In order to generate the samples presented in this section, it is necessary to load some libraries.
from clodsa.techniques.techniqueFactory import createTechnique
import cv2
import numpy as np
img = cv2.imread("images/cat1.jpg")
Smoothes the image using an average filter.
t = createTechnique("average_blurring", {"kernel" : 5})
img1 = t.apply(img)
cv2.imwrite("average_blurring.jpg",np.hstack([img,img1]))
Applies bilateral blurring to the image.
t = createTechnique("bilateral_blurring", {"diameter" : 11, "sigmaColor": 21, "sigmaSpace":7})
img1 = t.apply(img)
cv2.imwrite("bilateral_blurring.jpg",np.hstack([img,img1]))
Blurs an image using the normalized box filter.
t = createTechnique("blurring", {"ksize" : 5})
img1 = t.apply(img)
cv2.imwrite("blurring.jpg",np.hstack([img,img1]))
Changes the color space from RGB to HSV.
t = createTechnique("change_to_hsv",{})
img1 = t.apply(img)
cv2.imwrite("change_to_hsv.jpg",np.hstack([img,img1]))
Changes the color space from RGB to LAB.
t = createTechnique("change_to_lab",{})
img1 = t.apply(img)
cv2.imwrite("change_to_lab.jpg",np.hstack([img,img1]))
Crops pixels at the sides of the image.
t = createTechnique("crop",{"percentage":0.8,"startFrom": "TOPLEFT"})
img1 = t.apply(img)
cv2.imwrite("crop.jpg",img1)
Sets some pixels in the image to zero.
t = createTechnique("dropout",{"percentage":0.05})
img1 = t.apply(img)
cv2.imwrite("dropout.jpg",np.hstack([img,img1]))
Applies elastic deformation as explained in the paper: P. Simard, D. Steinkraus, and J. C. Platt. Best practices for convolutional neural networks applied to visual document analysis. Proceedings of the 12th International Conference on Document Analysis and Recognition (ICDAR'03) vol. 2, pp. 958--964. IEEE Computer Society. 2003.
t = createTechnique("elastic",{"alpha":5,"sigma":0.05})
img1 = t.apply(img)
cv2.imwrite("elastic.jpg",np.hstack([img,img1]))
Applies histogram equalization to the image.
t = createTechnique("equalize_histogram",{})
img1 = t.apply(img)
cv2.imwrite("equalize.jpg",np.hstack([img,img1]))
Flips the image horizontally, vertically or both.
t = createTechnique("flip",{"flip":0})
t1 = createTechnique("flip",{"flip":1})
t2 = createTechnique("flip",{"flip":-1})
img1 = t.apply(img)
img2 = t1.apply(img)
img3 = t2.apply(img)
cv2.imwrite("flip.jpg",np.hstack([img,img1,img2,img3]))
Applies gamma correction to the image.
t = createTechnique("gamma",{"gamma":1.5})
img1 = t.apply(img)
cv2.imwrite("gamma.jpg",np.hstack([img,img1]))
Blurs an image using a Gaussian filter.
t = createTechnique("gaussian_blur", {"kernel" : 5})
img1 = t.apply(img)
cv2.imwrite("gaussian_blurring.jpg",np.hstack([img,img1]))
Adds Gaussian noise to the image.
t = createTechnique("gaussian_noise", {"mean" : 0,"sigma":10})
img1 = t.apply(img)
cv2.imwrite("gaussian_noise.jpg",np.hstack([img,img1]))
Inverts all values in images, i.e. sets a pixel from value v to 255-v
t = createTechnique("invert",{})
img1 = t.apply(img)
cv2.imwrite("invert.jpg",np.hstack([img,img1]))
Blurs an image using the median filter.
t = createTechnique("median_blur", {"kernel" : 5})
img1 = t.apply(img)
cv2.imwrite("median_blurring.jpg",np.hstack([img,img1]))
This augmentation technique does not change the image.
t = createTechnique("none",{})
img1 = t.apply(img)
cv2.imwrite("none.jpg",np.hstack([img,img1]))
Raises the values in the blue channel.
t = createTechnique("raise_blue", {"power" : 0.9})
img1 = t.apply(img)
cv2.imwrite("raise_blue.jpg",np.hstack([img,img1]))
Raises the values in the green channel.
t = createTechnique("raise_green", {"power" : 0.9})
img1 = t.apply(img)
cv2.imwrite("raise_green.jpg",np.hstack([img,img1]))
Raises the hue value.
t = createTechnique("raise_hue", {"power" : 0.9})
img1 = t.apply(img)
cv2.imwrite("raise_hue.jpg",np.hstack([img,img1]))
Raises the value in the red channel.
t = createTechnique("raise_red", {"power" : 0.9})
img1 = t.apply(img)
cv2.imwrite("raise_red.jpg",np.hstack([img,img1]))
Raises the saturation.
t = createTechnique("raise_saturation", {"power" : 0.9})
img1 = t.apply(img)
cv2.imwrite("raise_saturation.jpg",np.hstack([img,img1]))
Raise the value of pixels.
t = createTechnique("raise_value", {"power" : 0.9})
img1 = t.apply(img)
cv2.imwrite("raise_value.jpg",np.hstack([img,img1]))
Resizes the image.
t = createTechnique("resize", {"percentage" : 0.9,"method":"INTER_NEAREST"})
img1 = t.apply(img)
cv2.imwrite("resize.jpg",img1)
Rotates the image.
t = createTechnique("rotate", {"angle" : 90})
img1 = t.apply(img)
cv2.imwrite("rotate.jpg",img1)
Adds salt and pepper noise to the image.
t = createTechnique("salt_and_pepper", {"low" : 0,"up":25})
img1 = t.apply(img)
cv2.imwrite("salt_and_pepper.jpg",np.hstack([img,img1]))
Sharpens the image.
t = createTechnique("sharpen", {})
img1 = t.apply(img)
cv2.imwrite("sharpen.jpg",np.hstack([img,img1]))
Shifts the channels of the image.
t = createTechnique("shift_channel", {"shift":0.2})
img1 = t.apply(img)
cv2.imwrite("sharpen.jpg",np.hstack([img,img1]))
Shears the image.
t = createTechnique("shearing", {"a":0.5})
img1 = t.apply(img)
cv2.imwrite("shearing.jpg",np.hstack([img,img1]))
Translates the image.
t = createTechnique("translation", {"x":10,"y":10})
img1 = t.apply(img)
cv2.imwrite("translation.jpg",np.hstack([img,img1]))