-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathData_Aug.py
32 lines (26 loc) · 1.02 KB
/
Data_Aug.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
from keras.preprocessing.image import ImageDataGenerator
from matplotlib import pyplot
import matplotlib.image as mpimg
import numpy as np
#load the cat image
image = mpimg.imread('images.jpeg')
#reshape the image into (batch_size, height, width, channels)
image = np.expand_dims(image, axis=0)
#view the shape of the image
image.shape
#apply transformations using ImageDataGenerator
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(rotation_range=50,
horizontal_flip=True,
vertical_flip=True,
zoom_range=0.5,
width_shift_range=0.2,
height_shift_range=0.2,
brightness_range=[0.5, 1.5])
#display the transformations of the image
img = datagen.flow(image, batch_size=1)
fig, ax = pyplot.subplots(nrows=1, ncols=3, figsize=(15,15))
for i in range(3):
image = next(img)[0].astype('uint8')
ax[i].imshow(image)
ax[i].axis('off')