-1

我试图使用 ImageDataGenerator 并应用一个 prepossing 函数来应用一些随机色调。当我通过 ImageDataGenerator 对单张图片运行转换时,我没有看到它的应用。

def hue_change(image):
new_img = tf.image.random_hue(np.array(image), 0.2)
return new_img

IMG_gen = ImageDataGenerator(rotation_range=30,height_shift_range=0.05, width_shift_range=0.05,fill_mode='nearest',
                         zoom_range=0.03, rescale=1./255,preprocessing_function=hue_change)

当我直接将此功能直接应用到图片中时,它可以工作。

plt.imshow(hue_change(imread('Train//Apple Granny Smith//179_100.jpg')))

但是当我通过 random_transform 生成它时

plt.imshow(IMG_gen.random_transform(imread(('Train//Apple Granny Smith//179_100.jpg'))))

我没有看到任何变化。

你能告诉我为什么它会这样工作吗?

4

1 回答 1

0

我使用 ImageDataGenerator.flow_from_directory 尝试了 hue_change 预处理功能,并显示了正确的结果。色调随机变化。我还在图像上尝试了您的代码

dgen=ImageDataGenerator(preprocessing_function=hue_change)
nimage=dgen.random_transform(image)
plt.imshow(nimage)

正如您所注意到的,这不会修改色调。random_transform 本身应该对图像应用随机变换。我不知道为什么它没有。也许这里的答案可能会有所帮助。

于 2021-03-21T18:10:20.540 回答