from 0 1 matrix to boundaries and vertices
조회 수: 2 (최근 30일)
이전 댓글 표시
I have a matrix like the one is attached here I want to overwrite on the ones:
- 2 if the cell is a edge
- 3 if the cell is a vertex
like from:
1 1 1 1 1
1 1 1 1 1
0 1 1 1 0
to:
3 2 2 2 3
3 3 1 3 3
0 3 2 3 0
any idea?
댓글 수: 3
채택된 답변
Matt J
2022년 12월 19일
편집: Matt J
2022년 12월 19일
A=load('domain').domain; A=imresize(A,1/20);
BW=logical(A);
A(BW)=2;
BW=bwmorph(BW,'remove');
A(A&~BW)=1;
BW=edgeLengthen(BW,5,0)+edgeLengthen(BW,5,1)>0;
v=bwmorph(BW,'branchpoints');
A(v(2:end-1,2:end-1))=3; %final result
imshow(A,[])
function BW=edgeLengthen(BW,n,rowwise)
BW=padarray(BW,[1,1]);
se0=ones(1,n-2);
se1=ones(1,n+2);
if ~rowwise, se0=se0'; se1=se1'; end
BW=imerode(BW,se0);
BW=imdilate(BW,se1);
end
추가 답변 (0개)
참고 항목
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!