How to reduce blob using aspect ratio?
Afficher commentaires plus anciens

.
I have a binary image with 4 blobs. 3 of them has an aspect ratio of more than 1. and 1 has aspect ratio of 1. Now I want to reduce that blobs which aspect ratio more than 1 in binary image. How could i do this. Can some one please provide a code??
A picture is provided for understanding.
2 commentaires
Walter Roberson
le 18 Juil 2017
When you say "reduce" do you mean "set to black" ?
Dominic
le 18 Juil 2017
Réponse acceptée
Plus de réponses (2)
Walter Roberson
le 18 Juil 2017
1 vote
If you used regionprops() to get the BoundingBox in order to calculate the aspect ratio, then you can also ask for the pixel ID list. For each region that does not pass your aspect ratio test, assign 0 to the pixels given by those indices.
9 commentaires
Dominic
le 18 Juil 2017
Walter Roberson
le 18 Juil 2017
Before discarding the roi entries with the aspect ratio you do not want, use those roi to zero parts of the array. Just remember that X corresponds to columns and Y corresponds to rows.
There could potentially be a problem if the roi overlap though.
Dominic
le 18 Juil 2017
Walter Roberson
le 18 Juil 2017
Modifié(e) : Walter Roberson
le 18 Juil 2017
unwanted_roi = roi( aspectRatio ~= 1 ,:);
for K = 1 : size(unwanted_roi,1)
this_roi = unwanted_roi(K,:);
binary_image(this_roi(2) : this_roi(2) + this_roi(4) - 1, this_roi(1) : this_roi(1) - 1) = 0;
end
Dominic
le 18 Juil 2017
Walter Roberson
le 18 Juil 2017
Could you attach the original image? The one that does not have the red rectangles on it?
Dominic
le 18 Juil 2017
Walter Roberson
le 18 Juil 2017
Change the line to
binary_image(this_roi(2) : this_roi(2) + this_roi(4) - 1, this_roi(1) : this_roi(1) + this_roi(3) - 1) = 0;
Dominic
le 19 Juil 2017
Image Analyst
le 18 Juil 2017
1 vote
Use regionprops() to ask for the bounding box. Then compute aspect ratio: width over height, and height over width and take the max (or min), whichever you're using. Then use find() to find out which blobs to keep, then use ismember() to extract only those blobs. See my Image Segmentation Tutorial for a detailed demo. http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862&sort=downloads_desc
2 commentaires
Dominic
le 18 Juil 2017
Image Analyst
le 18 Juil 2017
If I have more time later I'll help more, in the meantime, do this:
props = regionprops(labeledImage, 'BoundingBox');
bb = [props.BoundingBox];
allWidths = bb(3:4:end);
allHeights = bb(4:4:end);
aspectRatio = [allWidths./allHeights ; allHeights ./ allWidths]
aspectRatios = max(aspectRatio, [], 1)
compactIndexes = find(aspectRatios > 5); % or whatever.
binaryImage = ismember(labeledImage, compactIndexes);
Catégories
En savoir plus sur Region and Image Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


