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

11 visualizzazioni (ultimi 30 giorni)
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?

Risposta accettata

Matt J
Matt J il 20 Ott 2021
Modificato: Matt J il 20 Ott 2021
load Image
montage( {BW, imfill(BW,'holes')}, [],'Back','w','Bor',5)
  1 Commento
Nadia_Img
Nadia_Img il 20 Ott 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.

Accedi per commentare.

Più risposte (0)

Prodotti


Release

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by