索引图像的背景 [英] Background for indexed image
问题描述
我有一个索引图像(2-D,不是rgb),并且我使用imagesc
来显示图像.此功能提供了从蓝色到红色的范围,可以由colormap
设置,并且可以由colorbar
查看.
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
.
现在,我想将背景(通常为0或NaN)更改为白色或黑色,但不会影响或更改颜色图/颜色条的范围.我尝试将所有图像都转换为3-D rgb,但这会阻止更改对比度或clims
的选项,例如在imagesc
中.
那么,还有其他方法可以做到吗?
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?
@Shai的解决方案很好,但引起了其他问题-
@Shai's solution was good, but it caused other problem-
当我的图像具有一定范围的值并且背景是NaN的并且以特定的对比度显示图像时(例如通过imagesc(img, [-1,1])
),我得到的颜色范围是-1到1,并且i在背景中获取白色(因为我将[1 1 1]放置在颜色图的第一项中),但是所有对比度最小的值(例如,示例中的-1以下)也获得了白色颜色条刻度中最下面的深蓝色的颜色.
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...?
非常感谢.
推荐答案
考虑将[1, 1, 1]
作为颜色表的第一项,以使背景为白色.
Consider putting [1, 1, 1]
as the first entry of your colormap to get the background as white.
这篇关于索引图像的背景的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!