Hollow out binary matrix shape
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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?
0 commentaires
Réponse acceptée
Rik
le 3 Juil 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')
0 commentaires
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Read, Write, and Modify Image dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!