Commit 5b6dd737 authored by Mark Winter's avatar Mark Winter

Remove a bunch of orphaned files that are outdated or unused.

parent 438084cd
function CheckMEXSynch(checkGraph)
[checkOut checkIn] = mexDijkstra('debugAllEdges');
checkOut = sortrows(checkOut);
checkIn = sortrows(checkIn);
if ( any(checkOut(:) ~= checkIn(:)) )
error('In/Out MEX Edges are out of synch.');
end
if ( exist('checkGraph','var') )
[rcm, ccm] = find(checkGraph > 0);
graphInd = sub2ind(size(checkGraph), rcm, ccm);
checkMAT = [rcm ccm full(checkGraph(graphInd))];
checkMAT = sortrows(checkMAT);
if ( any(checkOut(:) ~= checkMAT(:)) )
error('MEX Edges out of synch with Matlab.');
end
end
end
\ No newline at end of file
This diff is collapsed.
This diff is collapsed.
function UnitTestMexDijkstra(costGraph, numIters)
UI.Progressbar(0);
% Test single edge removal
mexDijkstra('initGraph', costGraph);
numIters = min(numIters, nnz(costGraph));
testCostGraph = costGraph;
for i=1:numIters
[rcm, ccm] = find(testCostGraph > 0);
% graphInd = sub2ind(size(testCostGraph), rcm, ccm);
rndidx = randi(length(rcm),1);
testCostGraph(rcm(rndidx),ccm(rndidx)) = 0;
mexDijkstra('removeEdges', rcm(rndidx),ccm(rndidx));
UI.Progressbar((i/numIters) / 3);
end
Dev.CheckMEXSynch(testCostGraph);
% Test out edge removal
mexDijkstra('initGraph', costGraph);
testCostGraph = costGraph;
for i=1:numIters
[rcm, ccm] = find(testCostGraph > 0);
% graphInd = sub2ind(size(testCostGraph), rcm, ccm);
if ( isempty(rcm) )
break;
end
rndidx = randi(length(rcm),1);
testCostGraph(rcm(rndidx),:) = 0;
mexDijkstra('removeEdges', rcm(rndidx),[]);
UI.Progressbar((i/numIters) / 3 + 1/3);
end
Dev.CheckMEXSynch(testCostGraph);
% Test in edge removal
mexDijkstra('initGraph', costGraph);
testCostGraph = costGraph;
for i=1:numIters
[rcm, ccm] = find(testCostGraph > 0);
% graphInd = sub2ind(size(testCostGraph), rcm, ccm);
rndidx = randi(length(rcm),1);
testCostGraph(:,ccm(rndidx)) = 0;
mexDijkstra('removeEdges', [],ccm(rndidx));
UI.Progressbar((i/numIters) / 3 + 2/3);
end
Dev.CheckMEXSynch(testCostGraph);
UI.Progressbar(1);
end
\ No newline at end of file
% err = VerifyCachedCostMatrix()
% Compares CachedCostMatrix to what would be generated by old GetCostMatrix
% code.
function err = VerifyCachedCostMatrix()
global Costs GraphEdits CellHulls CachedCostMatrix
err = [];
costMatrix = Costs;
% bRemovedEdges = (GraphEdits < 0);
% costMatrix(bRemovedEdges) = 0;
%
% bSetEdges = (GraphEdits > 0);
% bSetRows = any(bSetEdges, 2);
% bSetCols = any(bSetEdges, 1);
%
% costMatrix(bSetRows,:) = 0;
% costMatrix(:,bSetCols) = 0;
% costMatrix(bSetEdges) = GraphEdits(bSetEdges)*eps;
% Vectorized/binary indexed implementation of this code is commented
% out above because we cannot use more than 46K square elements in a
% matrix in 32-bit matlab.
[r,c] = find(GraphEdits < 0);
for i=1:length(r)
costMatrix(r(i),c(i)) = 0;
end
% Remove all edges to/from deleted hulls
% This may end up being super slow, however it stops other graph code
% from always having to check for deleted hulls (in general) by making
% them unreachable.
r = find([CellHulls.deleted]);
for i=1:length(r)
costMatrix(r(i),:) = 0;
costMatrix(:,r(i)) = 0;
end
[r,c] = find(GraphEdits > 0);
for i=1:length(r)
costMatrix(r(i),:) = 0;
costMatrix(:,c(i)) = 0;
end
for i=1:length(r)
costMatrix(r(i),c(i)) = GraphEdits(r(i),c(i))*eps;
end
[r,c] = find(costMatrix ~= CachedCostMatrix);
err = [r c];
end
function WriteGraphDOT(callGraph, fullFuncList)
fullNames = cellfun(@(x)(strrep(x, '\', '\\')), fullFuncList, 'UniformOutput',0);
% toolboxes = {};
% toolboxMap = zeros(1,length(fullFuncList));
% for i=1:length(fullFuncList)
% toolboxPattern = '(?<=^.+[\\/]toolbox[\\/])[^\\/]+';
% matchToolbox = regexp(fullFuncList{i}, toolboxPattern, 'match', 'once');
% if ( isempty(matchToolbox) )
% continue;
% end
%
% if ( any(strcmpi(matchToolbox,toolboxes)) )
% toolboxMap(i) = find(strcmpi(matchToolbox,toolboxes));
% continue;
% end
%
% toolboxMap(i) = length(toolboxes) + 1;
% toolboxes = [toolboxes; {matchToolbox}];
% end
% Write a DOT file representing call graph
fid = fopen('adjmat.dot','w');
% fprintf(fid,'digraph G {\ncenter = 1;\nsize="10,10";\n');
fprintf(fid, 'digraph G \n{\n');
fprintf(fid, 'rankdir=LR\n');
fprintf(fid, 'node [shape=box]\n');
bUsedNodes = false(1,length(fullFuncList));
% for i=1:length(toolboxes)
% bInToolbox = (toolboxMap == i);
% tbGraph = callGraph(bInToolbox,bInToolbox);
% subNodes = find(bInToolbox);
%
% fprintf(fid, 'subgraph ["%s"]\n{\n', toolboxes{i});
%
% for j=1:length(subNodes)
% [funcPath shortName] = fileparts(fullFuncList{subNodes(j)});
% fprintf(fid, '%d[label="%s"]; ', subNodes(j), shortName);
% end
%
% fprintf(fid, '\n');
%
% [r c] = find(tbGraph);
% for j=1:length(r)
% fprintf(fid, '%d -> %d; ', subNodes(r(j)), subNodes(c(j)));
% end
%
% fprintf(fid, '\n}\n');
%
% bUsedNodes(bInToolbox) = 1;
% callGraph(bInToolbox,bInToolbox) = 0;
% end
remainingNodes = find(~bUsedNodes);
for i=1:length(remainingNodes)
[funcPath shortName] = fileparts(fullFuncList{remainingNodes(i)});
fprintf(fid, '%d[label="%s"]; ', remainingNodes(i), shortName);
end
fprintf(fid, '\n');
[r c] = find(callGraph);
for i=1:length(r)
fprintf(fid, '%d -> %d; ', r(i), c(i));
end
fprintf(fid, '\n}');
fclose(fid);
end
\ No newline at end of file
orgImg = imread('C:\Users\Eric\Pictures\Pos18\Pos18\Doc_0008_2_Position18.tif_Files_cropped\120608ML_p018_t00637_w0.tif');
gry = mat2gray(orgImg);
thGry = graythresh(gry);
bwGry = im2bw(gry,thGry);
se=strel('disk',2);
gd=imdilate(gry,se);
ge=imerode(gry,se);
ig=gd-ge;
thIg = graythresh(ig);
bwig=im2bw(ig,thIg);
% gry_ig=bwGry-bwig;
% gry_ig(:)=max(gry_ig(:),0);
% ds = bwdist(bwig);
bw = bwGry &~ bwig;
bw2 = +bwGry;
bw2 = bw2-ig;
bw3 = imfill(bw,'holes');
% bw3 = imopen(bw3,se);
[bwR bwC] = find(bwGry);
imagesc(gry);colormap gray, hold on
plot(bwC,bwR,'sb');
CC = bwconncomp(bw3,8);
stats = regionprops(CC, 'Area', 'Centroid', 'Eccentricity','MinorAxisLength');
idx = find([stats.Area] > 100);
for i=1:length(idx)
id = sprintf('%d',idx(i));
text(stats(idx(i)).Centroid(1),stats(idx(i)).Centroid(2),id);
end
cell = 166;
pixels = CC.PixelIdxList{cell};
[r c] = ind2sub(size(orgImg), pixels);
points = [];
for i=1:length(pixels)
% for j=1:stats(cell).MinorAxisLength*bw2(pixels(i))
% z = ceil(j/2);
% if (mod(j,2))
% z = -z;
% end
points = [points;[r(i) c(i) i]];
% end
end
[B I]=unique(points,'rows');
clstr = 4;
opt = statset('MaxIter',400);
obj = gmdistribution.fit([points(:,1) points(:,2)],clstr,'Options',opt,'Replicates',15);
kIdx = cluster(obj, [points(:,1) points(:,2)]);
[kIdxK m] = kmeans([points(:,1) points(:,2)],clstr,'Replicates',15);
hulls = [];
for i=1:clstr
hulls(i).pixels = [];
end
for i=1:length(I)
hulls(kIdx(I(i))).pixels = [hulls(kIdx(I(i))).pixels; points(I(i),:)];
end
hullsK = [];
for i=1:clstr
hullsK(i).pixels = [];
end
for i=1:length(I)
hullsK(kIdxK(I(i))).pixels = [hullsK(kIdxK(I(i))).pixels; points(I(i),:)];
end
% for i=1:4
% hulls(i).pixels = [r(kIdx==i) c(kIdx==i)];
% end
%imagesc(gry); colormap gray, hold on
plot(hulls(1).pixels(:,2),hulls(1).pixels(:,1),'.r');
plot(hulls(2).pixels(:,2),hulls(2).pixels(:,1),'.g');
plot(hulls(3).pixels(:,2),hulls(3).pixels(:,1),'.b');
plot(hulls(4).pixels(:,2),hulls(4).pixels(:,1),'.c');
plot(hulls(5).pixels(:,2),hulls(5).pixels(:,1),'om');
plot(hulls(6).pixels(:,2),hulls(6).pixels(:,1),'.y');
plot(hulls(7).pixels(:,2),hulls(7).pixels(:,1),'.k');
plot(hullsK(1).pixels(:,2),hullsK(1).pixels(:,1),'.r');
plot(hullsK(2).pixels(:,2),hullsK(2).pixels(:,1),'.g');
plot(hullsK(3).pixels(:,2),hullsK(3).pixels(:,1),'.b');
plot(hullsK(4).pixels(:,2),hullsK(4).pixels(:,1),'.c');
plot(hullsK(5).pixels(:,2),hullsK(5).pixels(:,1),'.m');
plot(hullsK(6).pixels(:,2),hullsK(6).pixels(:,1),'.y');
plot(hullsK(7).pixels(:,2),hullsK(7).pixels(:,1),'.k');
plot(m(1,2),m(1,1),'sk','MarkerFaceColor','k');
plot(m(2,2),m(2,1),'sk','MarkerFaceColor','k');
plot(m(3,2),m(3,1),'sk','MarkerFaceColor','k');
plot(m(4,2),m(4,1),'sk','MarkerFaceColor','k');
plot(m(5,2),m(5,1),'sk','MarkerFaceColor','k');
function testMexDijkstra()
global CellHulls
clear mex
tic;
costMatrix = Tracker.GetCostMatrix();
mexDijkstra('initGraph', costMatrix);
maxFrameExt = 19;
UI.Progressbar(0);
for i=1:length(CellHulls)
% [pathExt pathCost] = dijkstraSearch(i, costMatrix, @checkExtension, maxFrameExt);
[testPaths testCosts] = mexDijkstra('checkExtension', i, maxFrameExt+1);
% [pathCost srtidx] = sort(pathCost);
% pathExt = pathExt(srtidx);
%
% [testCosts srtidx] = sort(testCosts);
% testPaths = testPaths(srtidx);
%
% if ( length(pathExt) ~= length(testPaths) )
% error(['Unequal paths at i=' num2str(i) ' (lengths mismatched)']);
% end
%
% for j=1:length(pathExt)
% if ( testCosts(j) ~= pathCost(j) )
% error(['Unequal paths at i=' num2str(i) ' (' num2str(j) '-th cost mismatced)']);
% end
% end
%
% for j=1:length(pathExt)
% if ( testPaths{j}(end) ~= pathExt{j}(end) )
% error(['Unequal paths at i=' num2str(i) ' (' num2str(j) '-th endHull mismatced)']);
% end
% end
UI.Progressbar(i / length(CellHulls));
end
toc
disp('SWEETNESS!');
end
function bGoodExt = checkExtension(startHull, endHull, path)
global CellTracks CellHulls
bGoodExt = false;
trackID = Hulls.GetTrackID(endHull);
bGoodTime = (CellTracks(trackID).startTime == CellHulls(endHull).time);
if ( ~bGoodTime )
return;
end
parentID = CellTracks(trackID).parentTrack;
if ( ~isempty(parentID) )
nzParent = CellTracks(parentID).hulls(find(CellTracks(parentID).hulls,1,'last'));
[costMatrix bPathHulls bNextHulls] = Tracker.GetCostSubmatrix(nzParent, 1:length(CellHulls));
nxtHulls = find(bNextHulls);
[dump minidx] = min(costMatrix);
if ( nxtHulls(minidx) == endHull )
return;
end
end
bGoodExt = true;
end
function [paths pathCosts] = dijkstraSearch(startHull, costGraph, acceptFunc, maxExt)
paths = {};
pathCosts = [];
bestCosts = sparse([],[],[],1,size(costGraph,1),round(0.01*size(costGraph,1)));
bestPaths = cell(1,size(costGraph,1));
bestPaths{startHull} = startHull;
termHulls = [];
trvList = [];
trvHull = startHull;
while ( true )
nextHulls = find(costGraph(trvHull,:));
nextPathCosts = costGraph(trvHull,nextHulls) + bestCosts(trvHull);
% % Don't even bother putting paths that are higher cost in the list
% bestChk = bestCosts(nextHulls);
% bestChk(bestChk == 0) = Inf;
% bKeepNext = (min([nextPathCosts;bestChk],[],1) == nextPathCosts);
% nextHulls = nextHulls(bKeepNext);
% nextPathCosts = nextPathCosts(bKeepNext);
trvList = [trvList; nextPathCosts' trvHull*ones(length(nextHulls),1) nextHulls'];
bestChk = full(bestCosts(trvList(:,3)));
bestChk(bestChk == 0) = Inf;
bKeepNext = (min([trvList(:,1)';bestChk],[],1) == trvList(:,1)');
trvList = trvList(bKeepNext,:);
% trvList = sortrows([trvList; nextPathCosts' trvHull*ones(length(nextHulls),1) nextHulls'],1);
trvList = sortrows(trvList,1);
while ( size(trvList,1) > 0 )
if ( length(bestPaths{trvList(1,2)}) > maxExt )
trvList = trvList(2:end,:);
continue;
end
if ( (bestCosts(trvList(1,3))==0) )
bestCosts(trvList(1,3)) = trvList(1,1);
bestPaths{trvList(1,3)} = [bestPaths{trvList(1,2)} trvList(1,3)];
elseif ( (bestCosts(trvList(1,3)) > trvList(1,1)) )
error('This should never happen!');
end
% Is the next traversal a terminal node?
if ( acceptFunc(startHull, trvList(1,3),[bestPaths{trvList(1,2)} trvList(1,3)]) )
termHulls = union(termHulls,trvList(1,3));
trvList = trvList(2:end,:);
continue;
end
break;
end
if ( isempty(trvList) )
break;
end
trvHull = trvList(1,3);
trvList = trvList(2:end,:);
end
paths = cell(1,length(termHulls));
pathCosts = zeros(1,length(termHulls));
for i=1:length(termHulls)
paths{i} = bestPaths{termHulls(i)};
pathCosts(i) = bestCosts(termHulls(i));
end
end
\ No newline at end of file
function StackedHistory(action)
switch action
end
end
% families = FindFamiliesAfter(trackID)
% Find the set of families which start after the beginning of this track
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
%
% Copyright 2011 Andrew Cohen, Eric Wait and Mark Winter
%
% This file is part of LEVer - the tool for stem cell lineaging. See
% https://pantherfile.uwm.edu/cohena/www/LEVer.html for details
%
% LEVer is free software: you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation, either version 3 of the License, or
% (at your option) any later version.
%
% LEVer is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License
% along with LEVer in file "gnu gpl v3.txt". If not, see
% <http://www.gnu.org/licenses/>.
%
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function families = FindFamiliesAfter(trackID)
global CellTracks CellFamilies
nefam = find(arrayfun(@(x)(~isempty(x.startTime)), CellFamilies));
families = nefam([CellFamilies(nefam).startTime] > CellTracks(trackID).startTime);
end
\ No newline at end of file
function [iterations totalTime] = LinkFirstFrameTrees()
global HashedCells
iterations = 0;
% Try to Push/reseg
totalTime = 0;
maxPushCount = 10;
for i=1:maxPushCount
[assignExt findTime extTime] = Families.LinkTreesForward([HashedCells{1}.trackID]);
% 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 x_clamped = Clamp(x, minval, maxval)
x_clamped = max(cat(3,x,minval*ones(size(x))),[],3);
x_clamped = min(cat(3,x_clamped,maxval*ones(size(x))),[],3);
end
\ No newline at end of file
function [userEditCount resegEditCount userEditList resegEditList] = CountResegEdits(trackID)
global ReplayEditActions CellHulls CellTracks CellFamilies
userEditCount = 0;
resegEditCount = 0;
userEditList = {};
resegEditList = {};
%blockTypes = {'extra', 'reseg', 'user'};
% Pretty much simulates the undo stacks, but with just edit counts
typeStack = 1;
stackEnds = 0;
editStack = {{}};
totalReseg = 0;
bInReseg = 0;
for i=1:length(ReplayEditActions)
if ( strcmpi(ReplayEditActions(i).funcName,'Editor.ResegInitializeAction') )
bInReseg = 1;
continue;
end
% TODO: Get reseg edits out here:
if ( strcmpi(ReplayEditActions(i).funcName,'Editor.ResegFinishAction') )
bInReseg = 0;
if ( isempty(ReplayEditActions(i).ret) )
continue;
end
numEdits = length(ReplayEditActions(i).ret{2}.SegEdits);
totalReseg = totalReseg + numEdits;
newEdit = struct('count',{numEdits}, 'type',{typeStack(end)}, 'editFunc',{'ResegEdits'});
editStack{end} = [editStack{end}(1:stackEnds(end)); {newEdit}];
stackEnds(end) = stackEnds(end) + 1;
continue;
end
% TODO: This is unfortunate, and I need it to really just not happen
if ( bInReseg && strcmpi(ReplayEditActions(i).funcName,'Editor.InitHistory') )
warning('RESEG:NoFinish', 'The current file was closed without finishing resegmentation process, edit counts may be inaccurate');
% return;
end
% % Increase stack level and pick an edit type if a new subtask is started
% if ( strcmpi(ReplayEditActions(i).funcName,'Editor.StartReplayableSubtask') )
% typeStack = [typeStack 1];
% stackEnds = [stackEnds 0];
% editStack = [editStack; {{}}];
%
% if ( strcmpi(ReplayEditActions(i).args{1},'PauseResegTask') )
% typeStack(end) = 3;
% elseif ( strcmpi(ReplayEditActions(i).args{1},'InteractiveResegTask') )
% typeStack(end) = 2;
% end
% continue;
% end
%
% % Reduce stack level and add new edit block to level below (if not empty)
% if ( strcmpi(ReplayEditActions(i).funcName,'Editor.StopReplayableSubtask') )
% topStack = editStack{end};
% topEnd = stackEnds(end);
%
% stackEnds = stackEnds(1:(end-1));
% typeStack = typeStack(1:(end-1));
% editStack = editStack(1:(end-1));
%
% if ( topEnd > 0 )
% popEntry = topStack(1:topEnd,:);
% editStack{end} = [editStack{end}(1:stackEnds(end)); {popEntry}];
% stackEnds(end) = stackEnds(end) + 1;
% end
% continue;
% end
%
% % Just drop stack level by one
% if ( strcmpi(ReplayEditActions(i).funcName,'Editor.DropReplayableSubtask') )
%
% stackEnds = stackEnds(1:(end-1));
% typeStack = typeStack(1:(end-1));
% editStack = editStack(1:(end-1));
%
% if ( strcmpi(ReplayEditActions(i).args{1},'PauseResegTask') )
% bInPause = 0;
% end
% continue;
% end
%
% % Ignore these actions as they have no direct edit significance
% if ( strcmpi(ReplayEditActions(i).funcName,'Editor.ResegPlayAction') || strcmpi(ReplayEditActions(i).funcName,'Editor.ResegPauseAction') ...
% || strcmpi(ReplayEditActions(i).funcName,'Editor.ResegBackAction') || strcmpi(ReplayEditActions(i).funcName,'Editor.ResegPauseAction') ...
% || strcmpi(ReplayEditActions(i).funcName,'Editor.Top') )
% continue;
% end
%
% % Undo reduces current edit end by one
% if ( strcmpi(ReplayEditActions(i).funcName,'Editor.Undo') )
% if ( stackEnds(end) > 0 )
% stackEnds(end) = stackEnds(end) - 1;
% end
%
% continue;
% end
%
% % Redo increases current edit end by one
% if ( strcmpi(ReplayEditActions(i).funcName,'Editor.Redo') )
% if ( stackEnds(end) < size(editStack{end},1) )
% stackEnds(end) = stackEnds(end) + 1;
% end
%
% continue;
% end
%
% newEdit = struct('count',{1}, 'type',{typeStack(end)}, 'editFunc',{ReplayEditActions(i).funcName});
% editStack{end} = [editStack{end}(1:stackEnds(end)); {newEdit}];
%
% stackEnds(end) = stackEnds(end) + 1;
end
% [resegEditCount resegEditList] = countAllEdits(editStack{1}, 2);
% [userEditCount userEditList] = countAllEdits(editStack{1}, 3);
famID = CellTracks(trackID).familyID;
trackHulls = [CellTracks(CellFamilies(famID).tracks).hulls];
nzHulls = trackHulls(trackHulls ~= 0);
bUserEdited = [CellHulls(nzHulls).userEdited];
userEditCount = nnz(bUserEdited);
resegEditCount = totalReseg;
end
function [editCount editList] = countAllEdits(editStack, editType)