필터 지우기
필터 지우기

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

조회 수: 12 (최근 30일)
Emma Tompkins
Emma Tompkins 2017년 10월 30일
댓글: Emma Tompkins 2017년 10월 31일
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