图像中NaN的对比颜色 [英] Contrasting color for NaNs in imagesc

查看:114
本文介绍了图像中NaN的对比颜色的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用NaN填充矩阵中未使用的元素,并且当使用imagesc显示数据时,我想为那些具有NaN值的元素分配对比色.

I fill unused elements in a matrix with NaNs, and I would like to assign a contrasting color to those elements with the NaN value when displaying the data using imagesc.

以下是可能解决方案的链接,但我不太理解.

Below is a link to a possible solution, but I don't quite understand it.

http://www.mathworks.com/matlabcentral/newsreader/view_thread/19985

推荐答案

NaN值从轴颜色图中获取第一种颜色,默认情况下,其对应于最小值(NaN除外).您可以使用 CAXIS 函数更改最小值设置轴的颜色限制.要为NaN值分配对比色,您可以为NaN值添加特殊颜色作为第一种颜色(1x3矢量).

NaN values get the first color from the axes colormap, which by default corresponds to the minimum value (other than NaN). You can change the color for minimum value setting axes color limits with CAXIS function. To assign a contrast color to NaN values you can add a special color for NaN values as a first color (1x3 vector).

我以您的示例为例,并制作了一个函数(带有一些注释):

I take your example and made a function (with some comments):

function [h hcb] = imagescwithnan(a,cm,nanclr)
% IMAGESC with NaNs assigning a specific color to NaNs

%# find minimum and maximum
amin=min(a(:));
amax=max(a(:));
%# size of colormap
n = size(cm,1);
%# color step
dmap=(amax-amin)/n;

%# standard imagesc
him = imagesc(a);
%# add nan color to colormap
colormap([nanclr; cm]);
%# changing color limits
caxis([amin-dmap amax]);
%# place a colorbar
hcb = colorbar;
%# change Y limit for colorbar to avoid showing NaN color
ylim(hcb,[amin amax])

if nargout > 0
    h = him;
end

此处caxis语句将颜色图的第一种颜色分配给最小值amin,而不分配给最小值amin-dmap.因此,第一种颜色专门分配给了NaN.

Here caxis statement assigns the first color of the color map not to the minimum value amin, but to the amin-dmap. So the first color get assigned specifically to NaNs.

尝试使用此功能:

a=peaks;
a(a < 0.5) = nan;
imagescwithnan(a,hot,[0 1 1]) %# [0 1 1] is cyan

如果您在函数中注释ylim语句(可以用附加参数控制),则该NaN颜色将出现在颜色图上.

If you comment the ylim statement in the function (can be control with additional parameter) this NaN color will be on the colormap.

这篇关于图像中NaN的对比颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆