Changing the default colorbar

조회 수: 11 (최근 30일)
James
James 2011년 7월 25일
Hello,
I have a two-dimensional matrix which is basically an aerial image of some land "pixels" and ocean "pixels". The land pixels are given a value of -9999 by default and the ocean pixels have values from zero to approximately 250. I want to use the standard colormap "jet" when using the image() function. However, is there a way to set the land pixels (-9999) to be black (rather than the default dark blue)?
Any help would be greatly appreciated. Thanks,
James

답변 (2개)

Walter Roberson
Walter Roberson 2011년 7월 25일
No. The "jet" colormap does not contain black, so as long as you restrict yourself to "jet" you are not going to be able to do this.
If you augment the jet colormap with one more entry then you could do it, with appropriate mapping of the data.
One alternative is to overlay an all-black image on top of the other image, and set the AlphaData property of the top image such that the patch is transparent (AlphaData zero) where there is no land.

James
James 2011년 7월 25일
Do you know the most direct way to augment the colormap? I think I would have to set negative numbers to "black"...but I cannot find much online help about doing so...
  댓글 수: 1
Walter Roberson
Walter Roberson 2011년 7월 25일
In the below, I will rely upon your indication that your regular values are in the range 0 to 250. The below code will produce a distorted image if your range is significantly narrower or has values exceeding 254.
img = uint8(YourMatrix);
img(YourMatrix < 0) = 255;
At this point, your data has been discretized to uint8, and all of the original negative values have been set to 255. I choose to do it this way instead of shifting the other values "up" to make room for the black in order to allow the data cursor to function.
Now we set the color map to include black:
cmap = jet(256);
cmap(end,:) = [0;0;0]; %black
colormap(cmap); %activate it.

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Color and Styling에 대해 자세히 알아보기

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by