, 나는 영업 이익은 설명 된 규칙에 따라 가장자리의 집합을 추출하는 방법을 더 요구하고있다 생각합니다.
여기 가장자리를 포함하는 2x2 픽셀의 10 가지 패턴을 모두 식별하는 방법이 있습니다. 1
들과 0
의 (A = zeros(ny, nx); A(a) = 1
)으로 이미지 매트릭스 A
를 가정하면 : 여기
% we identify patterns with edges over 2x2 patches, describing with
% the first 4 binary values what pixels are set, and with the next 2
% the edge with 2 indices over the 2x2 patch
patterns = [
0,1,0,1, 3,4 % vertical edge at rhe right
1,0,1,0, 1,2 % vertical edge at the left
0,0,1,1, 2,4 % horizontal edge at the bottom
1,1,0,0, 1,3 % horizontal edge at the top
1,0,0,1, 1,4 % diagonal edge
0,1,1,0, 2,3 % diagonal edge
1,0,1,1, 1,4 % diagonal edge, extra pixel set
1,1,0,1, 1,4 % diagonal edge, extra pixel set
1,1,1,0, 2,3 % diagonal edge, extra pixel set
0,1,1,1, 2,3 % diagonal edge, extra pixel set
];
% 2x2 patches (matrix form)
P00 = A(1:end-1,1:end-1);
P10 = A(2:end,1:end-1);
P01 = A(1:end-1,2:end);
P11 = A(2:end,2:end);
% edge unique identifier using powers of 2
id = @(p00,p01,p10,p11) 1*p00 + 2*p10 + 4*p01 + 8*p11;
P = id(P00,P01,P10,P11); % vectorized pattern identification
% edges
e0 = []; % from (i,j)
e1 = []; % to (i,j)
for i = 1:size(patterns, 1) % small loop over the 10 patterns
p = patterns(i, :);
E = (P == id(p(1),p(2),p(3),p(4))); % pattern search, vectorized
[c,r] = ind2sub(size(E), find(E));
[c0,r0] = ind2sub([2,2], p(5));
[c1,r1] = ind2sub([2,2], p(6));
e0 = [e0; c+c0, r+r0];
e1 = [e1; c+c1, r+r1];
end
그리고 이미지에 적용 결과는 (내가 캡처 김프를 사용, 그래서 어쩌면 이미지가 아닌, 크기 조정 및 필터)정확히 동일한 :
X = [e0(:,2) e1(:,2)];
Y = size(A,1) - [e0(:,1) e1(:,1)];
plot(X', Y', '.-')
내가 가정하고 그 가장자리 descri의 정렬 된 시퀀스를 얻기 앞에서 설명한 것처럼 폴리곤 (또는 폴리곤)을 배치하는 것이 주된 문제는 아닙니다.
유사한 (http://stackoverflow.com/a/33473452/2521214) 및 [결정 최소 : 이는 다음을 산출한다 미로를 해결하는 라인 세그먼트] (http://stackoverflow.com/a/30908390/2521214) – Spektre
덕분에, 매우 도움이! –