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에서 Contrast Adjustment에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!


