Tuesday 15 January 2013

matlab - How to create a custom colormap programmatically? -


I want to create a colormap in matlab. I want to dim the color according to the gray level pixels.

For example:

  to 255 to 160 -> White to 15 to 9 120 - & gt; Pink to 119 to 50 - & gt; Brown 49 to 0 - & gt; Dark    

to:

A colormap is 0.0 And between 1.0 a m-by-3 matrix of the actual number. Each row is a RGB vector that defines one color. Theater's Keith Line defines Keith's color, where the map (k, :) = [r (k) g (k) b (k)] specifies the intensity of red, green and blue.

OK, to start, we are going to create an M-by-3 matrix, in your case, 161 is:

  m = 161; Map = zero (m, 3);   

Now you want to be black below (I'm going with black) and 50th point to be brown. But let's go with Lal as an example because it is easy RGB triple for black and red respectively: [0,0,0] and [1,0,0]

OK, so currently our anti-colormap art is. We know that we want map (50, :) = [1, 0, 0] that is red, but now we want a gradient between right? Then use for this (note that at the end of this reply there is a better way of using interp1 instead of linspace ):

 < Code> R0to50 = linkspace (0,1,50) ';   

By putting it in the map:

  Map (1:50, 1) = R0to50;   

To use now instead of red, use that link to divide each color component by three times to 255 so that our triple t = [101, 67, 33] ./255 . Ok, so now just repeat the linspace process for each color:

  R = linspace (0, t (1), 50); G = linspace (0, t (2), 50); B = Linespace (0, T (3), 50); T = [R ', G', B ']; Map (1:50, :) = T;   

And now repeat for each of your other nodes.

For example:

  I = linspace (0,1,161); Imagesc (I (: ,, ,, (10)) colormap (map)   

 Enter image details here


Once per channel individually use an option to use linspace and repeat it for every color, Use a linear interpolation.

Create a matrix where each line is one color sphere

  T = [0, 0, 0% // dark 101, 67, 33% // brown 255, 105, 180% / / pink 255, 255, 255% // white 255, 255, 255] ./255;% // again Note - This means that the value between 161 and 255 will not be different   

and in which category each color should be (i.e. this vector colors) Defines the vacancy, they do not need to be in regular / common place):

  x = [0 50 120 160 255];   < P> And finally you can create a complete map with a simple interpolation:  
  map = interp1 (x / 255, t, linsepse (0,1, 255));   

test

  i = linspace (0,1, 255); Imagesc (I (wal (1,10), :) ') colormap (map)   

 Enter image details here

No comments:

Post a Comment