Commit 438084cd authored by Mark Winter's avatar Mark Winter

Use new tracker and metadata when reading images and segmentation/tracking.

parent 1482dfb3
......@@ -160,16 +160,10 @@ function [errStatus,tSeg,tTrack] = SegAndTrackDataset(numProcessors, segArgs)
% Sort segmentations and fluorescent data so that they are time ordered
segtimes = [cellSegments.time];
[srtSegs srtIdx] = sort(segtimes);
[~,srtIdx] = sort(segtimes);
CellHulls = Helper.MakeInitStruct(Helper.GetCellHullTemplate(), cellSegments(srtIdx));
% Make sure center of mass is available
for i=1:length(CellHulls)
[r c] = ind2sub(Metadata.GetDimensions('rc'), CellHulls(i).indexPixels);
CellHulls(i).centerOfMass = mean([r c], 1);
end
fprintf('Building Connected Component Distances... ');
%% Build hashed cell list
HashedCells = cell(1,Metadata.GetNumberOfFrames());
for t=1:Metadata.GetNumberOfFrames()
HashedCells{t} = struct('hullID',{}, 'trackID',{});
......@@ -179,9 +173,10 @@ function [errStatus,tSeg,tTrack] = SegAndTrackDataset(numProcessors, segArgs)
HashedCells{CellHulls(i).time} = [HashedCells{CellHulls(i).time} struct('hullID',{i}, 'trackID',{0})];
end
%% Create connected component distances for tracker
fprintf('Building Connected Component Distances... ');
ConnectedDist = [];
Tracker.BuildConnectedDistance(1:length(CellHulls), 0, 1);
Segmentation.WriteSegData('segmentationData',Metadata.GetDatasetName());
fprintf(1,'\nDone\n');
tSeg = toc;
......@@ -189,19 +184,16 @@ function [errStatus,tSeg,tTrack] = SegAndTrackDataset(numProcessors, segArgs)
%% Tracking
tic
fprintf(1,'Tracking...');
fnameIn=['.\segmentationData\SegObjs_' Metadata.GetDatasetName() '.txt'];
fnameOut=['.\segmentationData\Tracked_' Metadata.GetDatasetName() '.txt'];
system(['MTC.exe ' num2str(CONSTANTS.dMaxCenterOfMass) ' ' num2str(CONSTANTS.dMaxConnectComponentTracker) ' "' fnameIn '" "' fnameOut '" > out.txt']);
[hullTracks,gConnect] = trackerMex(CellHulls, ConnectedDist, Metadata.GetNumberOfFrames(), CONSTANTS.dMaxCenterOfMass, CONSTANTS.dMaxConnectComponentTracker);
fprintf('Done\n');
tTrack = toc;
%% Import into LEVer's data sturcture
[objTracks gConnect] = Tracker.ReadTrackData('segmentationData', Metadata.GetDatasetName());
fprintf('Finalizing Data...');
try
Tracker.BuildTrackingData(objTracks, gConnect);
Tracker.BuildTrackingData(hullTracks, gConnect);
catch excp
cltime = clock();
......
function BuildTrackingData(objTracks, gConnect)
global CONSTANTS Costs GraphEdits ResegLinks CellHulls CellFamilies CellTracks HashedCells CellPhenotypes
function BuildTrackingData(hullTracks, gConnect)
global Costs GraphEdits ResegLinks CellHulls CellFamilies CellTracks HashedCells CellPhenotypes
%ensure that the globals are empty
Costs = gConnect;
......@@ -13,18 +13,15 @@ function BuildTrackingData(objTracks, gConnect)
CellPhenotypes = struct('descriptions', {{'died'}}, 'hullPhenoSet', {zeros(2,0)});
hullList = [];
for i=length(objTracks):-1:1
UI.Progressbar((length(objTracks)-i) / (length(objTracks)));
for i=length(hullTracks):-1:1
UI.Progressbar((length(hullTracks)-i) / (length(hullTracks)));
if ( any(ismember(hullList,i)) )
continue;
end
if ( objTracks(i).inID ~= 0 )
continue;
end
hullList = addToTrack(i,hullList,objTracks);
allTrackHulls = find(hullTracks == hullTracks(i));
hullList = [hullList addToTrack(allTrackHulls)];
end
if ( length(hullList) ~= length(CellHulls) )
......@@ -43,36 +40,19 @@ function BuildTrackingData(objTracks, gConnect)
Dev.PrintIntegrityErrors(errors);
end
%create the family trees
Families.ProcessNewborns();
end
function hullList = addToTrack(hullID, hullList, objTracks)
global CellHulls
if ( any(ismember(hullList,hullID)) || objTracks(hullID).inID ~= 0 )
function hullList = addToTrack(allTrackHulls)
if ( isempty(allTrackHulls) )
return
end
Families.NewCellFamily(hullID);
hullList = [hullList hullID];
nextHull = hullID;
while ( objTracks(nextHull).outID ~= 0 )
nextHull = objTracks(nextHull).outID;
if ( any(ismember(hullList,nextHull)) )
break;
end
if ( any(ismember(hullList,objTracks(nextHull).inID)) )
Tracks.AddHullToTrack(nextHull,[],objTracks(nextHull).inID);
else
%this runs if there was an error in objTracks data structure
Families.NewCellFamily(hull);
end
hullList = [hullList nextHull];
Families.NewCellFamily(allTrackHulls(1));
for i=2:length(allTrackHulls)
Tracks.AddHullToTrack(allTrackHulls(i),[],allTrackHulls(i-1));
end
end
\ No newline at end of file
hullList = allTrackHulls;
end
......@@ -47,20 +47,8 @@ for dirIdx=1:length(dirList)
continue
end
fileList = dir(fullfile(directory_name, dirList(dirIdx).name, '*.tif'));
if ( isempty(fileList) )
continue
end
validStartFilename = getValidStartFileName(fullfile(directory_name, dirList(dirIdx).name));
if ( isempty(validStartFilename) )
fprintf('\n**** Image list does not begin with frame 1 for %s. Skipping\n\n', directory_name);
continue;
end
datasetName = Helper.ParseImageName(validStartFilename);
if ( isempty(datasetName) )
fprintf('\n**** Image names not formatted correctly for %s. Skipping\n\n', directory_name);
imageData = MicroscopeData.ReadMetadata([fullfile(directory_name,dirList(dirIdx).name) '\'],false);
if ( isempty(imageData) )
continue;
end
......@@ -71,13 +59,11 @@ end
Load.AddConstant('version',softwareVersion,1);
Load.AddConstant('cellType', [], 1);
validStartFilename = getValidStartFileName(fullfile(directory_name, validDirs{1}));
[datasetName,namePattern] = Helper.ParseImageName(validStartFilename);
[imageData,imagePath] = MicroscopeData.ReadMetadata([fullfile(directory_name, validDirs{1}) '\']);
Metadata.SetMetadata(imageData);
Load.AddConstant('rootImageFolder', fullfile(directory_name, validDirs{1}),1);
Load.AddConstant('datasetName', datasetName,1);
Load.AddConstant('imageNamePattern', namePattern,1);
Load.AddConstant('matFullFile', fullfile(outputDir, [CONSTANTS.datasetName '_LEVer.mat']),1);
Load.AddConstant('rootImageFolder', imagePath, 1);
Load.AddConstant('matFullFile', fullfile(outputDir, Metadata.GetDatasetName()),1);
UI.SegPreview();
if ( isempty(CONSTANTS.cellType) )
......@@ -103,25 +89,21 @@ end
%% Run segmentation for all valid directories
processedDatasets = {};
for dirIdx=1:length(validDirs)
validStartFilename = getValidStartFileName(fullfile(directory_name, validDirs{dirIdx}));
[datasetName,namePattern] = Helper.ParseImageName(validStartFilename);
Load.AddConstant('cellType', cellType,1);
Load.AddConstant('rootImageFolder', fullfile(directory_name, validDirs{dirIdx}),1);
Load.AddConstant('datasetName', datasetName,1);
Load.AddConstant('imageNamePattern', namePattern,1);
Load.AddConstant('matFullFile', fullfile(outputDir, [CONSTANTS.datasetName '_LEVer.mat']),1);
[imageData,imagePath] = MicroscopeData.ReadMetadata([fullfile(directory_name, validDirs{dirIdx}) '\']);
Metadata.SetMetadata(imageData);
Load.AddConstant('rootImageFolder', imagePath, 1);
Load.AddConstant('matFullFile', fullfile(outputDir, [Metadata.GetDatasetName() '_LEVer.mat']),1);
if ( exist(CONSTANTS.matFullFile,'file') )
fprintf('%s - LEVer data already exists. Skipping\n', CONSTANTS.datasetName);
fprintf('%s - LEVer data already exists. Skipping\n', Metadata.GetDatasetName());
continue
end
Load.AddConstant('version',softwareVersion,1);
%% Segment and track folder
fprintf('Segment & track file : %s\n', CONSTANTS.datasetName);
fprintf('Segment & track file : %s\n', Metadata.GetDatasetName());
tic
if ( ~bTrialRun )
......@@ -130,9 +112,9 @@ for dirIdx=1:length(validDirs)
segArgs = Segmentation.GetCellTypeParams();
[errStatus tSeg tTrack] = Segmentation.SegAndTrackDataset(numProcessors, segArgs);
if ( ~isempty(errStatus) )
fprintf('\n\n*** Segmentation/Tracking failed for %s\n\n', CONSTANTS.datasetName);
fprintf('\n\n*** Segmentation/Tracking failed for %s\n\n', Metadata.GetDatasetName());
errFilename = fullfile(outputDir, [CONSTANTS.datasetName '_segtrack_err.log']);
errFilename = fullfile(outputDir, [Metadata.GetDatasetName() '_segtrack_err.log']);
fid = fopen(errFilename, 'wt');
fprintf(fid, '%s', errStatus);
fclose(fid);
......@@ -151,31 +133,8 @@ for dirIdx=1:length(validDirs)
Error.LogAction('Segmentation time - Tracking time',tSeg,tTrack);
end
processedDatasets = [processedDatasets; {CONSTANTS.datasetName}];
processedDatasets = [processedDatasets; {Metadata.GetDatasetName()}];
end %dd
clear global;
end
% This function tries to quickly find one or more files that qualify as an
% initial image frame for parsing dataset names, etc. Returns the first
% file name found
function filename = getValidStartFileName(chkPath)
filename = '';
flist = [];
chkDigits = 7:-1:2;
for i=1:length(chkDigits)
digitStr = ['%0' num2str(chkDigits(i)) 'd'];
flist = dir(fullfile(chkPath,['*_t' num2str(1,digitStr) '*.tif']));
if ( ~isempty(flist) )
break;
end
end
if ( isempty(flist) )
return;
end
filename = flist(1).name;
end
......@@ -87,7 +87,7 @@ try
continue;
end
imSize = size(chanImSet{primaryChan});
rcImageDims = Metadata.GetDimensions('rc');
validHulls = [];
for i=1:length(frameHulls)
......@@ -96,7 +96,7 @@ try
tag = [char(segFunc) ':' frameHulls(i).tag];
end
newHull = Hulls.CreateHull(imSize, frameHulls(i).indexPixels, t, false, tag);
newHull = Hulls.CreateHull(rcImageDims, frameHulls(i).indexPixels, t, false, tag);
validHulls = [validHulls newHull];
end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment