在Matlab图像中为NaN值分配不同的颜色 [英] Assign different color to NaN values in Matlab images

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

问题描述

我正在Matlab上处理卫星图像,并正在编写用于计算净辐射的代码.输出包含具有NaN值的矩阵形式的图像.当我尝试使用以下方式进行绘制时:

I am working with satellite images on Matlab and am writing a code for calculating Net Radiation. The output contains the image in form of a matrix with NaN values. When I try to plot it using:

figure
imshow(X);

它为NaN值分配与0相同的颜色.是否可以通过任何方法将这些值分配为不同的颜色?

it assigns the NaN values the same color as 0. Is there any way I can assign those values to be a different color?

此外,我想将矩阵另存为图像,但格式不能更改,可能是ASCII.是否有将矩阵转换为ASCII的工具?

Also, I want to save my matrix as an image, but in a format that its values don't get changed ... possibly ASCII. Is there a tool for converting matrix to ASCII?

推荐答案

如果您的X矩阵是2矩阵,其值介于0和1之间,且值为NaN,则可以使用以下命令将NaN值更改为例如0.88

If your X matrix, is a 2D matrix with values between 0 and 1 and NaN values, you can use the following command to change NaN values to for example 0.88.

X(isnan(X))=0.88;

但是如果X矩阵是3D(对于RGB),答案会略有不同,并且此解决方案不起作用.

but if the X matrix is 3D (for RGB) the answer is slightly different and this solution does not work.

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

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