1
votes

I have an indexed image (2-D, not rgb), and i use imagesc to display the image. This function gives a range from blue to red, which can be set by colormap, and can be viewed by colorbar.

Now, I want to change the background, that is usually 0's or NaN's, to white or black, but that it will not affect or change the range of the colormap/colorbar. I've tried converting all the image to 3-D rgb, but this prevent the option of changing the contrast, or the clims, like in imagesc. So, there is other way to do that?

EDIT:

@Shai's solution was good, but it caused other problem-

When I have an image with a range of values and the background is NaN's, and I display the image in a specific contrast (by imagesc(img, [-1,1]) for example), I get range of colors between -1 to 1, and i get white in the background (because i put [1 1 1] in the first entry of the colormap), but also all the values under the minimum of contrast (i.e., <-1 in the example) also get the white color instead of the bottom dark blue in the colorbar scale.

Any idea for that...?

Many Thanks.

1
you need to set the first entry in your color map to zero. - Shai
Sounds a good idea, i'll try it. - Adiel
@Shai Consider putting this into an answer. I'll upvote it if it works and is good. - krisdestruction
It's work, thank you! It may be a simple answer, but it think the problem and its solve should be as Q/A, so you can post it as answer and i'll accept it, of course. - Adiel

1 Answers

1
votes

Consider putting [1, 1, 1] as the first entry of your colormap to get the background as white.