对一些scikit图像代码示例和pyplot进行了一番研究,我发现根据我如何应用彩色地图,我在图像上发现了不同的结果,我不知道为什么。在
当我应用一个颜色贴图作为一个插件显示一个图像时,一切正常,当我直接对图像做它,它变成了完全黑色。我很困惑,因为我想把彩色地图应用到我想保存(而不是显示)的图像上,但我不知道如何正确地进行。在
import matplotlib.pyplot as plt
from skimage import data
from skimage.color import rgb2hed
ihc_rgb = data.immunohistochemistry()
ihc_hed = rgb2hed(ihc_rgb)
fig, axes = plt.subplots(2, 2, figsize=(7, 6))
ax0, ax1, ax2, ax3 = axes.ravel()
ax0.imshow(ihc_hed[:, :, 0], cmap=plt.cm.gray)
ax0.set_title("plugin")
ax1.imshow(plt.cm.gray(ihc_hed[:, :, 0]))
ax1.set_title("direct")
[继续说下去]
根据您对Stefan van der Walt的answer的评论,我得出结论,您不想保存matplotlib图形,而是直接保存图像。 正如Stefan指出的,在使用colormap之前,您需要缩放这些值。Matplotlib为此提供了
Normalize
类:ihc_hed[:, :, 0]
内的值介于-1.37和-0.99之间。imshow
的默认行为是显示整个值范围。^另一方面,{在第一种情况下,自动重新缩放可以节省您的时间,但第二种情况下不会。我建议始终使用固定范围的
imshow
,imshow(image, vmin=0, vmax=1, cmap='gray')
相关问题 更多 >
编程相关推荐