Changing the default colorbar

7 ビュー (過去 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 Center および File ExchangeColor and Styling についてさらに検索

タグ

製品

Community Treasure Hunt

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

Start Hunting!

Translated by