Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: damage measurement in a micrograph
Date: Wed, 11 Nov 2009 18:50:07 +0000 (UTC)
Organization: IIT Kanpur
Lines: 74
Message-ID: <hdf10v$1t1$1@fred.mathworks.com>
References: <hcadg1$3m1$1@fred.mathworks.com> <op.u2kwubcja5ziv5@uthamaa.dhcp.mathworks.com> <0396a454-3b1a-46e4-bffb-e769ea7043d1@s15g2000yqs.googlegroups.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-02-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1257965407 1953 172.30.248.37 (11 Nov 2009 18:50:07 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Wed, 11 Nov 2009 18:50:07 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 2015903
Xref: news.mathworks.com comp.soft-sys.matlab:584307


ImageAnalyst <imageanalyst@mailinator.com> wrote in message <0396a454-3b1a-46e4-bffb-e769ea7043d1@s15g2000yqs.googlegroups.com>...
> Ashish's code will find the defects - the large dark areas.  The code
> I'm giving you below will find the grains.  Run it and see.  What you
> have to do to find the grains not including the defects is to use
> Ashish's defect image and use it to mask (multiply) my labeled image.
> That way you'll get the grains not including the defects.  The key to
> finding the grain boundaries is to use the bottom hat filter.  Then
> skeletonize them down to single dividing lines.  Then just label, mask
> with Ashish's defect map, then call regionprops on the grains.  You
> can call regionprops on the defect image if you want info on the
> defects too.  I don't have anymore time to mask out the grains with
> the defects (I already spent an hour on this algorithm for you) but I
> think you can handle it from here.
> 
> % Demo to find grains in a metallurgical micrograph.
> % by ImageAnalyst
> % function test
> clc;
> close all;
> clear all;
> workspace; % Show the Workspace panel.
> originalImage = imread('grains.jpg');
> tic; % Start timer.
> originalImage = rgb2gray(originalImage);
> figure;
> imshow(originalImage);
> title('Original Image');
> 
> % Do a bottom hat filter.
> se = strel('disk', 5);
> topHatImage = imbothat(originalImage,se);
> figure;
> imshow(topHatImage, []);
> title('Bottom Hat Image');
> % imwrite(topHatImage, 'bottom hat image.bmp');
> 
> % Threshold at 20
> figure;
> grainsImage = topHatImage > 20;
> imshow(grainsImage, []);
> % Remove small debris.
> grainsImage = bwareaopen(grainsImage, 50);
> imshow(grainsImage, []);
> % Close gaps
> grainsImage = imclose(grainsImage, ones(3));
> imshow(grainsImage, []);
> % Skeletonize to find boundary lines.
> grainsImage = bwmorph(grainsImage, 'skel', inf);
> grainsImage = bwmorph(grainsImage, 'spur', inf);
> imshow(grainsImage, []);
> % Remove small lines.
> grainsImage = ~bwareaopen(grainsImage, 650);
> imshow(grainsImage, []);
> % Remove partial grains, where we don't have the complete grain.
> grainsImage = imclearborder(grainsImage, 4);
> % Show the final image.
> imshow(grainsImage, []);
> title('Thresholded Image');
> 
> % Label it.
> labeledImage = bwlabel(grainsImage, 4);
> coloredLabeledImage = label2rgb(labeledImage, 'lines');
> figure;
> imshow(coloredLabeledImage, []);
> title('Labeled Image');
> grainMeasurements = regionprops(labeledImage, 'all');
> toc; % Stop timer.
____________

Nice and thanks..

but what i asked is to find the centroid of each grain in the image....(a grain is the one which is surrounded by a closed black boundary...i.e the black lines are grain boundaries and the gray portion is grain)...i tried to sort out...but i'm unable to...help me in finding the centroid of each grain....

thank you..