from 0 1 matrix to boundaries and vertices
2 views (last 30 days)
Show older comments
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 Comments
Accepted Answer
Matt J
on 19 Dec 2022
Edited: Matt J
on 19 Dec 2022
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
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!