Python-为什么 imshow() 会为非零数组生成空白图像?

标签 python arrays image matplotlib imshow

我的目标是在 Python 中将二维数组显示为图像。该数组不包含零元素,因此我期望 imshow() 根据数组值自动设置颜色比例的图像。但是,当我运行代码时,图像是空白的。

csv 文件为:https://ufile.io/urk5m

import numpy as np
import matplotlib.pyplot as plt

data_ = np.loadtxt(open("new_file.csv", "rb"), delimiter=",")
plt.imshow(data_)

我的结果是这样的:/image/kPfgZ.jpg

最佳答案

永远记住,但实际上永远是,图像适用于 8 位整数。这就是为什么有 2^8 种灰色阴影以及为什么最常见的 CS 颜色数是 (2^8)^3= 1670 万种。颜色。 3 因为有 3 个颜色 channel - RGB,每个 channel 有 256 种色调。

每个人都在关注它,主要是图像处理库。

因此,始终确保将正确的矩阵数据类型传递到图像处理函数中:

image_8bit = np.uint8(data_)
plt.imshow(image_8bit)
plt.show()

enter image description here

关于Python-为什么 imshow() 会为非零数组生成空白图像?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55329153/

相关文章:

python - Samtools 共享库 libcrypto.so.1.0.0 未找到

python - 在 Python 中使用正则表达式进行搜索和替换

python - 如何解决 "WebDriverException: Message: TypeError: can' t 访问死对象”并使用 Selenium 和 Python 等待框架可用

arrays - 如何在 VBA 中将数据从 Access 表复制到数组?

python - 如何在python docx模板(docxtpl)中显示图像? python

python - 使用 qdbmp 读取.bmp 图像

python - 如何在Python中使用pandas访问导入的csv文件中的元素?

c# - 使用 linq 将 xml 文件加载到二维矩形数组中

javascript - 根据值将 javascript 对象数组分组到它们自己的对象子数组中

javascript - 仅以特定分辨率加载图像