Hollow out binary matrix shape

4 visualizaciones (últimos 30 días)
Dante Basile
Dante Basile el 3 de Jul. de 2019
Respondida: Rik el 3 de Jul. de 2019
I have an irregularly shaped blob of ones in a binary matrix. I want to shrink this by a user defined radius and then subtract from the original to get a hollowed blob with wall thickness equal to the user-defined radius. I think I should use imerode, but I am not sure which structuring element would give the best result. For example, should a square or circle be used? Should I erode with a radius of 4 at once, or erode with a radius of 1 4 times?

Respuesta aceptada

Rik
Rik el 3 de Jul. de 2019
To find the wall, I would invert the image, do a dilation and then & the original and the processed images. It doesn't really make a difference, but it makes more intuitive sense to me. The optimal size and shape of your SE depends on your application, but usually it doesn't matter very much.
However, I would suggest you limit the number of operations, so don't do 4 erosions if you actually only want 1.
im=imread('cameraman.tif');
L=bwlabel(im<=20);
im=L==1;%pick biggest blob
r=4;
[X,Y]=ndgrid(-r:r);
SE=hypot(X,Y)<=r;
im_shell_erode=~imerode(im,SE) & im;
im_shell_dilate=imdilate(~im,SE) & im;
im_rgb=double(im);
im_rgb(:,:,2)=im_shell_erode;
im_rgb(:,:,3)=im_shell_dilate;
figure(1),clf(1)%only use clf in debugging
imshow(im_rgb)
title('R=original, G=eroded, B=dilated')

Más respuestas (0)

Categorías

Más información sobre Read, Write, and Modify Image en Help Center y File Exchange.

Etiquetas

Productos


Versión

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by