Remove everything outside of largest circle found by regionProps

2 vues (au cours des 30 derniers jours)
Nathan Hughes
Nathan Hughes le 4 Fév 2017
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!

Réponses (2)

Walter Roberson
Walter Roberson le 4 Fév 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;

Image Analyst
Image Analyst le 4 Fév 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.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by