Creating a custom colormap with min and max pixel values, and white as 0?
12 次查看(过去 30 天)
显示 更早的评论
I'm looking to create a colourmap where the minimum pixel value to 0 is red to white and 0 to maximum pixel value is white to green.
I can set the caxis to span from the min to max value, but I can't figure out how to ensure that 0 is white and the other values are on the gradients.
Can I somehow create two colourmaps and combine them together? Is there another way to specify the range I want besides caxis?
Thanks
0 个评论
回答(1 个)
Image Analyst
2017-10-30
You need to decide on a length of a colormap, like 256. Then you need to say row 1 is [1,0,0] which is red and corresponds to the min value, which I guess is negative. Then you need to say the last row is [1,1,1] which is white and corresponds to the max value. Now the 0 value of your data may fall into some row in between 1 and 256 and you need to figure out what that is. Easy to do. Something like
zeroRow = 256 * (0-minValue)/(maxValue-minValue);
Now you need to have row 1 to zeroRow go from red to white, which you can do with linspace(), then have from zeroRow to 256 go from white to green, again using linspace(). Not too hard so give it a try.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 White 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!