Edge Detection in a 2D Matrix
19 ビュー (過去 30 日間)
古いコメントを表示
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.
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/1446707/image.jpeg)
2 件のコメント
Dyuman Joshi
2023 年 7 月 31 日
What is the output you want to obtain?
Also, can you attach your data? Use the paperclip button to do so.
採用された回答
DGM
2023 年 7 月 31 日
Consider the example:
% a logical image
mask = imread('tinyblobs.png');
imshow(mask)
% generate the perimeter image
paddedmask = padarray(mask,[1 1],'replicate','both');
perim = bwperim(~paddedmask);
perim = perim(2:end-1,2:end-1);
imshow(perim)
% show that the new pixels do not overlap the original blobs
% and that there is no gap between the two
imshow(imfuse(mask,perim))
その他の回答 (2 件)
Bruno Luong
2023 年 7 月 31 日
編集済み: Bruno Luong
2023 年 7 月 31 日
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
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!