Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!t21g2000yqi.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Please Help, How to calculate the area percentage of each color
Date: Wed, 10 Jun 2009 19:39:40 -0700 (PDT)
Organization: http://groups.google.com
Lines: 40
Message-ID: <47524990-144b-48a8-b54f-9270ca25fb05@t21g2000yqi.googlegroups.com>
References: <h0oll9$r0s$1@fred.mathworks.com> <c1d7887a-da8f-4521-baa5-9d764061ac5e@o36g2000vbi.googlegroups.com> 
	<h0pa7d$bcf$1@fred.mathworks.com>
NNTP-Posting-Host: 75.186.70.56
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1244687980 30174 127.0.0.1 (11 Jun 2009 02:39:40 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Thu, 11 Jun 2009 02:39:40 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: t21g2000yqi.googlegroups.com; posting-host=75.186.70.56; 
	posting-account=0rLUzAkAAABojYSRC64DkTbtiSCX77HH
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; 
	GTB6; .NET CLR 1.1.4322; .NET CLR 2.0.50727; .NET CLR 3.0.04506.648; .NET CLR 
	3.5.21022),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:546394


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.');