Hollow out binary matrix shape
3 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
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 Kommentare
Akzeptierte Antwort
Rik
am 3 Jul. 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 Kommentare
Weitere Antworten (0)
Siehe auch
Kategorien
Mehr zu Read, Write, and Modify Image finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!