Classification-driven region-growing for voxel classification.

1 view (last 30 days)
I am not professional in Matlab Programming.I face a problem in re-implementing an algorithm.
It seems it is in an infinite loop that after long time I stopped it but there is nothing inside the LV matrix. the code is:
% neigb[]: 26 Neighbor locations (footprint)
th=.98; % threshold for controlling classifier since the number object voxels is much much lesser that background
maxDist = Inf;
while ~isempty(VQ)
idx=VQ(1);% removing first element from queue
VQ(1)=[]; % deleting the first place in the queue
[xi,yi,zi]=ind2sub([X2,Y2,Z2],idx); %converting index to position
LV(idx,1)=1; % marking the place as visited
[~,ScoreF]=predict(Mdl_classifier1,Features_Test(idx,Feat));
[~,ScoreT]=predict(Mdl_classifier2,Features_Test(idx,TFeat));
if (ScoreF(2)>th && ScoreF(2)>ScoreT(2) )
LV(idx,2)=.5; % Point is classified as first object
% Finding 26 neighbors
for j=1:26
% Calculate the neighbour coordinate
xn = xi+neigb(j,1); yn = yi+neigb(j,2); zn=zi+neigb(j,3);
% Check if neighbour is inside or outside the image
ins=(xn>=1)&&(yn>=1)&&(xn<=nRow)&&(yn<=nCol)&&(zn>=1)&&(zn<=nSli)...
&& sqrt((xn-initPos(1))^2+(yn-initPos(2))^2+(zn-initPos(3))^2)<maxDist;
if (ins)
idx=sub2ind([X2,Y2,Z2],xn,yn,zn);
if (~LV(idx,1))% Check whether the point has already been visited or not
VQ(end+1)=idx; % if the point has not been visited, add the neighbor point to the queue
end
end
end
elseif (ScoreT(2)>th && ScoreT(2)>ScoreF(2)) % If the point is classified as object 2
LV(idx,2)=1; % Point is classified as object 2
for j=1:26
% Calculate the neighbour coordinate
xn = xi+neigb(j,1); yn = yi+neigb(j,2); zn=zi+neigb(j,3);
% Check if neighbour is inside or outside the image
ins=(xn>=1)&&(yn>=1)&&(xn<=nRow)&&(yn<=nCol)&&(zn>=1)&&(zn<=nSli)...
&& sqrt((xn-initPos(1))^2+(yn-initPos(2))^2+(zn-initPos(3))^2)<maxDist;
if (ins)
idx = sub2ind([X2,Y2,Z2],xn,yn,zn);
if (~LV(idx,1))
VQ(end+1)=idx;
end
end
end % end for
else
LV(idx,2)=0; % Point is classified background
end % end if
end % end whiled

Accepted Answer

Image Analyst
Image Analyst on 10 Nov 2016
Why don't you step through it with the debugger to figure out why no values in the LV matrix are getting changed? That's what everyone else would do in your situation. I don't see any reason why you can't do it too.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!