为什么 matplotlib imshow() 和 show() 函数会根据图像是作为 uint8 还是 in64 读入而以不同的配色方案显示图像? [英] Why does matplotlib imshow() and show() functions show images in a different color scheme depending on whether they're read in as uint8 or in64?

查看:60
本文介绍了为什么 matplotlib imshow() 和 show() 函数会根据图像是作为 uint8 还是 in64 读入而以不同的配色方案显示图像?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据我在图像中的阅读方式(选项1或选项2),打印时图像的显示方式有所不同.为什么会这样?

Depending on how I read in the image (option 1 or option 2), the images are shown differently when printed. Why is that?

选项1

image = np.array(plt.imread('fixed_image.jpg'), dtype='int64')[:, :, 0:3]

选项 2

image = np.array(plt.imread('fixed_image.jpg'), dtype='uint8')[:, :, 0:3]

打印

plt.imshow(image)
plt.show()

推荐答案

我认为 imshow 文档很清楚:

I think the imshow documentation is pretty clear on that:

X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4)
在X轴上将图像显示到当前轴.X 可以是数组或 PIL 图像.如果X是一个数组,则可以具有以下形状和类型:

X : array_like, shape (n, m) or (n, m, 3) or (n, m, 4)
Display the image in X to current axes. X may be an array or a PIL image. If X is an array, it can have the following shapes and types:

  • MxN –要映射的值(浮点数或整数)
  • MxNx3 – RGB(浮点数或 uint8)
  • MxNx4 – RGBA(浮点数或 uint8)

MxNx3和MxNx4浮点数组的每个分量的值都应在0.0到1.0的范围内.

The value for each component of MxNx3 and MxNx4 float arrays should be in the range 0.0 to 1.0.

这意味着您可以提供 0.1. 之间的浮点值数组,或 0 之间的无符号整数值数组和 255 .

This means you may provide a float array of values between 0. and 1., or an unsigned integer array of values between 0 and 255.

未记录如果使用'int64'会发生什么.因此,任何事情都可能发生,从不想要的图像上的错误到预期的输出.

What happens if you use 'int64' is not documented. Therefore just anything could happen, ranging from an error over an undesired image to the expected output.

为了解释您的实际结果,您需要了解操作系统,python版本,操作系统和python的位深度,您使用的numpy和matplotlib版本.也可能是您读入的实际图像.

In order to explain your actual outcome, one would need to know the operating system, the python version, the bit depth of the OS and of python, the numpy and matplotlib versions you use. Possibly also the actual image you read in.

这篇关于为什么 matplotlib imshow() 和 show() 函数会根据图像是作为 uint8 还是 in64 读入而以不同的配色方案显示图像?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆