classes = ["dog", "cat", "bird"]
img_width, img_height = 1600, 1200
DATA_DIR = [""] * len(classes)
SAVE_DIR = [""] * len(classes)
for i in range(len(classes)):
DATA_DIR[i] = 'input/' + classes[i]
SAVE_DIR [i] = os.path.join ('output /', classes [i]) # Directory where the generated image is saved if not os.path.exists(SAVE_DIR[i]): os.makedirs(SAVE_DIR[i])
#Load image (PIL format image) # img = load_img(IMAGE_FILE)
# plt.imshow(img)
# plt.show()
#Rotation: -15 ~ 15 #Translation up and down: -0.8 to 1.2% movement #Translation from side to side: -0.8 to 1.2% movement #Shear: Shear at -5 degrees to 5 degrees
#Brightness change: Add value to pixel value in the range of -5.0 to 5.0
datagen = ImageDataGenerator(
rotation_range=15,
height_shift_range=0.2,
width_shift_range=0.2,
shear_range=5,
zoom_range=0.2,
channel_shift_range=5,
brightness_range=[0.3, 1.0]
)
for i in range(len(classes)):
for picture in list_pictures(DATA_DIR[i]):
img = img_to_array(load_img(picture, target_size=(img_height, img_width)))
Convert to an array of # numpy x = img_to_array(img)
# x = np.expand_dims(x, axis=0)
x = x.reshape((1,) + x.shape)
# print(x.shape)
g = datagen.flow(x, batch_size=1, save_to_dir=SAVE_DIR[i], save_prefix='out', save_format='jpg')
for j in range(3):
batches = g.next()
# print(batches.shape)
#To display as an image, change from 4D to 3D data, and change from an array to an image. gen_img = array_to_img(batches[0])
# plt.subplot(8, 8, i + 1)
# plt.imshow(gen_img)
# plt.axis('off')