Creating a custom colormap with min and max pixel values, and white as 0?

8 次查看(过去 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

回答(1 个)

Image Analyst
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.
  1 个评论
Emma Tompkins
Emma Tompkins 2017-10-31
Thank you, still a little confused on one part. How to I ensure that my min and max values correspond to the right row in my scale?
lowest = min(min(I4));
highest = max(max(I4));
row1 = [0 1 0];
zerorow = [0 0 0];
row256 = [1 0 0];
zerolocation = 256 * ((0-lowest)/(highest-lowest));
Cmap = linspace(....?);
So linspace(row1,zerorow,zerolacation) should be what I want for red to white? How does it know to assign my lowest number to row1?
Is it something like linspace(row1(lowest),zerorow,zerolocation) ?
Sorry, I'm very new at this and am teaching myself. I appreciate any help!

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 White 的更多信息

Community Treasure Hunt

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

Start Hunting!

Translated by