Path: news.mathworks.com!not-for-mail
From: "Vihang Patil" <vihang_patil@yahoo.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: Area of specific pixel color?
Date: Fri, 21 Mar 2008 06:44:02 +0000 (UTC)
Organization: Konem Solutions
Lines: 60
Message-ID: <frvlfi$3rh$1@fred.mathworks.com>
References: <frvesa$ol9$1@news.ks.uiuc.edu>
Reply-To: "Vihang Patil" <vihang_patil@yahoo.com>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1206081842 3953 172.30.248.35 (21 Mar 2008 06:44:02 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Fri, 21 Mar 2008 06:44:02 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 413701
Xref: news.mathworks.com comp.soft-sys.matlab:458435


Allen <ajhalldeleteme@gmail.com> wrote in message 
<frvesa$ol9$1@news.ks.uiuc.edu>...
> Hi guys,
> 
> Quick Q version:
> 	How does one determine the fractional pixel area 
of a color.  i.e., if 
> I highlight grains one color, how can I determine the 
area of the 
> colored portion in pixels?
> 
> Longer Q version:
> 	I'm doing something complex (finding the surface 
area of a tilted 
> segment of an image)... but I think it can be done very 
simply.
> 	I have a method to highlight only the area of 
interest, and now I want 
> to determine the area which is highlighted.  I'm 
assuming this will be 
> in pixels x pixels of the image, but can convert this 
easily to 
> real-space (as well as use the cosine of the tilt to 
give me the real area).
> 	So, is there a good way to get image information 
about areas 
> highlighted with specific colors etc.?  If I painted one 
section of the 
> image all red, for instance, could I determine the pixel 
x pixel area?
> 
> Thanks a ton for your help and thoughts, everyone!!  :)
> -Allen
> 
> ps- this is an attempt to measure the surface-area of 
facets in a grown 
> crystal.  The data is taken from an AFM, and I can 
highlight them based 
> on the surface-gradient information.  The resulting 
images in plan-view 
> will be flat (forshortened areas etc.)


Hello Allen
If you could highlight the area of interest, then it means 
that you know that threshold. So you could easily convert 
this RGB image to grayscale and then binary B/W image. And 
then use bwlabel() and regionprops() followed by it..

ex:
RGB = imread('Your Image');
gray = rgb2gray(RGB);
bw = im2bw(gray, <computed threshold>);
L = bwlabel(bw);
stats = regionprops(L,'All');
area = [stats.Area];

HTH
Vihang