Klassen = ["Hund", "Katze", "Vogel"]
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]) # Verzeichnis, in dem das generierte Bild gespeichert wird if not os.path.exists(SAVE_DIR[i]): os.makedirs(SAVE_DIR[i])
# img = load_img(IMAGE_FILE)
# plt.imshow(img)
# plt.show()
#Scherung: Scherung bei -5 bis 5 Grad
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)))
In # numpy Array konvertieren 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)
#Um als Bild anzuzeigen, wechseln Sie von 4D- zu 3D-Daten und von einem Array zu einem Bild. gen_img = array_to_img(batches[0])
# plt.subplot(8, 8, i + 1)
# plt.imshow(gen_img)
# plt.axis('off')