2014-04-07 2 views
1

세그먼트 화 알고리즘의 출력을 입력 이미지와 동일한 크기의 매트릭스라고 가정합니다. 감지되는 각 세그먼트에 대해 특정 행렬의 특정 부분이 특정 번호/색인으로 색인됩니다.분할 된 이미지에서 특정 세그먼트의 인접 라우터

특정 세그먼트의 인접 항목을 검색하려고합니다. Here 각 픽셀의 이웃을 다른 크기로 가져 오는 것에 대한 설명이 있습니다. 예를 들어, 3x3, 5x5, 7x7, e.t.c에서. 위의 링크에서와 같이 시간이 효율적으로 다른 크기 (약)의 이웃에있는 특정 세그먼트에 대해 비슷한 절차를 수행 할 수 있습니까?

안부,

토트

enter image description here

PS : 질문이 높게 평가된다.

답변

1

특정 지역의 이웃의 인덱스를 찾으려면, 다음을 수행 할 수 있습니다 : 당신은 물론, 병렬로 모든 세그먼트에 대해이 작업을 수행, 그리고를 만들 수 있습니다

%# input: lblImg - image where pix(x,y) is the index of the segment 
targetSegment = 4; 
%# grow the segment by 2 pixels, since I assume the boundary in between is 1 pixel wide 
msk = imdilate(lblImg == targetSegment,strel('disk',2)); 
msk(lblImg == targetSegment | lblImg == 0) = false; %# remove original cell, and boundary 

%# retrieve the list of neighbors 
listOfNeighbors = unique(lblImg(msk)); 

인접 행렬. Dilation은 로컬 최대 작업이므로 다른 인덱스의 레이블이 겹치게됩니다.

dilImg = imdilate(lblImg, strel('disk',2)); 
msk = dilImg ~= lblImg & lblImg > 0; %# assume indices are all positive 

%# msk contains the indices of pixels where dilation 
%# has created an overlap between segments. 

rowColIdx = unique([dilImg(msk), lblImg(msk)], 'rows'); 

%# create adjacency matrix. Due to the nature of imdilate, this will fill in 
%# only the values below the diagonal. 
%# adjacencyMatrix = adjacencyMatrix + adjacencyMatrix.' would fix that. 
nLabels = max(lblImg(:)); 
adjacencyMatrix = sparse(rowColIdx(:,1),rowColIdx(:,2),ones(size(rowColIdx,1),1),... 
    nLabels, nLabels); 
+0

응답 해 주셔서 감사합니다. 나는 질문이 없다는 것을 확신 할 수있게 되 자마자 답변을 표시 할 것이다. 다시 한 번 감사드립니다! :) – Thoth

관련 문제