Stuart’s MATLAB Videos

Watch and Learn

This is machine translation

Translated by Microsoft
Mouseover text to see original. Click the button below to return to the English version of the page.

MATLAB Controlling color saturation points on an image 3

Posted by Doug Hull,

In this MATLAB video we show how you can manipulate the clim property of an axis to determine the points that an image will saturate the colormap. This is often a better choice than making a strange colormap to get the same effect.

3 CommentsOldest to Newest

Roy replied on : 1 of 3
I have a related question. I have used the function you wrote "makeColorMap" to make a colormap that goes smoothly from red to white to blue. Now suppose I want to make sure that red shades are for negative numbers, blue shades are for positive numbers and any zero contours would be white. Is there a simple way to anchor white to the zero level?
dhull replied on : 2 of 3
@Roy, You can set the clim as specified in the movie. Make those limits such that the white value of colormap happens to fall on zero. So it is slightly indirect, takes a little bit of math, but should not be difficult. Especially if it is a symmetric colormap, just choose the clims to be equidistant from zero. Doug
Matteo replied on : 3 of 3
Roy, If the colorbar is not symmetric you could calculate the difference between the signed most negative and most positive values in your data and use both the numerical result and its sign to assign the limits of saturation automatically. this should anchor it to zero. Something like the below "pseudocode":
if D maxpos+maxneg >0 % abs(maxpos) > abs (maxneg)
   clim=[maxneg (maxpos-D)]
elseif 
   D = maxpos+maxneg <0
   clim=[(maxneg-D) (maxpos)]
end