how to select the object with the largest area ?

26 views (last 30 days)
hi...i have i used bwconvhull to detect a certain part of the image, as you can see in the image that there are number of objects with certain centroids. what i want to do is to detect the object with the largest area(1st big one from the left) and neglect the others.
which method should i follow?
i will will be very thankful for your help.
following is the code(its very roughly written as i am still working on it. Sorry for any inconvenience in advance)
CH_objects = bwconvhull(c,'objects');
imshow(CH_objects);
title('Objects Convex Hull');
bwarea(CH_objects)
Ilabel =bwlabel(CH_objects,8);
stat = regionprops(Ilabel,'centroid');
imshow(CH_objects); hold on;
for x = 1: numel(stat)
plot(stat(x).Centroid(1),stat(x).Centroid(2),'ro');
end

Accepted Answer

Image Analyst
Image Analyst on 22 Dec 2013
I have a demo for exactly that purpose. Please click the blue link (ExtractBiggestBlob.m) below copy the program to MATLAB and run it.
  2 Comments
Image Analyst
Image Analyst on 22 Dec 2013
The main function is at the bottom:
% Function to return the specified number of largest or smallest blobs in a binary image.
% If numberToExtract > 0 it returns the numberToExtract largest blobs.
% If numberToExtract < 0 it returns the numberToExtract smallest blobs.
% Example: return a binary image with only the largest blob:
% binaryImage = ExtractNLargestBlobs(binaryImage, 1)
% Example: return a binary image with the 3 smallest blobs:
% binaryImage = ExtractNLargestBlobs(binaryImage, -3)
function binaryImage = ExtractNLargestBlobs(binaryImage, numberToExtract)
all the stuff above it to make a nice demo for you.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!