How to close small holes inside each blob?
Mostrar comentarios más antiguos
Hi,


I have attached two images above. The 140_multiplied.jpg is the original image. I plan to close the small holes inside the regions. I tried the code below. But the result is shown in 140_multiplied_closed.jpg which is not correct as it changes the shape of the regions. Any suggestions would be appreciated. Thank you.
result_img=imread('140_multiplied.jpg');
% Close the holes in the regions of the result image
result_img_filled = imfill(result_img, 'holes');
result_img_closed = imclose(result_img_filled, strel('disk', 5)); % Adjust the disk size as needed
1 comentario
Morphological closing with imclose() will change the mask shape dependent on the shape of the structuring element.
You can use imfill() to close all holes that aren't connected to the image edge.
If you only want to fill holes below a certain size, you can try something like
% get rid of holes below a certain size
minimumholearea = 25; % area in pixels
mask = ~bwareaopen(~mask,minimumholearea);
Respuesta aceptada
Más respuestas (0)
Categorías
Más información sobre Images en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!

