Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

Thread Subject:
Custom colormap

Subject: Custom colormap

From: fas

Date: 1 Jan, 2010 04:06:41

Message: 1 of 8

Hi,
I have used 'colormap' with custom color with two colors. One extreme
is white and other extreme is red ( so the variation is between white
to red). I can do it by going into the property of the figure, but I
want to do it with code. Any idea

Subject: Custom colormap

From: ImageAnalyst

Date: 1 Jan, 2010 04:09:56

Message: 2 of 8

On Dec 31, 11:06 pm, fas <faisalmu...@gmail.com> wrote:
> Hi,
> I have used 'colormap' with custom color with two colors. One extreme
> is white and other extreme is red ( so the variation is between white
> to red). I can do it by going into the property of the figure, but I
> want to do it with code. Any idea

------------------------------------------------
There is a colormap() function, you know....

Subject: Custom colormap

From: fas

Date: 2 Jan, 2010 02:17:12

Message: 3 of 8

On Jan 1, 3:09 pm, ImageAnalyst <imageanal...@mailinator.com> wrote:
> On Dec 31, 11:06 pm, fas <faisalmu...@gmail.com> wrote:
>
> > Hi,
> > I have used 'colormap' with custom color with two colors. One extreme
> > is white and other extreme is red ( so the variation is between white
> > to red). I can do it by going into the property of the figure, but I
> > want to do it with code. Any idea
>
> ------------------------------------------------
> There is a colormap() function, you know....

Of course I know of colormap function and that is why I assume that it
can be manipulated through code. The only problem is that I do not
know how to solve my trivial problem through colormap(). Any help ??

Subject: Custom colormap

From: Jan Simon

Date: 2 Jan, 2010 03:26:03

Message: 4 of 8

Dear fas!

> > There is a colormap() function, you know....
>
> Of course I know of colormap function and that is why I assume that it
> can be manipulated through code. The only problem is that I do not
> know how to solve my trivial problem through colormap(). Any help ??

Did you take a look at:
  help colormap
or
  doc colormap
?

Good night, Jan

Subject: Custom colormap

From: fas

Date: 2 Jan, 2010 04:29:47

Message: 5 of 8

On Jan 2, 2:26 pm, "Jan Simon" <matlab.THIS_Y...@nMINUSsimon.de>
wrote:
> Dear fas!
>
> > > There is a colormap() function, you know....
>
> > Of course I know of colormap function and that is why I assume that it
> > can be manipulated through code. The only problem is that I do not
> > know how to solve my trivial problem through colormap(). Any help ??
>
> Did you take a look at:
>   help colormap
> or
>   doc colormap
> ?
>
> Good night, Jan

I am afraid that I posted this question after going through the help/
doc file. Since after several experiments, I failed to do so I am
asking for help if any ???

Subject: Custom colormap

From: Jan Simon

Date: 2 Jan, 2010 04:46:02

Message: 6 of 8

Dear fas!

What happens if you type:
  colormap([1,0,0; 1,1,1])

Or set the property directly:
  set(gcf, 'ColorMap', [1,0,0; 1,1,1])

Does this help? Jan

Subject: Custom colormap

From: ImageAnalyst

Date: 2 Jan, 2010 06:33:07

Message: 7 of 8

On Jan 1, 11:29 pm, fas <faisalmu...@gmail.com> wrote:
> I am afraid that I posted this question after going through the help/
> doc file. Since after several experiments, I failed to do so I am
> asking for help if any ???
------------------------------------------------------------------------------------------------------------------------
OK, perhaps this demo I wrote for you will help you to not fail
anymore.
Be sure to join any lines broken into two by the newsreader.


% Demo to apply random colormaps to a gray scale image.
% by ImageAnalyst
clc;
close all;
clear all;
workspace; % Display workspace panel.
clc;
close all;
clear all;
workspace; % Display workspace panel.
% Read in standard MATLAB demo image.
grayImage = imread('cameraman.tif');
subplot(1, 2, 1);
imshow(grayImage);
title('Original Grayscale Image');
set(gcf, 'Position', get(0,'Screensize')); % Maximize figure.

% Make color maps - loop applying random colormaps until told to stop.
gl = 1:256;
promptMessage = sprintf('Do you want to continue with a different
colormap?');
count = 1;
while true
        % Make sine wave colormaps.
rOffset = 256*rand(1,1);
gOffset = 256*rand(1,1);
bOffset = 256*rand(1,1);
period = 50;
cmapR = (sin((gl-rOffset)/period)+1)/2;
cmapG = (sin((gl-gOffset)/period)+1)/2;
cmapB = (sin((gl-bOffset)/period)+1)/2;
cmap = [cmapR; cmapG; cmapB]';

% Plot colormap in the second axes
subplot(1, 2, 2);
hold off;
plot(gl, cmapR, 'r-');
hold on;
plot(gl, cmapG, 'g-');
plot(gl, cmapB, 'b-');
caption = sprintf('Random colormap #%d', count);
title(caption);

% Apply colormap to the axes containing the image.
subplot(1, 2, 1);
colormap(cmap);
caption = sprintf('Image pseudocolored with random colormap #%d',
count);
title(caption);

% Ask user if they want another colormap
button = questdlg(promptMessage, 'Continue with another colormap?',
'Continue', 'Cancel', 'Continue');
if strcmp(button, 'Cancel')
break;
end
count = count + 1;
end

Subject: Custom colormap

From: fas

Date: 4 Jan, 2010 06:18:45

Message: 8 of 8

On Jan 2, 3:46 pm, "Jan Simon" <matlab.THIS_Y...@nMINUSsimon.de>
wrote:
> Dear fas!
>
> What happens if you type:
>   colormap([1,0,0; 1,1,1])
>
> Or set the property directly:
>   set(gcf, 'ColorMap', [1,0,0; 1,1,1])
>
> Does this help? Jan

Thanks Jan, precisely what I want!.

Tags for this Thread

What are tags?

A tag is like a keyword or category label associated with each thread. Tags make it easier for you to find threads of interest.

Anyone can tag a thread. Tags are public and visible to everyone.

Contact us