Skip to content
Snippets Groups Projects
Commit 6a4bfbad authored by Mark Winter's avatar Mark Winter
Browse files

Make Tree-Inference run on the currently selected tree only.

parent c8ea9bf9
No related branches found
No related tags found
No related merge requests found
...@@ -3,8 +3,8 @@ ...@@ -3,8 +3,8 @@
% %
% Applies inference to attempt to improve tree structure. % Applies inference to attempt to improve tree structure.
function historyAction = TreeInference() function historyAction = TreeInference(families)
[iters totalTime] = Families.LinkFirstFrameTrees(); [iters totalTime] = Families.LinkTrees(families);
Helper.SweepDeleted(); Helper.SweepDeleted();
......
function [iterations totalTime] = LinkTrees(families)
global CellFamilies
iterations = 0;
rootTrackIDs = [CellFamilies(families).rootTrackID];
% Try to Push/reseg
totalTime = 0;
maxPushCount = 10;
for i=1:maxPushCount
[assignExt findTime extTime] = Families.LinkTreesForward(rootTrackIDs);
% LogAction(['Tree inference step ' num2str(i)],[assignExt findTime extTime],[]);
totalTime = totalTime + findTime + extTime;
iterations = i;
if ( assignExt == 0 )
break;
end
end
% LogAction('Completed Tree Inference', [i totalTime],[]);
end
\ No newline at end of file
function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks) function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks)
global CellHulls HashedCells Costs global CellHulls CellTracks HashedCells Costs
assignedExtensions = 0; assignedExtensions = 0;
foundExtensions = 0; foundExtensions = 0;
...@@ -7,6 +7,20 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks) ...@@ -7,6 +7,20 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks)
findTime = 0; findTime = 0;
extTime = 0; extTime = 0;
rootTracks = unique(getRootTracks(rootTracks));
% Initialize mex routine with current cost-graph
costMatrix = Tracker.GetCostMatrix();
mexDijkstra('initGraph', costMatrix);
% Use changelabel to try and extend tracks back to first frame
backTracks = rootTracks([CellTracks(rootTracks).startTime] ~= 1);
for i=1:length(backTracks)
linkTreeBack(backTracks(i));
end
rootTracks = unique(getRootTracks(rootTracks));
leafHulls = getLeafHulls(rootTracks); leafHulls = getLeafHulls(rootTracks);
tStart = CellHulls(leafHulls(1)).time; tStart = CellHulls(leafHulls(1)).time;
tEnd = length(HashedCells); tEnd = length(HashedCells);
...@@ -16,11 +30,6 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks) ...@@ -16,11 +30,6 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks)
extGraph = sparse([],[],[], size(Costs,1),size(Costs,1), round(0.01*size(Costs,1))); extGraph = sparse([],[],[], size(Costs,1),size(Costs,1), round(0.01*size(Costs,1)));
extEnds = sparse([],[],[], size(Costs,1),size(Costs,1), round(0.01*size(Costs,1))); extEnds = sparse([],[],[], size(Costs,1),size(Costs,1), round(0.01*size(Costs,1)));
costMatrix = Tracker.GetCostMatrix();
% Initialize mex routine with current cost-graph
mexDijkstra('initGraph', costMatrix);
chkFindTime = tic(); chkFindTime = tic();
UI.Progressbar(0); UI.Progressbar(0);
i = 1; i = 1;
...@@ -50,7 +59,6 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks) ...@@ -50,7 +59,6 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks)
for l = 1:length(nextLeaves) for l = 1:length(nextLeaves)
trackCost = calcTrackCost(costMatrix, extHulls(j),nextLeaves(l), maxFrameExt); trackCost = calcTrackCost(costMatrix, extHulls(j),nextLeaves(l), maxFrameExt);
extendCost = trackCost + pathCost(extIdx(k)); extendCost = trackCost + pathCost(extIdx(k));
extGraph(checkExtHulls(i),nextLeaves(l)) = extendCost; extGraph(checkExtHulls(i),nextLeaves(l)) = extendCost;
extEnds(checkExtHulls(i),nextLeaves(l)) = pathExt{extIdx(k)}(end); extEnds(checkExtHulls(i),nextLeaves(l)) = pathExt{extIdx(k)}(end);
...@@ -121,6 +129,28 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks) ...@@ -121,6 +129,28 @@ function [assignedExtensions findTime extTime] = LinkTreesForward(rootTracks)
extTime = toc(chkExtendTime); extTime = toc(chkExtendTime);
end end
function linkTreeBack(rootTrack)
global CellTracks
costMatrix = Tracker.GetCostMatrix();
curTrack = rootTrack;
while ( CellTracks(curTrack).startTime > 1 )
curHull = CellTracks(curTrack).hulls(1);
prevHulls = find(costMatrix(:,curHull) > 0);
if ( isempty(prevHulls) )
break;
end
[bestCost bestIdx] = min(costMatrix(prevHulls,curHull));
prevTrack = Hulls.GetTrackID(prevHulls(bestIdx));
Tracks.ChangeLabel(curTrack, prevTrack);
curTrack = getRootTracks(prevTrack);
end
end
function cost = calcTrackCost(costMatrix, startHull, endHull, maxFrameExt) function cost = calcTrackCost(costMatrix, startHull, endHull, maxFrameExt)
global CellHulls CellTracks global CellHulls CellTracks
...@@ -324,3 +354,17 @@ function [paths pathCosts] = dijkstraSearch(startHull, costGraph, acceptFunc, ma ...@@ -324,3 +354,17 @@ function [paths pathCosts] = dijkstraSearch(startHull, costGraph, acceptFunc, ma
pathCosts(i) = bestCosts(termHulls(i)); pathCosts(i) = bestCosts(termHulls(i));
end end
end end
function rootTracks = getRootTracks(tracks)
global CellTracks CellFamilies
rootTracks = [];
for i=1:length(tracks)
if ( isempty(CellTracks(tracks(i)).startTime) )
continue;
end
familyID = CellTracks(tracks(i)).familyID;
rootTracks = [rootTracks CellFamilies(familyID).rootTrackID];
end
end
...@@ -355,7 +355,7 @@ function treeInference(src, evt) ...@@ -355,7 +355,7 @@ function treeInference(src, evt)
currentHull = CellTracks(CellFamilies(Figures.tree.familyID).rootTrackID).hulls(1); currentHull = CellTracks(CellFamilies(Figures.tree.familyID).rootTrackID).hulls(1);
bErr = Editor.ReplayableEditAction(@Editor.TreeInference); bErr = Editor.ReplayableEditAction(@Editor.TreeInference, Figures.tree.familyID);
if ( bErr ) if ( bErr )
return; return;
end end
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment