Matlab imshow 省略 NaN [英] Matlab imshow omit NaN
问题描述
我正在使用 imshow()
来可视化从两个灰度图像的差异中获得的数据.图像被遮罩,即位于"遮罩下的每个像素都具有 NaN
值.数据由 parula
颜色图表示.问题在于 imshow()
将 NaN
视为零,因此屏蔽像素表示为蓝色.是否有一种简单的方法可以省略被屏蔽的像素或以不属于颜色图的颜色(例如白色、灰色或黑色)显示它们?
I am using imshow()
to visualize data obtained from the difference of two grayscale images. The images are masked, i.e. each pixel 'laying under' the mask has the value NaN
. The data are represented by the parula
colormap. The problem is that imshow()
treates NaN
as zero and therefore the masked pixels are represented as blue. Is there an easy way to omit the masked pixels or to display them in a color that is not part of the colormap (e.g. white, gray, or black)?
我更喜欢基于 imshow()
的解决方案,因为它最容易包含到我的代码中.然而,使用 pcolor
、imagesc
等的解决方案也将受到赞赏.
I would prefer the solution to base on imshow()
since it would be easiest to include into my code. However, solutions using pcolor
, imagesc
or the like will also be appreciated.
推荐答案
你可以设置图像对象的AlphaData
等于~isnan(data)
这样NaN 将显示为透明值.
You can set the AlphaData
of the image object to be equal to ~isnan(data)
such that NaN's will be shown as transparent values.
R = rand(10);
R(R < 0.25) = NaN;
him = imshow(R, 'InitialMagnification', 10000);
colormap parula
set(him, 'AlphaData', ~isnan(R))
如果你想要一个特定的颜色,你可以打开坐标轴并将坐标轴的颜色设置为你想要 NaN
值的任何颜色.
If you want a specific color, you could turn on the axes and set the color of the axes to be whatever color you want the NaN
values to be.
axis on;
% Make a red axis
set(gca, 'XColor', 'none', 'yColor', 'none', 'xtick', [], 'ytick', [], 'Color', 'r')
如果您使用 pcolor
,则 NaN
值已被视为透明.
If you use pcolor
, then NaN
values are already treated as transparent.
这篇关于Matlab imshow 省略 NaN的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!