These functions will randomly distort image data to amplify total amount of images for use in machine learning algorithms.
We will use this package to amplify ("augment") a single image.
The library randomly rotates, flips along axis, translates, adds noise, and adds "black boxes" to images to increase the number of usable data for a machine learning algorithm.
import DataAugmentation as da
import matplotlib.pyplot as plt
import numpy as np
%matplotlib inline
Augment function signature:
def augment(images, labels=None, amplify=2):
Input Data:
images
shape: (batch_size, height, width, channels=3)
labels
shape: (batch_size, 3) [this is an optional parameter]
amplify
is how many (randomly altered) copies of the original image(s) you want to produce
# Sample image to amplify
sample = plt.imread('samples/dog_icon.jpg')
plt.imshow(sample)
<matplotlib.image.AxesImage at 0x1161fe550>
sample.shape #Need to reshape to (batch_size, height, width, channels)
sample = np.reshape(sample, (1,256,256,3))
augmented_data = da.augment(sample, amplify=10)
augmented_data.shape
#First image is original, rest are synthesized
(10, 256, 256, 3)
plt.imshow(augmented_data[1])
#Randomly translated
<matplotlib.image.AxesImage at 0x118a3bd68>
plt.imshow(augmented_data[7])
#Look carefully, random noise added
<matplotlib.image.AxesImage at 0x118e4e080>
plt.imshow(augmented_data[6])
#Randomly rotated
<matplotlib.image.AxesImage at 0x118f488d0>