특정 지역의 이웃의 인덱스를 찾으려면, 다음을 수행 할 수 있습니다 : 당신은 물론, 병렬로 모든 세그먼트에 대해이 작업을 수행, 그리고를 만들 수 있습니다
%# 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);
응답 해 주셔서 감사합니다. 나는 질문이 없다는 것을 확신 할 수있게 되 자마자 답변을 표시 할 것이다. 다시 한 번 감사드립니다! :) – Thoth