how to save double loop output in matrix form.
이전 댓글 표시
i am running double loop and i want to save its output in a matrix and plot each points of the matrix on image.
[rows, colm]=size(thin_image);
bifurcation=0;
ridge=0;
for i=2:rows-1
for j=2:colm-1
sub_matrix=(thin_image(i-1:i+1,j-1:j+1));
if sub_matrix(2,2)==1
sub_matrix=sum(sub_matrix(:))-1;
if sub_matrix==1
P=fprintf('it is a ridge termination');
i
j
ridge=ridge+1;
else if sub_matrix==3
Q=fprintf('it is a bifurcation');
i
j
bifurcation=bifurcation+1;
end
end
end
end
end
답변 (1개)
Andrei Bobrov
2019년 7월 24일
편집: Andrei Bobrov
2019년 7월 24일
sm = conv2(thin_image,ones(3),'valid')
imat = thin_image(2:end-1,2:end-1) == 1;
ridge = sum(sm(:) == 1 & imat(:));
bifurcation = sum(sm(:) == 3 & imat(:));
카테고리
도움말 센터 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!