How to reduce blob using aspect ratio?
Ältere Kommentare anzeigen

.
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 Kommentare
Walter Roberson
am 18 Jul. 2017
When you say "reduce" do you mean "set to black" ?
Dominic
am 18 Jul. 2017
Akzeptierte Antwort
Weitere Antworten (2)
Walter Roberson
am 18 Jul. 2017
1 Stimme
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 Kommentare
Dominic
am 18 Jul. 2017
Walter Roberson
am 18 Jul. 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
am 18 Jul. 2017
Walter Roberson
am 18 Jul. 2017
Bearbeitet: Walter Roberson
am 18 Jul. 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
am 18 Jul. 2017
Walter Roberson
am 18 Jul. 2017
Could you attach the original image? The one that does not have the red rectangles on it?
Dominic
am 18 Jul. 2017
Walter Roberson
am 18 Jul. 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
am 19 Jul. 2017
Image Analyst
am 18 Jul. 2017
1 Stimme
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 Kommentare
Dominic
am 18 Jul. 2017
Image Analyst
am 18 Jul. 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);
Kategorien
Mehr zu Contrast Adjustment finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


