#仅介绍以下参数,图片增强
from tensorflow.keras.preprocessing.image import ImageDataGenerator
datagen=ImageDataGenerator(rotation_range=40,#随机旋转角度
width_shift_range=0.2,#随机水平迁移
height_shift_range=0.2,#随机垂直迁移
shear_range=0.2,#随机剪切
zoom_range=0.2,#随机放大
horizontal_flip=True,#镜像
fill_mode='nearest'#像素填充,‘constant',‘nearest',‘reflect'或‘wrap'之一,当进行变换时超出边界的点将根据本参数给定的方法进行处理)
from tensorflow.keras.preprocessing import image
from tensorflow.keras.preprocessing.image import ImageDataGenerator
import matplotlib.pyplot as plt
img = image.load_img('1.jpg')
img_na=image.img_to_array(img)
img_na=img_na.reshape((1,)+img_na.shape)
datagen=ImageDataGenerator(
rotation_range=40,
# width_shift_range=0.2,
# height_shift_range=0.2,
# shear_range=0.2,
# zoom_range=0.2,
# horizontal_flip=True,
# fill_mode='nearest'
)
def img_show():
i=0
for batch in datagen.flow(img_na,batch_size=1):
plt.figure()
imgplot=plt.imshow(image.array_to_img(batch[0]))
plt.axis('off')
if i%4==0:
break
return
img_show()
datagen=ImageDataGenerator(
# rotation_range=40,
width_shift_range=0.2,
height_shift_range=0.2,
# shear_range=0.2,
# zoom_range=0.2,
# horizontal_flip=True,
# fill_mode='nearest'
)
img_show()
datagen=ImageDataGenerator(
# rotation_range=40,
# width_shift_range=0.2,
# height_shift_range=0.2,
# shear_range=0.5,
# zoom_range=0.2,
horizontal_flip=True,
# fill_mode='nearest'
)
img_show()
datagen=ImageDataGenerator(
# rotation_range=40,
# width_shift_range=0.2,
# height_shift_range=0.2,
# shear_range=0.5,
zoom_range=0.2,
# horizontal_flip=True,
# fill_mode='nearest'
)![在这里插入图片描述](https://img-blog.csdnimg.cn/20201210114317965.png#pic_center)
img_show()