Path: news.mathworks.com!not-for-mail
From: "Hooman " <hoomanp@rci.rutgers.edu>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Please Help, How to calculate the area percentage of each color
Date: Thu, 11 Jun 2009 05:06:01 +0000 (UTC)
Organization: Rutgers University
Lines: 54
Message-ID: <h0q3bp$i0u$1@fred.mathworks.com>
References: <h0oll9$r0s$1@fred.mathworks.com> <c1d7887a-da8f-4521-baa5-9d764061ac5e@o36g2000vbi.googlegroups.com> <47524990-144b-48a8-b54f-9270ca25fb05@t21g2000yqi.googlegroups.com>
Reply-To: "Hooman " <hoomanp@rci.rutgers.edu>
NNTP-Posting-Host: webapp-03-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1244696761 18462 172.30.248.38 (11 Jun 2009 05:06:01 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 11 Jun 2009 05:06:01 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 1723265
Xref: news.mathworks.com comp.soft-sys.matlab:546408


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <47524990-144b-48a8-b54f-9270ca25fb05@t21g2000yqi.googlegroups.com>...
> On Jun 10, 5:57 pm, "Hooman " <hoom...@rci.rutgers.edu> wrote:
> > First of all thanks for your reply.
> > could you be more specific, since I have never used the histogram I am not sure how to use it.
> > It would be perfect if you tell me what should I do in a more basic way or tell me which part of Matlab help should I read to get this.
> >
> > Thanks alot-
> -----------------------------------------------------------------------
> Perhaps this demo will get you started:
> 
> % Demo macro
> % by ImageAnalyst
> clc;
> close all;
> % Create some sample image data with 256 separate discrete values.
> [X,Y,Z] = peaks(60);
> minv = min(min(Z));
> maxv = max(max(Z));
> subplot(1, 2, 1);
> originalImage = uint8(255 * (Z - minv) / (maxv - minv));
> imagesc(originalImage);
> title('Original Image');
> % Get its histogram.  The 256 gray levels will be binned into bins of
> width 256/16 = 16 gray levels.
> [pixelCounts grayLevels] = imhist(originalImage, 16);
> % Plot the histogram (relative areas).
> subplot(1, 2, 2);
> bar(pixelCounts);
> title('Histogram');
> % Get the area fractions.
> areaPercentages = 100.0 * single(pixelCounts) / sum(pixelCounts);
> % Display in the command window.
> message = sprintf('gl, grayLevels(gl), areaFractions(gl)');
> disp(message);
> for gl = 1 : length(grayLevels)
> 	message = sprintf('%d\t%5.1f\t%6.2f%%',gl, grayLevels(gl),
> areaPercentages(gl));
> 	disp(message);
> end
> set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.
> msgbox('Done.  Look in the command window.');

thanks alot, that was a very good demo,
I have some questions about this, 

1 - how would I know which gray(out of 16) is for which color, is there anyway for me to find out which grayscale is which color?

2- if I define 4 bins instead of 16, is it possible that the algorithm put more than one color in 1 bin and no color in another bin or that wont happen?

3- what should I use as my input image matrix here, can I use the same matrix that I use for contour map input or I need something else?

Thanks alot for your help and for your time,
Best wishes,
Hooman