Distinct NaN from other values in image

I want to plot image with different values and easily distinct them from NaN values. As default NaN values are imaged with the same color as the minimum value. I have tried a range of possibilites but each provide their own issue. Here is one example:
The solution from here, image all other values as one color
imagesc(CP)
sc(isnan(CP), 'bone', [1 1 1]);

3 commentaires

Agnete
Agnete le 25 Nov 2013
The NaN values outside of my shape should be one color (gray/white) but without changing the value of my polygon inside my shape (value 10-100). When I use imagesc(~isnan(CP)) the value of my polygons are overwritten with value of 1.
Image Analyst
Image Analyst le 25 Nov 2013
The answer has been accepted. I don't see a question in the last comment. And no m-file was attached.
You did not use sc correctly. Try:
sc(CP, 'bone', 'r')

Connectez-vous pour commenter.

 Réponse acceptée

Iain
Iain le 21 Nov 2013
This can let you plot NaN & any other logically findable section of the image as white
a = rand(5);
a(3,3) = NaN;
b = imagesc(a);
set(b,'AlphaData',~isnan(a))
Alternatively, you can deliberately control the "colormap" settings to ensure that "invalid" values show up as a colour that isn't used by the colour map.

3 commentaires

Agnete
Agnete le 22 Nov 2013
Modifié(e) : Agnete le 25 Nov 2013
At first I was taken back as the axis values was dublicated in a weird way as can be seen with the fig-format but fortunately this is resolved when saving as pdf-format. However when I use export_fig the original NaN-color returns!
Andrea
Andrea le 29 Déc 2017
changed my life
Works like a charm!

Connectez-vous pour commenter.

Plus de réponses (1)

Image Analyst
Image Analyst le 20 Nov 2013
I don't know what "plot" means when talking about an image. I don't know why you want to plot anything on an image, like markers to "cover up" the nan locations. Why not just set the nan's to the min gray level and view it like a normal image?
CP(isnan(CP)) = min(CP(:)); % Set nan values to the min value
image(CP);
colormap(bone(256));
colorbar;

3 commentaires

Agnete
Agnete le 21 Nov 2013
Nan values are imaged with the same color as my minimum value. I want to distinct between my minimum values and Nan.
Why I use add a plot of coordinates to my image is irrelevant in this context and I have now deleted that code in my original question.
Agnete
Agnete le 21 Nov 2013
The problem is illustrated in the attached where it is seen that the polygon in northeast corner blends into the background
Image Analyst
Image Analyst le 22 Nov 2013
Sorry but I don't understand this. One just sort of looks like a very blurred version of the other. Both have the same pattern of triangles on them, and I don't even know what a triangle means/represents. Your image is an array. You can't have nan values have the same value as your minimum value. An element can have only one value, either a nan or some number. It can't have both at the same time. So "Nan values are imaged with the same color as my minimum value" makes no sense to me.

Connectez-vous pour commenter.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by