Got Questions? Get Answers.
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:
Giving RGB color for certain Cdata of colorbar

Subject: Giving RGB color for certain Cdata of colorbar

From: edward kabanyas

Date: 17 Aug, 2011 04:39:09

Message: 1 of 10

Hi all,

Again I need your help..

Don't you know how to provide a certain RGB value for a certain Cdata of colorbar ? For example, CData = 0, the RGB = [255 255 255], white color. I know that we can do it by colormap editor, but it will take time. If possible, it is much better to set it directly in my matlab code. If you have experience with this problem, please share with me.

Thank you
Edward

Subject: Giving RGB color for certain Cdata of colorbar

From: Bruno Luong

Date: 17 Aug, 2011 07:33:07

Message: 2 of 10

I don't think you can escape of either change colormap and/ change the CData that maps to the while color. It's just the right mechanism for what you want to achieve.

Bruno

Subject: Giving RGB color for certain Cdata of colorbar

From: edward kabanyas

Date: 17 Aug, 2011 07:38:10

Message: 3 of 10

"Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j2fqrj$25n$1@newscl01ah.mathworks.com>...
> I don't think you can escape of either change colormap and/ change the CData that maps to the while color. It's just the right mechanism for what you want to achieve.
>
> Bruno

Thanks Bruno, a solution probably by changing the 0 value with NaN..

EDward

Subject: Giving RGB color for certain Cdata of colorbar

From: Bruno Luong

Date: 17 Aug, 2011 07:43:10

Message: 4 of 10

"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message <j2fr52$313$1@newscl01ah.mathworks.com>...
> "Bruno Luong" <b.luong@fogale.findmycountry> wrote in message <j2fqrj$25n$1@newscl01ah.mathworks.com>...
> > I don't think you can escape of either change colormap and/ change the CData that maps to the while color. It's just the right mechanism for what you want to achieve.
> >
> > Bruno
>
> Thanks Bruno, a solution probably by changing the 0 value with NaN..
>

I believe NaN will map to lowest color in the colormap. Now what if the colormap does not contain [0 0 0]?

Bruno

Subject: Giving RGB color for certain Cdata of colorbar

From: ImageAnalyst

Date: 17 Aug, 2011 15:49:52

Message: 5 of 10

On Aug 17, 12:39 am, "edward kabanyas" <djuky_...@yahoo.com> wrote:
> Hi all,
>
> Again I need your help..
>
> Don't you know how to provide a certain RGB value for a certain Cdata of colorbar ? For example, CData = 0, the RGB = [255 255 255], white color. I know that we can do it by colormap editor, but it will take time. If possible, it is much better to set it directly in my matlab code. If you have experience with this problem, please share with me.
>
> Thank you
> Edward

--------------------------------------------
I don't understand you. What is the Cdata of the colorbar? You make
up the color bar with the colormap() and colorbar() functions, so you
already know what monochrome intensity value gets mapped into which
color - you told it. For example:

imshow('cameraman.tif');
% Create a custom colormap
myColorMap = autumn(256);
% Apply it to the image.
colormap(myColorMap);
% Display the colorbar on the figure
colorbar();
% Enlarge figure to full screen.
set(gcf, 'Position', get(0,'Screensize'));


So that's why I'm confused.

Subject: Giving RGB color for certain Cdata of colorbar

From: Steven_Lord

Date: 17 Aug, 2011 16:19:37

Message: 6 of 10



"edward kabanyas" <djuky_hmi@yahoo.com> wrote in message
news:j2fgld$3t0$1@newscl01ah.mathworks.com...
> Hi all,
>
> Again I need your help..
>
> Don't you know how to provide a certain RGB value for a certain Cdata of
> colorbar ? For example, CData = 0, the RGB = [255 255 255], white color. I
> know that we can do it by colormap editor, but it will take time. If
> possible, it is much better to set it directly in my matlab code. If you
> have experience with this problem, please share with me.

I _think_ what you're looking for is the object's CDataMapping property.

http://www.mathworks.com/help/techdoc/ref/surface_props.html#CDataMapping

If it's set to 'scaled' then MATLAB will map the range of CData values
associated with the object to the color limits of the axes. If set to
'direct' then no scaling takes place and the CData values are used as
indices into the colormap directly.

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Giving RGB color for certain Cdata of colorbar

From: edward kabanyas

Date: 17 Aug, 2011 23:58:08

Message: 7 of 10

hi Steven,

Thanks for reply. Is it not possible to modify the "Jet" or "HSV" colormap ?. Because the default for Jet color is from BLUE (lowest Cdata)-RED. For example, we modify this jet, for example WHITE (lowest C data)-RED ..

Thank you
Edward



"Steven_Lord" <slord@mathworks.com> wrote in message <j2gpmo$ab6$1@newscl01ah.mathworks.com>...
>
>
> "edward kabanyas" <djuky_hmi@yahoo.com> wrote in message
> news:j2fgld$3t0$1@newscl01ah.mathworks.com...
> > Hi all,
> >
> > Again I need your help..
> >
> > Don't you know how to provide a certain RGB value for a certain Cdata of
> > colorbar ? For example, CData = 0, the RGB = [255 255 255], white color. I
> > know that we can do it by colormap editor, but it will take time. If
> > possible, it is much better to set it directly in my matlab code. If you
> > have experience with this problem, please share with me.
>
> I _think_ what you're looking for is the object's CDataMapping property.
>
> http://www.mathworks.com/help/techdoc/ref/surface_props.html#CDataMapping
>
> If it's set to 'scaled' then MATLAB will map the range of CData values
> associated with the object to the color limits of the axes. If set to
> 'direct' then no scaling takes place and the CData values are used as
> indices into the colormap directly.
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

Subject: Giving RGB color for certain Cdata of colorbar

From: ImageAnalyst

Date: 18 Aug, 2011 02:10:26

Message: 8 of 10

It's possible, but not recommended, to overwrite built in functions
like the colormap functions jet, autumn, winter, lines, etc. You
should make a copy of them like I already showed you, and modify that
instead:

% Create a custom colormap
myColorMap = autumn(256);

% Now, modify 0 to be white:
myColorMap(1, :) = [1 1 1];

Subject: Giving RGB color for certain Cdata of colorbar

From: Steven_Lord

Date: 18 Aug, 2011 20:42:10

Message: 9 of 10



"ImageAnalyst" <imageanalyst@mailinator.com> wrote in message
news:193369a3-9d93-4ad1-9c49-f497c20a1b00@q1g2000vbj.googlegroups.com...
> It's possible, but not recommended, to overwrite built in functions
> like the colormap functions jet, autumn, winter, lines, etc. You
> should make a copy of them like I already showed you, and modify that
> instead:
>
> % Create a custom colormap
> myColorMap = autumn(256);
>
> % Now, modify 0 to be white:
> myColorMap(1, :) = [1 1 1];

Instead of making a copy of the color map functions that ship with MATLAB
and modifying them, you could create your own function that calls the
existing color map function and modifies the output of that function. Since
you referred to JET in your response to me, let's create a jetWithWhite
function:

function y = jetWithWhite(varargin)
y = jet(varargin{:});
y(1, :) = [1 1 1];

Now instead of:

figure('Colormap', jet);

you would use:

figure('Colormap', jetWithWhite);

I needed/wanted to use varargin in jetWithWhite because JET can be called
with either 0 or 1 input, and jetWithWhite should behave the same way (and
indeed should just pass its input, if any, into JET.)

--
Steve Lord
slord@mathworks.com
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

Subject: Giving RGB color for certain Cdata of colorbar

From: edward kabanyas

Date: 19 Aug, 2011 00:33:08

Message: 10 of 10

Hi Steven and ImageAnalyst;

Thanks for your suggestion. it works..Thanks again,

Edward

"Steven_Lord" <slord@mathworks.com> wrote in message <j2jtf1$l0n$1@newscl01ah.mathworks.com>...
>
>
> "ImageAnalyst" <imageanalyst@mailinator.com> wrote in message
> news:193369a3-9d93-4ad1-9c49-f497c20a1b00@q1g2000vbj.googlegroups.com...
> > It's possible, but not recommended, to overwrite built in functions
> > like the colormap functions jet, autumn, winter, lines, etc. You
> > should make a copy of them like I already showed you, and modify that
> > instead:
> >
> > % Create a custom colormap
> > myColorMap = autumn(256);
> >
> > % Now, modify 0 to be white:
> > myColorMap(1, :) = [1 1 1];
>
> Instead of making a copy of the color map functions that ship with MATLAB
> and modifying them, you could create your own function that calls the
> existing color map function and modifies the output of that function. Since
> you referred to JET in your response to me, let's create a jetWithWhite
> function:
>
> function y = jetWithWhite(varargin)
> y = jet(varargin{:});
> y(1, :) = [1 1 1];
>
> Now instead of:
>
> figure('Colormap', jet);
>
> you would use:
>
> figure('Colormap', jetWithWhite);
>
> I needed/wanted to use varargin in jetWithWhite because JET can be called
> with either 0 or 1 input, and jetWithWhite should behave the same way (and
> indeed should just pass its input, if any, into JET.)
>
> --
> Steve Lord
> slord@mathworks.com
> To contact Technical Support use the Contact Us link on
> http://www.mathworks.com

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