【问题标题】:image data go beyond 0-1 range after processing图像数据处理后超出0-1范围
【发布时间】:2018-08-07 01:11:09
【问题描述】:

我正在随机调整图像的亮度、饱和度等。但是调整后img_data的值超过了0-1,这样imshow就不起作用了。

tf.InteractiveSession()
image_raw_data=tf.read_file('C:/Users/User/PycharmProjects/Neural_Network\\cat.jpg')
sess=tf.Session()
img_data=tf.image.decode_jpeg(image_raw_data,channels=3)
img_data=tf.image.convert_image_dtype(img_data,dtype=tf.float32)
img_data=tf.image.resize_images(img_data,[300,300],method=0)
img_data=tf.image.random_brightness(img_data,max_delta=32/255)
plt.imshow(img_data.eval())

错误是:

ValueError: Floating point image RGB values must be in the 0..1 range.

我可以知道我应该如何正确转换图像以便显示吗?

【问题讨论】:

    标签: python image-processing tensorflow deep-learning


    【解决方案1】:

    我要做的纯粹是可视化图像是在图像中添加最小值,然后除以最大值以将图像钳位在 0 和 1 之间,如下所示:

    import numpy as np
    img_data_np = img_data.eval()
    min_val = np.min(img_data_np)
    max_val = np.max(img_data_np)
    img_data_clamped = (img_data_np - min_val) / (max_val - min_val)
    plt.imshow(img_data_clamped)
    

    【讨论】:

      猜你喜欢
      • 2019-04-06
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-09-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多