Edge Detection in a 2D Matrix
Afficher commentaires plus anciens
Hi there,
I have a 2D matrix which contains contains 0s and 1s as shown in the left image below. I would like to get the outer boundary of this shape. By using the edge function, it gives a nice estimate of the boundary, but some of the points lie on the original shape. What I did was to use the "edge" function directly with only my 2D matrix as input. Are there any ways to get the outer boundary only and without any points intersecting the original shape? Thank you.

2 commentaires
Dyuman Joshi
le 31 Juil 2023
What is the output you want to obtain?
Also, can you attach your data? Use the paperclip button to do so.
Wayne
le 31 Juil 2023
Réponse acceptée
Plus de réponses (2)
% a logical image
mask = imread('tinyblobs.png');
outerboundary = imdilate(mask,strel('disk',1))&~mask;
imshow(mask+2*outerboundary,[])
1 commentaire
Wayne
le 8 Août 2023
Bruno Luong
le 31 Juil 2023
Modifié(e) : Bruno Luong
le 31 Juil 2023
Do you want this
load(websave('data.mat','https://www.mathworks.com/matlabcentral/answers/uploaded_files/1446792/data.mat'))
d=conv2(data,[0 1 0; 1 1 1; 0 1 0],'same')>0;
b=d-data;
figure
imagesc(data);
axis equal
figure
imagesc(b)
axis equal
1 commentaire
Wayne
le 8 Août 2023
Catégories
En savoir plus sur Region and Image Properties dans Centre d'aide et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!





