필터 지우기
필터 지우기

Edge Detection in a 2D Matrix

조회 수: 19 (최근 30일)
Wayne
Wayne 2023년 7월 31일
댓글: Wayne 2023년 8월 8일
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
Dyuman Joshi
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.
Wayne
Wayne 2023년 7월 31일
Hi @Dyuman Joshi thanks for the reply - i have attached the data. I would like to have a boundary of a single pixel which surrounds the original figure. The "edge" function does that to some extent, but there are still some overlapped regions.

댓글을 달려면 로그인하십시오.

채택된 답변

DGM
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))
  댓글 수: 1
Wayne
Wayne 2023년 8월 8일
That's great, thank you!

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Matt J
Matt J 2023년 8월 1일
편집: Matt J 2023년 8월 1일
% a logical image
mask = imread('tinyblobs.png');
outerboundary = imdilate(mask,strel('disk',1))&~mask;
imshow(mask+2*outerboundary,[])
  댓글 수: 1
Wayne
Wayne 2023년 8월 8일
Thank you, appreciate the response!

댓글을 달려면 로그인하십시오.


Bruno Luong
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
  댓글 수: 1
Wayne
Wayne 2023년 8월 8일
Yes this was what I wanted, thanks for your help!

댓글을 달려면 로그인하십시오.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by