Different color for saturated pixels in colormap

I have a contourplot using the jet colormap. When I set the max and min data points, using the 'CLim' property, the data points above and below the limiting values are mapped on to the max and min color values respectively (right plot).
My question is, would it be possible to set the saturated pixels, the dark red and dark blue ones on the right plot, to a different color? For example saturation beyond the max value to white and below the min value to black.
Thanks!

 Accepted Answer

Yes, just set the first and last rows to black and white
% Create sample data and display it.
indexedImage = -3E-4 * rand(50,50);
imshow(indexedImage, [], 'InitialMagnification', 800);
movegui('northeast');
% Create/initialize default colormap of jet.
cmap = jet(16); % or 256, 64, 32 or whatever.
% Now make lowest values show up as black.
cmap(1,:) = 0;
% Now make highest values show up as white.
cmap(end,:) = 1;
% Apply colormap. Changes take effect only when you call colormap().
colormap(cmap);
colorbar;

2 Comments

Only the values that extend beyond the maximum or below the minimum are intended to be given the different color: the values that are just below (or up to) the maximum are intended to keep the current maximum color.
Qifei Gu
Qifei Gu on 19 Aug 2016
Edited: Qifei Gu on 19 Aug 2016
For my data visualisation purposes this solution is good enough. As Walter pointed out, you lose a few of data points to saturation color near the minimum and maximum. I guess I can mitigate that but using finer spacing in the jet colormap. For exact solution might need to consider Walter's solution. Thank you both for the help!

Sign in to comment.

More Answers (1)

No, not directly.
You have two possibilities that I can think of at the moment:
1) create a new colormap with two additional colors, one on each end. It gets tricky to adjust the clim or values properly so that only the saturated (or underflow) pixels get those colors and not values that are nearly saturated or nearly underflowing.
2) Add an additional image() object positioned exactly over the contour map. At each non saturated point, set the AlphaData of the image object to 0, so that the contour map shows through. At each saturated point, set the AlphaData of the image object to 1, so that contour map does not show through. At the saturated points, set the CData property of the image() object to the RGB value you want (white) and at the underflow points, set the CData property of the image() object to the RGB value you want (black). CLim does not apply to RGB color so you do not need to worry about adjusting CLim or adjusting any values in the contour map.

Asked:

on 18 Aug 2016

Edited:

on 19 Aug 2016

Community Treasure Hunt

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

Start Hunting!