Displaying Lab colors on a 3d surface

5 views (last 30 days)
Jon
Jon on 9 Aug 2011
I am trying to plot a color distribution of an image, and it would be nice to quickly see which colors are more frequent. To do this I have fit Gaussian curves over the a and b components of Lab space. I'm setting L constant so I can visualize it in 3d.
so I have the range of a and b colors that I want to plot.
%Get the range of a and b values
min_a = min(a_colors);
max_a = max(a_colors);
min_b = min(b_colors);
max_b = max(b_colors);
xspace = linspace(min_a,max_a,150);
yspace = linspace(min_b,max_b,150);
%Create x,y pairs for each point on the grid corresponding to
%a*b space
[x,y] = meshgrid(xspace,yspace);
This gives me the x and y for the surf function. I have another process that gives me the height values for the surface. It produces the variable z. For now we can pretend z = 1 everywhere because it doesn't matter for my problem.
What I would like to do is find some C such that surf(x,y,z,C) would plot the surface such that the color of the grid was a function of x (the a colors) and y (the b colors). And it looked similar to a subset of this picture.
In other words for each x,y point on the surface, I would like to color that point like this Lab2RGB([50, x, y]).
I tried to do it like this:
L = zeros(150,150) + 50; %Keep L at a constant 50
CLab = zeros(150,150,3);
CLab(:,:,1) = L;
CLab(:,:,2) = x;
CLab(:,:,3) = y;
CRGB = Lab2RGB(CLab);
surf(x,y,z,CRGB);
but that didn't do anything. I just got a blank screen.
I'm relativly new to matlab and I'm pretty stumped as to how to do this.
EDIT: I solved the issue. The problem was that I didn't normalize CRGB to the range 0 to 1. I feel pretty silly now.
Change the line CRGB = Lab2RGB(CLab); to CRGB = double(Lab2RGB(CLab))./255; and everything works.

Answers (2)

Image Analyst
Image Analyst on 10 Aug 2011
You need to look at the "Color Frequency Image" - a concept developed just a few years ago by Japanese professors T. Kashiwagi & S. Oe. You can find the MATLAB implementation here http://www.mathworks.com/matlabcentral/fileexchange/28164-color-frequency-image
%-------------------------------------------------------------------------------
% http://ieeexplore.ieee.org/xpl/freeabs_all.jsp?tp=&arnumber=4421050&isnumber=4420928
% Introduction of frequency image and applications
% Kashiwagi, T. Oe, S.
% Tokushima Prefectural Ind. Technol. Center, Tokushima;
%
% This paper appears in: SICE (Society of Instrument and Control Engineers), 2007 Annual Conference
% Publication Date: 17-20 Sept. 2007
% On page(s): 584-591
% Location: Takamatsu,
% ISBN: 978-4-907764-27-2
% INSPEC Accession Number: 9853526
% Digital Object Identifier: 10.1109/SICE.2007.4421050
% Current Version Published: 2008-01-07
%
% Abstract
% We introduce a new imaging method of "Frequency Image" and its applications.
% This new image is made from multi-dimensional features of an image and presents
% a distribution of the frequency of feature vectors. Especially, selecting R, G and B colors
% as the three features of an image, Frequency Image is a feature image of which pixel
% represents the frequency of the same color pixels. In this paper, first, we explain
% the basic idea and how to make this Frequency Image. Next, we introduce some effective
% applications using this image. Finally we mention excellent potentials of Frequency Images.
%-------------------------------------------------------------------------------
Next you need to download ImageJ http://rsb.info.nih.gov/ij/ and then download the "3D Color Inspector" plug-in http://rsb.info.nih.gov/ij/plugins/color-inspector.html so that you can visualize the 3D color gamut. You will be glad you did. It is a very powerful visualization technique that MATLAB does not yet have, though I have a meeting with the Image Processing Toolbox developers the day after tomorrow on what it would take to implement that functionality. Actually I have a script that you can use to run that plug-in directly from MATLAB without having to run ImageJ - let me know if you want it. I have that script tied to a toolbar button on my MATLAB shortcut toolbar interface. I know a lot about color (as you can tell from my logo) so if you have questions, ask, or (if it doesn't involve MATLAB but just color science in general) ask in sci.engr.color. ImageAnalyst
  2 Comments
Jon
Jon on 10 Aug 2011
That's not quite what I asked. I already have a way of viewing the color distribution and it works well for what I need it to do.
I have a distribution. Here is an example, where I model the color distribution with 2 Gaussians, which creates a simple foreground/background segmentation. http://i.imgur.com/Qkyb0.png
here is the picture used to create this information: http://cgm.technion.ac.il/Computer-Graphics-Multimedia/Software/Saliency/leaf.jpg
What I would like, is instead of the colormap on the gaussian to be a function of height (z) and use an hsv colormap. I would like the x coordinate to correspond to a values in Lab space and I would like y values to correspond to b values in Lab space, so I could see exactly which colors the Gaussians are describing.
The second Gaussian explains the red colors in the leaf which and you can see that because the gaussian is centered around the -3ish / -3ish point in ab space, which corresponds to red and colors that look like red.
The first gaussian is much more spread out because only 2 were used to create this mixture model. It just explains every other color which is less frequent, but you can see some blueish colors are more common, so it would be useful to see the a bulge in the graph on a a bluish area.
I don't really care about modeling the distribution, because that is already done. I just would like to assign Lab colors to x,y coordinates on the surface of these graphs.
Jon
Jon on 10 Aug 2011
This is a picture of what I want the XY view of the graph to look like. http://imgur.com/7OEdJ This is the output of imshow(CRGB) from the previous code in my original answer.

Sign in to comment.


Image Analyst
Image Analyst on 11 Aug 2011
I'm confused by the grammar on this sentence: "What I would like, is instead of the colormap on the gaussian to be a function of height (z) and use an hsv colormap." What I'm guessing this means is "What I would like, instead of a Gaussian image with a colormap applied, is to see the Gaussian displayed as a function of height (z) and use colormap that has different colors at different heights (values)." If that's what you meant, then maybe you are ask for something like surf() or waterfall(), but I'm not sure because I don't understand.
You say "I would like the x coordinate to correspond to a values in Lab space and I would like y values to correspond to b values in Lab space, so I could see exactly which colors the Gaussians are describing. " Then you need to get the arrays you are displaying to be lab instead of hsv:
cform = makecform('srgb2lab');
lab_Image = applycform(rgbImage, cform);
Then display your gamut (not your spatial image).

Community Treasure Hunt

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

Start Hunting!