2016-01-21 61 views
3

我有一個二進制圖像,其中有幾個感興趣的區域,我通過bwconncomp識別出來。我試圖找到連接每個區域的最短點。我正考慮在代碼類似於下面的代碼循環中使用更大更大的內核大小的擴展,當連接組件的數量下降時暫停循環,然後可能識別通過質心的可觀變化連接並使用迭代次數兩個給出近似的距離?我覺得應該有更好的方式來做到這一點?找到感興趣區域之間的最短長度

distancebetweenROIS=[]; 
M11=tempBimage; 

for c=1:50   
    TT=bwconncomp(M11); 
    seDil=strel('disk',c); 
    M11=imdilate(tempBimage,seDil); 
    YY=bwconncomp(M11); 
    if length(TT.PixelIdxList)>length(YY.PixelIdxList) 
     distancebetweenROIS(end+1)=c*2; 
    end 

end 

enter image description here

enter image description here

enter image description here

+0

我認爲你可以使用['pdist2'](http://www.mathworks.com/help/stats/pdist2.html)來做到這一點,如果你只是傳遞它的每一對區域(指定爲(x ,y)座標)。如果您沒有統計工具箱,請嘗試http://www.mathworks.com/matlabcentral/fileexchange/29004-feature-points-in-image--keypoint-extraction/content/FPS_in_image/FPS%20in%20image/幫助%20Functions/SearchingMatches/pdist2.m – Dan

回答

0

使用bwdistbwlabel,你可以找到所有其他功能的任何要素的最短距離。你所要做的就是循環播放這些功能。

%// labeledImage is 1 on feature #1, 2 on feature #2, etc 

labeledImage = bwlabel(yourBinaryImage); 

nLabels = max(labeledImage(:)); 

%// find the distance between each label and all other labels 

distMat = zeros(nLabels, nLabels); 

for iLabel = 1:nLabels 

%// distance transform - every pixel is the distance to the nearest 
%// non-zero pixel, i.e. the location of label iLabel 

dist = bwdist(labeledImage==iLabel); 

%// use accumarray b/c we can 
%// get rid of the zeros in labeledImage, though, as there is no index 0 

distMat(:,iLabel) = accumarray(dist(labeledImage>0),labeledImage(labeledImage>0),[],@min); 

end 

注意,距離相當於「多少跳,我需要以最低的,如果我開始有X和跳像素到像素到功能Y」。如果需要質心之間的距離,regionprops(yourBinaryImage,'Centroids')後跟pdist2是更好的方法。