2014-03-28 44 views
0

我在我的項目中使用了matlab中央網站的以下代碼來執行種子區域生長。這是完美的,但我很努力地理解代碼在某些地方正在做什麼。我已經聯繫了作者,但沒有回覆。任何人都可以向我提供一些解釋嗎?Matlab種子區域種植

function Phi = segCroissRegion(tolerance,Igray,x,y) 
if(x == 0 || y == 0) 
    imshow(Igray,[0 255]); 
    [x,y] = ginput(1); 
end 
Phi = false(size(Igray,1),size(Igray,2)); 
ref = true(size(Igray,1),size(Igray,2)); 
PhiOld = Phi; 
Phi(uint8(x),uint8(y)) = 1; 
while(sum(Phi(:)) ~= sum(PhiOld(:))) 
    PhiOld = Phi; 
    segm_val = Igray(Phi); 
    meanSeg = mean(segm_val); 
    posVoisinsPhi = imdilate(Phi,strel('disk',1,0)) - Phi; 
    voisins = find(posVoisinsPhi); 
    valeursVoisins = Igray(voisins); 
    Phi(voisins(valeursVoisins > meanSeg - tolerance & valeursVoisins < meanSeg + tolerance)) = 1; 
end 

感謝

回答

2

我已經在你的代碼中加入一些註釋:

function Phi = segCroissRegion(tolerance,Igray,x,y) 

% If there's no point, select one from image 

if(x == 0 || y == 0) 
    imshow(Igray,[0 255]); 
    [x,y] = ginput(1); 
end 

%Create seed with by adding point in black image 

Phi = false(size(Igray,1),size(Igray,2)); 
ref = true(size(Igray,1),size(Igray,2)); 
PhiOld = Phi; 
Phi(uint8(x),uint8(y)) = 1; 
while(sum(Phi(:)) ~= sum(PhiOld(:))) 
    PhiOld = Phi; 
% Evaluate image intensity at seed/line points 
    segm_val = Igray(Phi); 
% Calculate mean intensity at seed/line points 
    meanSeg = mean(segm_val); 
% Grow seed 1 pixel, and remove previous seed (so you'll get only new pixel perimeter) 
    posVoisinsPhi = imdilate(Phi,strel('disk',1,0)) - Phi; 
% Evaluate image intensity over the new perimeter 
    voisins = find(posVoisinsPhi); 
    valeursVoisins = Igray(voisins); 
% If image intensity over new perimeter is greater than the mean intensity of previous perimeter (minus tolerance), than this perimeter is part of the segmented object 
    Phi(voisins(valeursVoisins > meanSeg - tolerance & valeursVoisins < meanSeg + tolerance)) = 1; 
% Repeat while there's new pixel in seed, stop if no new pixel were added 
end 
+0

非常感謝您的幫助! – user1853871