Doug's MATLAB Video Tutorials

June 11th, 2010

MATLAB Controlling color saturation points on an image

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 Responses to “MATLAB Controlling color saturation points on an image”

  1. Roy replied on :

    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?

  2. dhull replied on :

    @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

  3. Matteo replied on :

    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
    

Leave a Reply

Wrap code fragments inside <pre> tags, like this:

<pre class="code">
a = magic(3);
sum(a)
</pre>

If you have a "<" character in your code, either follow it with a space or replace it with "&lt;" (including the semicolon).


MathWorks

Doug Hull is a proud MathWorker who is on a mission to help you with MATLAB.

Doug's picture

These postings are the author's and don't necessarily represent the opinions of The MathWorks.