【发布时间】:2023-03-21 15:59:01
【问题描述】:
我尝试使用数组中的 image.fromarray 来显示图片,但我无法从 plt.imshow 中获得正确的图片。你有什么想法吗?
from PIL import Image
import numpy as np
import matplotlib.pyplot as plt
row,col,ch=img_array.shape
mean=0.0
sigma=20
gauss = np.array(np.random.normal(mean,sigma,(row,col,ch)),dtype=np.int64)
noisy = img_array + gauss
new_image = Image.fromarray(noisy,'RGB')
new_image
如果我通过 plt.imshow 运行它,请求的图片在下面
plt.imshow(noisy, interpolation='nearest')
plt.show()
【问题讨论】:
-
因为类型是
int64,它不太适合只能处理 8/16 位样本的 PNG 文件。 -
@Mark Setchell 感谢我尝试了 int8 /int16 的回复,但仍然没有达到我的预期,您还有其他想法吗?
-
我无法运行您的代码,因为我不知道
img_array是什么。 -
256X256 lena RGB 图像
-
请确保您的代码最小、完整和可验证 - 请参阅stackoverflow.com/help/mcve 如果您让人们更容易运行您的代码,您将更有可能获得帮助.
标签: image matplotlib python-imaging-library