Hollow out binary matrix shape

4 次查看(过去 30 天)
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?

采纳的回答

Rik
Rik 2019-7-3
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')

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Read, Write, and Modify Image 的更多信息

产品


版本

R2018b

Community Treasure Hunt

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

Start Hunting!

Translated by