initialising a color map

2 views (last 30 days)
Harry
Harry on 16 Jul 2013
How do I create a colormap with n*m pixels which is all white and then display it?

Answers (2)

Image Analyst
Image Analyst on 16 Jul 2013
whiteColorMap = ones(256,3);
colormap(whiteColorMap);
colorbar;
Not sure what good that would be. What's the point?
  2 Comments
Harry
Harry on 16 Jul 2013
I'm just trying to learn how they work as I find the documentation about colormaps confusing.
Is there a way of specifying the dimensions of the image as at the moment it will only give a single pixel?
Essentially I want to set up an image so that I can manipulate it later.
Image Analyst
Image Analyst on 16 Jul 2013
No, that doesn't make sense. Colormaps are used as a pseudocolor look up table. For a typical uint8, 256 gray level image, use a 256 row by 3 column look up table. The row is the gray level, and the values in the row are the fraction of Red, Green, and Blue that that gray level will be displayed as. So it maps a gray level into a color. For example if you make a colormap
myColorMap = zeros(256,3); % All black
That will map all gray levels into black. Now if you set row 42 equal to a color
myColorMap(42, :) = [1, 0, 0]; % GL 42 maps to red
Then when you apply the colormap with the colormap() function, the look up table (myColorMap) says to make any/all pixels with gray level 42 show up as pure red instead of a gray with intensity 42. Does that explain it better? There are predefined colormaps you can use where you specify the number of levels, for example jet(256) or cool(256). Use fewer gray levels if you want a more "posterized" look.

Sign in to comment.


Iain
Iain on 16 Jul 2013
image_dat = uint16(randn(1024,1280)*5+5000); % random image (single colour channel)
imagesc(image_dat) % display it
colorbar % put the scale on the screen
colormap white % use the "white colormap"
custom_colormap = [r1 g1 b1;
r2 g2 b2
r3 g2 ...
...
rn gn bn];
r1, is the amount of red in the first colormap bin, g2 is the green in the second colormap bin, b3 is the blue in the 3rd colormap bin, (and so on) they are scaled from 0 (none) to 1 (max)
colormap(custom_colormap) % changes the display to the colormap you defined.
  2 Comments
Harry
Harry on 16 Jul 2013
I am still having trouble understanding how theses colormaps work as I don't see how you can give the image x and y dimensions. Because that custom colormap looks like series of bins with three different colours, but no indication of which row and column its on.
Image Analyst
Image Analyst on 16 Jul 2013
Did you see my comment?

Sign in to comment.

Tags

Community Treasure Hunt

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

Start Hunting!