How to fill a hollow donut-shaped object so that it looks like a circle?

7 vues (au cours des 30 derniers jours)
Nadia_Img
Nadia_Img le 20 Oct 2021
Commenté : Nadia_Img le 20 Oct 2021
I have a segmentation that looks like a donut (see image attached). I want to fill the "donut hole" so that the segmentation looks like a circle instead of a donut. I feel like there has to be a simple solution but I cannot seem to figure it out. I have tried inverting the image using imcomplement and then using bwconncomp and regionprops to find the pixel indices of the two objects in the image (1 being the centre circle, the other being the background pixels which are now white, as seen in the attached image). However, running bwconncomp on the inverted image, I can get the pixel indices of the white pixels, but there is no distinction between the two objects such that I can set the "background" area to black and keep the centre circle as white. Is there any other solution?

Réponse acceptée

Matt J
Matt J le 20 Oct 2021
Modifié(e) : Matt J le 20 Oct 2021
load Image
montage( {BW, imfill(BW,'holes')}, [],'Back','w','Bor',5)
  1 commentaire
Nadia_Img
Nadia_Img le 20 Oct 2021
Thank you, I used your 'imfill' approach but did bwperim first to get a smoother line. This is my code:
j = double(bwperim(mask_Alg1)); %get perimeters of inner and outer circles
objects = bwconncomp(j); %get pixel indices
numPixels = cellfun(@numel,objects.PixelIdxList); %find indices inner and outer circles
[smallest,endo_indx] = min(numPixels); %smallest index
j(objects.PixelIdxList{endo_indx}) = 0; %get rid of smallest index
Epi_Mask=imfill(j,'holes'); %create new mask using only inner index.

Connectez-vous pour commenter.

Plus de réponses (0)

Produits


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by