From b8078501148558abdce7b71540506f877af7b728 Mon Sep 17 00:00:00 2001
From: Eric Wait <eric@waitphoto.com>
Date: Fri, 8 Apr 2011 22:47:18 -0500
Subject: [PATCH] LEVer 4.1

---
 .gitignore                       |  1 +
 src/MATLAB/AddConstant.m         | 21 +++++++++++++++++++
 src/MATLAB/InitializeConstants.m | 35 ++++++++++++++++----------------
 src/MATLAB/OpenData.m            | 21 +++++++------------
 src/MATLAB/SegAndTrack.m         |  1 -
 src/MATLAB/Segmentor.m           |  9 ++++++--
 src/MATLAB/TrackSplitHulls.m     |  7 ++++++-
 7 files changed, 59 insertions(+), 36 deletions(-)
 create mode 100644 src/MATLAB/AddConstant.m

diff --git a/.gitignore b/.gitignore
index 85223e81..867e20ea 100644
--- a/.gitignore
+++ b/.gitignore
@@ -1,4 +1,5 @@
 
+*~
 bin/*.c
 bin/*.log
 *.mat
diff --git a/src/MATLAB/AddConstant.m b/src/MATLAB/AddConstant.m
new file mode 100644
index 00000000..1f131407
--- /dev/null
+++ b/src/MATLAB/AddConstant.m
@@ -0,0 +1,21 @@
+function AddConstant(field,val,overWrite)
+% AddConstant(field,val,overWrite) will add the given field to the
+% CONSTANTS global variable and assign it the given value.
+% overWrite - is an optional flag {0,1} that will force the new value if
+% the field exists. Zero will keep the old value, One will overwrite the
+% current value
+
+%--Eric Wait
+
+global CONSTANTS
+
+if(~exist('overWrite','var'))
+    overWrite = 0;
+end
+
+if(~isfield(CONSTANTS,field))
+    CONSTANTS.(field) = val;
+elseif(overWrite)
+    CONSTANTS.(field) = val;
+end
+end
\ No newline at end of file
diff --git a/src/MATLAB/InitializeConstants.m b/src/MATLAB/InitializeConstants.m
index e61181fa..b82f31f5 100644
--- a/src/MATLAB/InitializeConstants.m
+++ b/src/MATLAB/InitializeConstants.m
@@ -2,23 +2,22 @@ function InitializeConstants()
 %Set all constants here
 
 %--Eric Wait
-global CONSTANTS
 
-CONSTANTS.imageAlpha = 1;
-CONSTANTS.maxRetrackDistSq = 40^2;
-CONSTANTS.maxPixelDistance = 40;
-CONSTANTS.maxCenterOfMassDistance = 80;
-CONSTANTS.minParentCandidateTimeFrame = 5;
-CONSTANTS.minParentHistoryTimeFrame = 5;
-CONSTANTS.minParentFuture = 5;
-CONSTANTS.minFamilyTimeFrame = 5;
-CONSTANTS.maxFrameDifference = 5;
-CONSTANTS.historySize = 50;
-CONSTANTS.clickMargin = 500;
-CONSTANTS.timeResolution = 10; %in frames per min
-CONSTANTS.dMaxConnectComponet = 40;
-CONSTANTS.dMaxCenterOfMass = 80;
-CONSTANTS.lookAhead = 2;
-CONSTANTS.minPlayer = 9;
-CONSTANTS.minMitosis = 30;
+AddConstant('imageAlpha',1.5);
+AddConstant('maxRetrackDistSq',40^2);
+AddConstant('maxPixelDistance',40);
+AddConstant('maxCenterOfMassDistance',80);
+AddConstant('minParentCandidateTimeFrame',5);
+AddConstant('minParentHistoryTimeFrame',5);
+AddConstant('minParentFuture',5);
+AddConstant('minFamilyTimeFrame',5);
+AddConstant('maxFrameDifference',5);
+AddConstant('historySize',50);
+AddConstant('clickMargin',500);
+AddConstant('timeResolution',10); %in frames per min
+AddConstant('dMaxConnectComponet',40);
+AddConstant('dMaxCenterOfMass',80);
+AddConstant('lookAhead',2);
+AddConstant('minPlayer',9);
+AddConstant('minMitosis',30);
 end
\ No newline at end of file
diff --git a/src/MATLAB/OpenData.m b/src/MATLAB/OpenData.m
index a08b6921..7aad96c8 100644
--- a/src/MATLAB/OpenData.m
+++ b/src/MATLAB/OpenData.m
@@ -7,7 +7,7 @@ function opened = OpenData()
 
 global Figures Colors CONSTANTS CellFamilies CellHulls HashedCells Costs CellTracks
 if(isempty(Figures))
-    fprintf('LEVer ver 4.0\n***DO NOT DISTRIBUTE***\n\n');
+    fprintf('LEVer ver 4.1\n***DO NOT DISTRIBUTE***\n\n');
 end
 
 if(exist('ColorScheme.mat','file'))
@@ -30,11 +30,6 @@ if (~exist('settings','var') || isempty(settings))
 end
 
 filterIndexImage = 0;
-matFile = [];
-matFilePath = [];
-imageFile = [];
-imagePath = [];
-imageDataset = [];
 goodLoad = 0;
 opened = 0;
 
@@ -56,7 +51,6 @@ if(~isempty(Figures))
 end
 
 oldCONSTANTS = CONSTANTS;
-InitializeConstants();
 
 %find the first image
 imageFilter = [settings.imagePath '*.TIF'];
@@ -70,7 +64,6 @@ while (filterIndexImage==0)
 end
 
 index = strfind(settings.imageFile,'_t');
-frameT = '001';
 if (~isempty(index) && filterIndexImage~=0)
     CONSTANTS.rootImageFolder = settings.imagePath;
     imageDataset = settings.imageFile(1:(index(length(index))-1));
@@ -117,11 +110,11 @@ switch answer
                     end
                 catch
                 end
-                CellFamilies = [];
-                CellTracks = [];
-                CellHulls = [];
-                HashedCells = [];
-                Costs = [];
+%                 CellFamilies = [];
+%                 CellTracks = [];
+%                 CellHulls = [];
+%                 HashedCells = [];
+%                 Costs = [];
 				rootImageFolder = CONSTANTS.rootImageFolder;
                 imageSignificantDigits = CONSTANTS.imageSignificantDigits;
 				
@@ -160,7 +153,7 @@ switch answer
         
         Figures.time = 1;
         
-        LogAction(['Opened file ' matFile],[],[]);
+        LogAction(['Opened file ' settings.matFile],[],[]);
     otherwise
         return
 end
diff --git a/src/MATLAB/SegAndTrack.m b/src/MATLAB/SegAndTrack.m
index a80271ef..ddb2799e 100644
--- a/src/MATLAB/SegAndTrack.m
+++ b/src/MATLAB/SegAndTrack.m
@@ -51,7 +51,6 @@ WriteSegData(cellSegments,CONSTANTS.datasetName);
 
 fprintf(1,'\nDone\n');
 
-load ( ['SegObjs_' CONSTANTS.datasetName '.mat']);
 fnameIn=['SegObjs_' CONSTANTS.datasetName '.txt'];
 fnameOut=['Tracked_' CONSTANTS.datasetName '.txt'];
 tSeg=toc;
diff --git a/src/MATLAB/Segmentor.m b/src/MATLAB/Segmentor.m
index 1e01b415..b14d8ca7 100644
--- a/src/MATLAB/Segmentor.m
+++ b/src/MATLAB/Segmentor.m
@@ -8,7 +8,7 @@ function objs = Segmentor(tStart,tLength,rootImageFolder,datasetName,imageAlpha,
 %--Andrew Cohen
 
 % global CONSTANTS
-se=strel('square',3);
+
 
 objs=[];
 if(ischar(tStart)),tStart = str2double(tStart);end
@@ -30,6 +30,11 @@ for t = tStart:tStart + tLength
     fname=[rootImageFolder '\' datasetName '_t' frameT '.TIF'];
     if(isempty(dir(fname))),continue,end
     
+    fprintf('%d, ', t);
+    if ( mod(t,20) == 0 )
+        fprintf('\n');
+    end
+    
     [im map]=imread(fname);
     im=mat2gray(im);
     
@@ -44,7 +49,7 @@ for t = tStart:tStart + tLength
     
     % bwNorm=GetNormalVectors(bwHalo,bwDark);
     bwNorm=0*bwDark;
-    
+    se=strel('square',3);
     gd=imdilate(im,se);
     ge=imerode(im,se);
     ig=gd-ge;
diff --git a/src/MATLAB/TrackSplitHulls.m b/src/MATLAB/TrackSplitHulls.m
index d5ba2212..5ca54d55 100644
--- a/src/MATLAB/TrackSplitHulls.m
+++ b/src/MATLAB/TrackSplitHulls.m
@@ -2,7 +2,12 @@ function trackIDs = TrackSplitHulls(newHulls, forceTracks, COM)
     global CONSTANTS CellHulls HashedCells
     
     t = CellHulls(newHulls(1)).time;
-    trackIDs = [CellHulls(newHulls).trackID];
+    
+    trackIDs = [];
+    for i = 1:length(newHulls)
+        trackIDs = [trackIDs GetTrackID(newHulls(i))];
+    end
+    
     if ( t <= 1 )
         return;
     end
-- 
GitLab