From a1ca3abb2cb07e4a9c724482e4ffe79ce796f4a3 Mon Sep 17 00:00:00 2001 From: Eric Wait <eric@waitphoto.com> Date: Fri, 8 Apr 2011 22:41:22 -0500 Subject: [PATCH] LEVer 4.0 --- bin/CompileLEVer.m | 6 ++++- src/MATLAB/InitializeFigures.m | 17 ++++++++++++ src/MATLAB/OpenData.m | 48 ++++++++++++---------------------- src/MATLAB/ProcessNewborns.m | 2 +- src/MATLAB/SaveData.m | 2 +- src/MATLAB/SaveDataAs.m | 14 ++++++---- src/MATLAB/SegAndTrack.m | 2 ++ src/MATLAB/TrackSplitHulls.m | 1 + 8 files changed, 53 insertions(+), 39 deletions(-) diff --git a/bin/CompileLEVer.m b/bin/CompileLEVer.m index fec62063..aa9094db 100644 --- a/bin/CompileLEVer.m +++ b/bin/CompileLEVer.m @@ -1 +1,5 @@ -mcc -m ../LEVer.m \ No newline at end of file +mcc -m ../LEVer.m +mcc -m ../Segmentor.m +if(isempty(dir('./MTC.exe'))) + warndlg('Make sure that MTC.exe is in the same dir as LEVer.exe'); +end \ No newline at end of file diff --git a/src/MATLAB/InitializeFigures.m b/src/MATLAB/InitializeFigures.m index 4cd18456..acdb4788 100644 --- a/src/MATLAB/InitializeFigures.m +++ b/src/MATLAB/InitializeFigures.m @@ -10,6 +10,13 @@ global Figures CONSTANTS Figures.time = 1; +oldCellsHandle = []; +oldTreeHandle = []; +if(isfield(Figures,'cells') && isfield(Figures.cells,'handle') && ~isempty(Figures.cells.handle)) + oldCellsHandle = Figures.cells.handle; + oldTreeHandle = Figures.tree.handle; +end + Figures.cells.handle = figure(); Figures.tree.handle = figure(); @@ -68,6 +75,16 @@ Figures.tree.timeLabel = uicontrol(Figures.tree.handle,... 'String',['Time: ' num2str(Figures.time)]); FindLargestTree([],[]); + +if(~isempty(oldCellsHandle) && ishandle(oldCellsHandle)) + set(oldCellsHandle,'CloseRequestFcn','remove'); + close(oldCellsHandle); +end +if(~isempty(oldTreeHandle) && ishandle(oldTreeHandle)) + set(oldTreeHandle,'CloseRequestFcn','remove'); + close(oldTreeHandle); +end + % DrawTree(1); % figure(Figures.tree.handle); % diff --git a/src/MATLAB/OpenData.m b/src/MATLAB/OpenData.m index 581d302a..a08b6921 100644 --- a/src/MATLAB/OpenData.m +++ b/src/MATLAB/OpenData.m @@ -31,7 +31,7 @@ end filterIndexImage = 0; matFile = []; -matPath = []; +matFilePath = []; imageFile = []; imagePath = []; imageDataset = []; @@ -56,39 +56,40 @@ if(~isempty(Figures)) end oldCONSTANTS = CONSTANTS; +InitializeConstants(); %find the first image imageFilter = [settings.imagePath '*.TIF']; while (filterIndexImage==0) fprintf('\nSelect first .TIF image...\n\n'); - [imageFile,imagePath,filterIndexImage] = uigetfile(imageFilter,'Open First Image in dataset: '); + [settings.imageFile,settings.imagePath,filterIndexImage] = uigetfile(imageFilter,'Open First Image in dataset: '); if (filterIndexImage==0) CONSTANTS = oldCONSTANTS; return end end -index = strfind(imageFile,'_t'); +index = strfind(settings.imageFile,'_t'); frameT = '001'; if (~isempty(index) && filterIndexImage~=0) - CONSTANTS.rootImageFolder = imagePath; - imageDataset = imageFile(1:(index(length(index))-1)); + CONSTANTS.rootImageFolder = settings.imagePath; + imageDataset = settings.imageFile(1:(index(length(index))-1)); CONSTANTS.imageDatasetName = imageDataset; CONSTANTS.datasetName = imageDataset; - index2 = strfind(imageFile,'.'); + index2 = strfind(settings.imageFile,'.'); CONSTANTS.imageSignificantDigits = index2 - index - 2; fileName=[CONSTANTS.rootImageFolder imageDataset '_t' SignificantDigits(1) '.TIF']; end while (isempty(index) || ~exist(fileName,'file')) fprintf(['Image file name not in correct format: ' CONSTANTS.datasetName '_t' frameT '.TIF\nPlease choose another...\n']); - [imageFile,imagePath,filterIndexImage] = uigetfile(settings.imagePath,'Open First Image'); + [settings.imageFile,settings.imagePath,filterIndexImage] = uigetfile(settings.imagePath,'Open First Image'); if(filterIndexImage==0) CONSTANTS = oldCONSTANTS; return end index = strfind(imageFile,'t'); - CONSTANTS.rootImageFolder = [imagePath '\']; + CONSTANTS.rootImageFolder = [settings.imagePath '\']; imageDataset = imageFile(1:(index(length(index))-2)); fileName=[CONSTANTS.rootImageFolder imageDataSet '_t' SignificantDigits(t) '.TIF']; end @@ -96,12 +97,13 @@ end answer = questdlg('Run Segmentation and Tracking or Use Existing Data?','Data Source','Segment & Track','Existing','Existing'); switch answer case 'Segment & Track' + save('LEVerSettings.mat','settings'); InitializeConstants(); SegAndTrack(); case 'Existing' while(~goodLoad) fprintf('Select .mat data file...\n'); - [matFile,matPath,filterIndexMatFile] = uigetfile([settings.matFilePath '*.mat'],... + [settings.matFile,settings.matFilePath,filterIndexMatFile] = uigetfile([settings.matFilePath '*.mat'],... 'Open Data'); if (filterIndexMatFile==0) @@ -124,7 +126,7 @@ switch answer imageSignificantDigits = CONSTANTS.imageSignificantDigits; try - load([matPath matFile]); + load([settings.matFilePath settings.matFile]); fprintf('\nFile open.\n\n'); catch exception %DEBUG -- Uncomment @@ -132,21 +134,16 @@ switch answer end end - if(~isfield(CONSTANTS,'rootImageFolder')) - CONSTANTS.rootImageFolder = rootImageFolder; - end - - if(~isfield(CONSTANTS,'imageSignificantDigits')) - CONSTANTS.imageSignificantDigits = imageSignificantDigits; - end + CONSTANTS.rootImageFolder = rootImageFolder; + CONSTANTS.imageSignificantDigits = imageSignificantDigits; + InitializeConstants(); if(exist('objHulls','var')) fprintf('Converting File...'); - InitializeConstants(); ConvertTrackingData(objHulls,gConnect); fprintf('\nFile Converted.\n'); CONSTANTS.datasetName = strtok(matFile,' '); - save([matPath CONSTANTS.datasetName '_LEVer'],... + save([settings.matFilePath CONSTANTS.datasetName '_LEVer'],... 'CellFamilies','CellHulls','CellTracks','HashedCells','Costs','CONSTANTS'); fprintf(['New file saved as:\n' CONSTANTS.datasetName '_LEVer.mat']); goodLoad = 1; @@ -159,9 +156,6 @@ switch answer end %save out settings - settings.matFilePath = matPath; - settings.imageFile = imageFile; - settings.imagePath = [imagePath '\']; save('LEVerSettings.mat','settings'); Figures.time = 1; @@ -176,7 +170,7 @@ if ( ~isfield(CellHulls, 'imagePixels') ) fprintf('Adding Image Pixel Information...\n'); AddImagePixelsField(); fprintf('Image Information Added\n'); - save([matPath matFile],... + save([settings.matFilePath settings.matFile],... 'CellFamilies','CellHulls','CellTracks','HashedCells','Costs','CONSTANTS'); end @@ -186,12 +180,4 @@ if (~strcmp(imageDataset,CONSTANTS.datasetName)) warndlg({'Image file name does not match .mat dataset name' '' 'LEVer may display cells incorectly!'},'Name mismatch','modal'); end -% if(~isempty(Figures) && ishandle(Figures.cells.handle)) -% close(Figures.cells.handle); -% end - -% Figures.time = 1; - -% LogAction(['Opened file ' matFile],[],[]); - end diff --git a/src/MATLAB/ProcessNewborns.m b/src/MATLAB/ProcessNewborns.m index 86fecd5b..5d8942d3 100644 --- a/src/MATLAB/ProcessNewborns.m +++ b/src/MATLAB/ProcessNewborns.m @@ -15,7 +15,7 @@ for i=1:size %Get all the possible hulls that could have been connected childHullID = CellTracks(childTrackID).hulls(1); - if(childHullID>length(Costs)),continue,end + if(childHullID>length(Costs) || childHullID==0),continue,end parentHullCandidates = find(Costs(:,childHullID)); if(isempty(parentHullCandidates)),continue,end diff --git a/src/MATLAB/SaveData.m b/src/MATLAB/SaveData.m index 03269839..f13d696f 100644 --- a/src/MATLAB/SaveData.m +++ b/src/MATLAB/SaveData.m @@ -8,7 +8,7 @@ global CellFamilies CellTracks HashedCells CONSTANTS Costs CellHulls Figures if (exist('LEVerSettings.mat','file')~=0) load('LEVerSettings.mat'); else - settings.matPath = ['.\' CONSTANTS.datasetName '_LEVer_edits.mat']; + settings.matFilePath = '.\'; end %let the user know that this might take a while diff --git a/src/MATLAB/SaveDataAs.m b/src/MATLAB/SaveDataAs.m index b0af3b07..685b8736 100644 --- a/src/MATLAB/SaveDataAs.m +++ b/src/MATLAB/SaveDataAs.m @@ -8,7 +8,7 @@ global CellFamilies CellTracks HashedCells CONSTANTS Costs CellHulls Figures if (exist('LEVerSettings.mat','file')~=0) load('LEVerSettings.mat'); else - settings.matPath = ['.\' CONSTANTS.datasetName '_LEVer.mat']; + settings.matFilePath = '.\'; end goodSave = 1; @@ -16,21 +16,25 @@ goodSave = 1; while(goodSave) time = clock; fprintf('Choose a folder to save current data...\n'); - [FileName,PathName,FilterIndex] = uiputfile('.mat','Save edits',... + if(strcmp(settings.matFilePath,'.\')) + [settings.matFile,settings.matFilePath,FilterIndex] = uiputfile('.mat','Save edits',... + [CONSTANTS.datasetName '_LEVer.mat']); + else + [settings.matFile,settings.matFilePath,FilterIndex] = uiputfile('.mat','Save edits',... [CONSTANTS.datasetName ' edits ' num2str(time(1)) '-' num2str(time(2),'%02d') '-' num2str(time(3),'%02d') '_LEVer.mat']); + end if (FilterIndex~=0) - save([PathName FileName],... + save([settings.matFilePath settings.matFile],... 'CellFamilies','CellTracks','HashedCells','CONSTANTS','Costs','CellHulls'); goodSave = 0; end end -settings.matPath = [FileName PathName]; save('LEVerSettings.mat','settings'); %no longer "dirty" set(Figures.tree.menuHandles.saveMenu,'Enable','off'); set(Figures.cells.menuHandles.saveMenu,'Enable','off'); -LogAction(['Saved As: ' FileName],[],[]); +LogAction(['Saved As: ' settings.matFile],[],[]); end diff --git a/src/MATLAB/SegAndTrack.m b/src/MATLAB/SegAndTrack.m index e3f16b94..a80271ef 100644 --- a/src/MATLAB/SegAndTrack.m +++ b/src/MATLAB/SegAndTrack.m @@ -43,6 +43,8 @@ for i=1:step:numberOfImages pause(1) end +fprintf('Please wait...'); + cellSegments = GetDarkConnectedHulls(cellSegments); save ( ['SegObjs_' CONSTANTS.datasetName '.mat'],'cellSegments'); WriteSegData(cellSegments,CONSTANTS.datasetName); diff --git a/src/MATLAB/TrackSplitHulls.m b/src/MATLAB/TrackSplitHulls.m index 8a6471d8..d5ba2212 100644 --- a/src/MATLAB/TrackSplitHulls.m +++ b/src/MATLAB/TrackSplitHulls.m @@ -2,6 +2,7 @@ function trackIDs = TrackSplitHulls(newHulls, forceTracks, COM) global CONSTANTS CellHulls HashedCells t = CellHulls(newHulls(1)).time; + trackIDs = [CellHulls(newHulls).trackID]; if ( t <= 1 ) return; end -- GitLab