Changing the default colorbar

7 visualizzazioni (ultimi 30 giorni)
James
James il 25 Lug 2011
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

Risposte (2)

Walter Roberson
Walter Roberson il 25 Lug 2011
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 il 25 Lug 2011
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 Commento
Walter Roberson
Walter Roberson il 25 Lug 2011
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.

Accedi per commentare.

Categorie

Scopri di più su Color and Styling in Help Center e File Exchange

Prodotti

Community Treasure Hunt

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

Start Hunting!

Translated by