These functions will randomly distort image data to amplify total amount of images for use in machine learning algorithms.
Python
Switch branches/tags
Nothing to show
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
samples First commit Apr 26, 2017
.gitignore
DataAugmentation.py First commit Apr 26, 2017
LICENSE Initial commit Apr 26, 2017
README.md First commit Apr 26, 2017
output_3_1.png First commit Apr 26, 2017
output_7_1.png First commit Apr 26, 2017
output_8_1.png
output_9_1.png

README.md

Data-Augmentation

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>

png

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>

png

plt.imshow(augmented_data[7])
#Look carefully, random noise added
<matplotlib.image.AxesImage at 0x118e4e080>

png

plt.imshow(augmented_data[6])
#Randomly rotated
<matplotlib.image.AxesImage at 0x118f488d0>

png