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)?
I我希望解决方案基于 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(数据)
,这样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屋!