简体   繁体   English

Tensorflow 绿移图像

[英]Tensorflow green-shifts image

I have the following code:我有以下代码:

import tensorflow as tf
from matplotlib import pyplot as plt

def load(im1, im2):
    ima1 = tf.io.read_file(im1)
    ima1 = tf.image.decode_image(ima1)
    ima1 = tf.cast(ima1, tf.float32)

    ima2 = tf.io.read_file(im2)
    ima2 = tf.image.decode_image(ima2)
    ima2 = tf.cast(ima2, tf.float32)

    return ima1, ima2

inp, re = load(r"RAWs/1313 (1).jpg", r"Clean/1313 (1).png")

plt.figure()
plt.imshow(inp)
plt.figure()
plt.imshow(re)
plt.show()

Everything works fine, no errors, except that the second image re is greenshifted (right-most image below):一切正常,没有错误,除了第二个图像re被绿移(下面最右边的图像):

在此处输入图片说明

I have the latest version of tensorflow-cpu as I don't have a GPU due to current shortage, Python 3.9 64 Bit.我有最新版本的 tensorflow-cpu,因为由于当前短缺,我没有 GPU,Python 3.9 64 位。

Does someone know why this is happening and how to resolve it?有人知道为什么会发生这种情况以及如何解决吗?

Raw images: one , two , three .原始图像:

It's not a colour image, it's a single-channel greyscale image.它不是彩色图像,而是单通道灰度图像。 You are looking at false colour , sometimes called pseudocolour .您正在查看假色,有时称为 The imshow() function is mapping the numbers in the array to the colours in the viridis colourmap. imshow()函数将数组中的数字映射到viridis颜色图中的颜色。

Colour images have 3 channels (or 4, if they have opacity too).彩色图像有 3 个通道(或 4 个,如果它们也有不透明度)。 So a NumPy array of a colour image will have shape like (h, w, 3) or (h, w, 4) .因此,彩色图像的 NumPy 数组将具有类似(h, w, 3)(h, w, 4)形状。 This one has a single channel (shape like (h, w) ).这个只有一个通道(形状像(h, w) )。 To put it another way, it's a greyscale image.换句话说,它是一个灰度图像。

If you plot this array with plt.imshow(img, cmap='gray') it will display how you're expecting.如果您使用plt.imshow(img, cmap='gray')绘制此数组,它将显示您的期望。 This scheme maps zeros (or whatever the lowest number is) to black and ones (or the highest value) to white.该方案将零(或任何最低数字)映射到黑色,将 1(或最高值)映射到白色。 (See all maplotlib 's colourmaps here .) 在此处查看所有maplotlib的颜色图。)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM