【问题标题】:Keras ImageDataGenerator messing up with grey images, how to correctly augment greyscale image?Keras ImageDataGenerator 弄乱了灰度图像,如何正确增强灰度图像?
【发布时间】:2018-11-01 16:34:38
【问题描述】:

我正在分析 16 位灰度图像。 上传灰度图后,一切正常。

import matplotlib.pyplot as plt
import numpy as np
img = plt.imread('example_image.tif')
plt.imshow(img)
plt.show()

或者也可以

import cv2
img = cv2.imread('example_image.tif', -cv2.IMREAD_ANYDEPTH)
img1 = np.expand_dims(img, axis=2)
img2 = np.reshape(img1,[1,696,520,1])
plt.imshow(img)
plt.show()

当我检查我的增强图像时,它们看起来是扭曲的。我做错了什么?

img1 = np.expand_dims(img, axis=2)
img2 = np.reshape(img1,[1,696,520,1])
from keras.preprocessing.image import ImageDataGenerator
datagen = ImageDataGenerator(
    rescale=1. / 4095,
    shear_range=0.2,
    zoom_range=0.2,
    horizontal_flip=True)

i=0
for batch in datagen.flow(img2, batch_size=1,
                          save_to_dir='C:/image_analysis', save_prefix='grey_check_', save_format='tif'):
    i += 1
    if i > 20:
        break

【问题讨论】:

    标签: python-3.x tensorflow keras deep-learning


    【解决方案1】:

    替换这一行:

    img2 = np.reshape(img1,[1,696,520,1])
    

    关于这个:

    img2 = np.reshape(img1,[1,520,696,1])
    

    【讨论】:

      猜你喜欢
      • 2014-05-30
      • 1970-01-01
      • 1970-01-01
      • 2019-04-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-11-30
      相关资源
      最近更新 更多