How to extract objects from an image after i have measured properties through regionprops?

2 views (last 30 days)
I have extracted the properties of an binary image by 'Regionprops' like eccentricity,Area,Perimeter.
I have calculated the aspect ratio from the width of the Bounding Box.
Now I want to extract those objects which belong to certain criteria.
Here is my image.
Say,I want to extract objects with eccentricity>0.5 , aspect ratio=1.
How can i do this?

Accepted Answer

Image Analyst
Image Analyst on 9 May 2015
See my image segmentation tutorial - it goes over all of that. http://www.mathworks.com/matlabcentral/fileexchange/25157-image-segmentation-tutorial
Here's the relevant snippet. Change the filter parameters to be eccentricity and aspect ratio and you're all set.
% Now I'll demonstrate how to select certain blobs based using the ismember() function.
% Let's say that we wanted to find only those blobs
% with an intensity between 150 and 220 and an area less than 2000 pixels.
% This would give us the three brightest dimes (the smaller coin type).
allBlobIntensities = [blobMeasurements.MeanIntensity];
allBlobAreas = [blobMeasurements.Area];
% Get a list of the blobs that meet our criteria and we need to keep.
% These will be logical indices - lists of true or false depending on whether the feature meets the criteria or not.
% for example [1, 0, 0, 1, 1, 0, 1, .....]. Elements 1, 4, 5, 7, ... are true, others are false.
allowableIntensityIndexes = (allBlobIntensities > 150) & (allBlobIntensities < 220);
allowableAreaIndexes = allBlobAreas < 2000; % Take the small objects.
% Now let's get actual indexes, rather than logical indexes, of the features that meet the criteria.
% for example [1, 4, 5, 7, .....] to continue using the example from above.
keeperIndexes = find(allowableIntensityIndexes & allowableAreaIndexes);
% Extract only those blobs that meet our criteria, and
% eliminate those blobs that don't meet our criteria.
% Note how we use ismember() to do this. Result will be an image - the same as labeledImage but with only the blobs listed in keeperIndexes in it.
keeperBlobsImage = ismember(labeledImage, keeperIndexes);
% Re-label with only the keeper blobs kept.
labeledDimeImage = bwlabel(keeperBlobsImage, 8); % Label each blob so we can make measurements of it
% Now we're done. We have a labeled image of blobs that meet our specified criteria.

More Answers (0)

Community Treasure Hunt

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

Start Hunting!