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
댓글 수: 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!