Hollow out binary matrix shape

4 ビュー (過去 30 日間)
Dante Basile
Dante Basile 2019 年 7 月 3 日
回答済み: Rik 2019 年 7 月 3 日
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 Center および File ExchangeRead, 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