Skip to content

Instantly share code, notes, and snippets.

@PulkitS01
Created November 27, 2019 10:16
Show Gist options
  • Save PulkitS01/3664129249f734a80da139fd9b9bca3a to your computer and use it in GitHub Desktop.
Save PulkitS01/3664129249f734a80da139fd9b9bca3a to your computer and use it in GitHub Desktop.
Augmentation
#standard deviation for noise to be added in the image
sigma=0.155
#add random noise to the image
noisyRandom = random_noise(image,var=sigma**2)
plt.imshow(noisyRandom)
plt.title('Random Noise')
#blur the image
blurred = gaussian(image,sigma=1,multichannel=True)
plt.imshow(blurred)
plt.title('Blurred Image')
#flip image left-to-right
flipLR = np.fliplr(image)
plt.imshow(flipLR)
plt.title('Left to Right Flipped')
#flip image up-to-down
flipUD = np.flipud(image)
plt.imshow(flipUD)
plt.title('Up Down Flipped')
print('Rotated Image')
#rotating the image by 45 degrees
rotated = rotate(image, angle=45, mode = 'wrap')
#plot the rotated image
io.imshow(rotated)
#apply shift operation
transform = AffineTransform(translation=(25,25))
wrapShift = warp(image,transform,mode='wrap')
plt.imshow(wrapShift)
plt.title('Wrap Shift')
# importing all the required libraries
import warnings
warnings.filterwarnings('ignore')
import numpy as np
import skimage.io as io
from skimage.transform import rotate, AffineTransform, warp
from skimage.util import random_noise
from skimage.filters import gaussian
import matplotlib.pyplot as plt
% matplotlib inline
# reading the image using its path
image = io.imread('emergency_vs_non-emergency_dataset/images/0.jpg')
# shape of the image
print(image.shape)
# displaying the image
io.imshow(image)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment