Path: news.mathworks.com!newsfeed-00.mathworks.com!newsfeed2.dallas1.level3.net!news.level3.com!postnews.google.com!d4g2000vbm.googlegroups.com!not-for-mail
From: ImageAnalyst <imageanalyst@mailinator.com>
Newsgroups: comp.soft-sys.matlab
Subject: Re: find Spots in the Image
Date: Tue, 22 Sep 2009 19:26:17 -0700 (PDT)
Organization: http://groups.google.com
Lines: 64
Message-ID: <188a88d3-4aae-41d8-80bb-1dc1a3394ec8@d4g2000vbm.googlegroups.com>
References: <h96qbb$ug$1@fred.mathworks.com> <h96r1t$emm$1@fred.mathworks.com> 
	<3aeaa406-d937-4807-a397-4e46c2ea46ec@s6g2000vbp.googlegroups.com> 
	<h99d10$6ge$1@fred.mathworks.com> <h9a9no$jni$1@fred.mathworks.com> 
	<h9blnq$or4$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: quoted-printable
X-Trace: posting.google.com 1253672777 21707 127.0.0.1 (23 Sep 2009 02:26:17 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 23 Sep 2009 02:26:17 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: d4g2000vbm.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; AskTB5.5),gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:572227


On Sep 22, 7:14 pm, "Yi " <heyinba0...@hotmail.com> wrote:
> hi ImageAnalyst
> i have read your tutorial. this is the code what i learn from your tutorial:
>
> % Read in standard MATLAB demo image
> originalImageX = imread('testImage.JPG');
> originalImage = rgb2gray(originalImageX);
> thresholdValue = 1;
> binaryImage = originalImage < thresholdValue;
> binaryImage = imfill(binaryImage, 'holes');
> labeledImage = bwlabel(binaryImage, 8);
> blobMeasurements = regionprops(labeledImage, originalImage, 'EulerNumber');  
> numberOfBlobs = size(blobMeasurements, 1);
>
> after i run this function
> i got numberOfBlobs = 49 and each of them has a EulerNumber which equal to "1"
> so i really can not understand the meaning of this result.
> could you help me and give me some ideas?
>
> thanks so much
>
--------------------------------------------------------------------------------
Try this:

workspace;
% Read in demo image
originalImageX = imread('testimageg.jpg');
originalImage = rgb2gray(originalImageX);
subplot(3,1,1);
imshow(originalImage, []);
title('Original Image');

thresholdValue = 150;
binaryImage = originalImage < thresholdValue;
subplot(3,1,2);
imshow(binaryImage, []);
title('Binarized Image');

labeledImage = bwlabel(binaryImage, 8);
subplot(3,1,3);
imshow(labeledImage, []);
title('Labeled Image');

blobMeasurements = regionprops(labeledImage, originalImage,
'EulerNumber', 'Centroid');
numberOfBlobs = size(blobMeasurements, 1);
for blobNumber = 1 : numberOfBlobs
    thisBlobsEulerNumber = int32(blobMeasurements
(blobNumber).EulerNumber);  % Get list of pixels in current blob.
	numberOfHoles = int32(1 - thisBlobsEulerNumber);
	blobCentroid = blobMeasurements(blobNumber).Centroid;		% Get
centroid.
	labelString = sprintf('Blob #%d', blobNumber);
	text(blobCentroid(1), blobCentroid(2), labelString, 'Color', [1 .25 .
10], 'FontSize', 14);
    fprintf(1,'Blob #%d Euler Number = %d, number of Holes = %d \n',
blobNumber, thisBlobsEulerNumber, numberOfHoles);
end
set(gcf, 'Position', get(0, 'ScreenSize')); % Maximize figure.
uiwait(msgbox('Check out the command window'));