How to reduce blob using aspect ratio?
古いコメントを表示

.
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 件のコメント
Walter Roberson
2017 年 7 月 18 日
When you say "reduce" do you mean "set to black" ?
Dominic
2017 年 7 月 18 日
採用された回答
その他の回答 (2 件)
Walter Roberson
2017 年 7 月 18 日
1 投票
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 件のコメント
Dominic
2017 年 7 月 18 日
Walter Roberson
2017 年 7 月 18 日
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
2017 年 7 月 18 日
Walter Roberson
2017 年 7 月 18 日
編集済み: Walter Roberson
2017 年 7 月 18 日
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
2017 年 7 月 18 日
Walter Roberson
2017 年 7 月 18 日
Could you attach the original image? The one that does not have the red rectangles on it?
Dominic
2017 年 7 月 18 日
Walter Roberson
2017 年 7 月 18 日
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
2017 年 7 月 19 日
Image Analyst
2017 年 7 月 18 日
1 投票
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 件のコメント
Dominic
2017 年 7 月 18 日
Image Analyst
2017 年 7 月 18 日
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);
カテゴリ
ヘルプ センター および File Exchange で Region and Image Properties についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


