Remove everything outside of largest circle found by regionProps
3 views (last 30 days)
Show older comments
Hello!
So I followed this example here: RegionProps and I was wanting to take the largest circle found and to segment out / clear everything else from the image.
Is there a straight forward way to do this, or rather a Matlab method of doing it?
Many thanks for any help!
0 Comments
Answers (2)
Walter Roberson
on 4 Feb 2017
YourRGBImage = .... original image
ROI = .... after threshholding
props = regionprops(ROI, 'Area, 'PixelIdxList');
[~, idx] = max([props.Area]);
this_region = props(idx).PixelIdxList;
mask = zeros(size(ROI), class(YourRGBImage));
mask(this_region{:}) = 1;
mask = mask(:,:,[1 1 1]); %replicate to 3D
masked_Image = YourRGBImage .* mask;
0 Comments
Image Analyst
on 4 Feb 2017
Before you call regionprops, simply call bwareafilt() on bw:
bw = bwareafilt(bw, 1); % Extract largest blob.
This will keep (segment out) only the largest circle in the image.
0 Comments
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!