from keras.preprocessing.image import ImageDataGenerator, array_to_img, img_to_array, load_img
import cv2
import numpy as np
datagen = ImageDataGenerator(
rotation_range=180,
width_shift_range=0.5,
height_shift_range=0.5,
shear_range=0.3,
zoom_range=0.6,
horizontal_flip=True,
vertical_flip = True,
fill_mode = "wrap")
img = cv2.imread(r"C:\image data\test\defect 001.jpg", 0)
#tensorflow backend
x = img_to_array(img) # this is a Numpy array with shape (150, 150 , 1)
x = x.reshape( (1,) + x.shape ) # this is a Numpy array with shape (1, 150, 150 , 1~3(ch) )
i = 0
for batch in datagen.flow_from_directory( directory= r"C:\image data\defect"
, target_size = (64,64)
, color_mode = "grayscale"
, batch_size=1
, shuffle = True
, save_to_dir=r'C:\image data\test\result'
, save_prefix='defect'
):
i += 1
if i > 50000:
break
댓글 없음:
댓글 쓰기