Home > SuperSegger > frameLink > trackOptiLinkCellMulti.m

trackOptiLinkCellMulti

PURPOSE ^

trackOptiLinkCellMulti : links the cells frame-to-frame and resolves errors.

SYNOPSIS ^

function trackOptiLinkCellMulti (dirname,clean_flag,CONST,header,debug_flag,startFrom)

DESCRIPTION ^

 trackOptiLinkCellMulti : links the cells frame-to-frame and resolves errors.

 INPUT :
       dirname    : seg folder eg. maindirectory/xy1/seg
       clean_flag : remove all *err.mat files and start linking again
       CONST      : SuperSeggerOpti set parameters
       header     : displayed string
       debug_flag  : a flag set for displaying the results


 Copyright (C) 2016 Wiggins Lab
 Written by Stella Stylianidou.
 University of Washington, 2016
 This file is part of SuperSegger.

 SuperSegger 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.

 SuperSegger 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 SuperSegger.  If not, see <http://www.gnu.org/licenses/>.

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SUBFUNCTIONS ^

SOURCE CODE ^

0001 function trackOptiLinkCellMulti (dirname,clean_flag,CONST,header,debug_flag,startFrom)
0002 % trackOptiLinkCellMulti : links the cells frame-to-frame and resolves errors.
0003 %
0004 % INPUT :
0005 %       dirname    : seg folder eg. maindirectory/xy1/seg
0006 %       clean_flag : remove all *err.mat files and start linking again
0007 %       CONST      : SuperSeggerOpti set parameters
0008 %       header     : displayed string
0009 %       debug_flag  : a flag set for displaying the results
0010 %
0011 %
0012 % Copyright (C) 2016 Wiggins Lab
0013 % Written by Stella Stylianidou.
0014 % University of Washington, 2016
0015 % This file is part of SuperSegger.
0016 %
0017 % SuperSegger is free software: you can redistribute it and/or modify
0018 % it under the terms of the GNU General Public License as published by
0019 % the Free Software Foundation, either version 3 of the License, or
0020 % (at your option) any later version.
0021 %
0022 % SuperSegger is distributed in the hope that it will be useful,
0023 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0024 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0025 % GNU General Public License for more details.
0026 %
0027 % You should have received a copy of the GNU General Public License
0028 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0029 
0030 USE_NEW_ERROR_REZ = 0;
0031 USE_LARGE_REGION_SPLITTING = 0;
0032 
0033 
0034 if(nargin<1 || isempty(dirname))
0035     dirname=uigetdir();
0036 end
0037 
0038 dirname = fixDir(dirname);
0039 
0040 if ~exist('debug_flag','var') || isempty( debug_flag );
0041     debug_flag = 0;
0042 end
0043 
0044 if ~exist('clean_flag','var') || isempty( clean_flag );
0045     clean_flag = 0;
0046 end
0047 
0048 
0049 if ~exist('header','var')
0050     header = [];
0051 end
0052 
0053 
0054 if ~exist('startFrom','var') || isempty(startFrom)
0055     startFrom = 0;
0056 end
0057 
0058 
0059 
0060 verbose = CONST.parallel.verbose;
0061 assignmentFun = CONST.trackOpti.linkFun;
0062 
0063 filt = '*seg.mat'; % files loaded
0064 filt2 = 'err.mat'; % name of final files
0065 contents=dir([dirname,filt]);
0066 contents2=dir([dirname,'*',filt2]);
0067 
0068 if numel(contents) == 0
0069     numIm = length(contents2);
0070     contents = contents2;
0071 else
0072     numIm = length(contents);
0073 end
0074 
0075 cell_count = 0;
0076 time = 1;
0077 restartFlag = 0;
0078 
0079 if clean_flag
0080     if numel(contents) ~=0
0081         delete([dirname,'*err.mat'])
0082     end
0083 elseif startFrom~=0 && numel(contents2)>startFrom
0084     time = startFrom;
0085     dataLast = load([dirname,contents2(time).name]);
0086     cell_count = max(dataLast.regs.ID);
0087     restartFlag = 1;
0088     for xx = startFrom:numel(contents2)
0089         delete([dirname,contents2(xx).name])
0090     end
0091     disp (['starting from time : ', num2str(time)]);
0092 elseif ~isempty(contents2)
0093     time = numel(contents2);
0094     restartFlag = 1;
0095     if time > 1
0096         disp (['continuing from where I stopped - time : ', num2str(time)]);
0097         dataLast = load([dirname,contents2(end-1).name]);
0098         cell_count = max(dataLast.regs.ID);
0099     end
0100 end
0101 
0102 
0103 ignoreError = 0;
0104 ignoreAreaError = restartFlag; %Don't split big regions on restart (already done)
0105 maxIterPerFrame = 3;
0106 curIter = 1;
0107 
0108 if CONST.parallel.show_status
0109     h = waitbar( 0, 'Linking.');
0110     cleanup = onCleanup( @()( delete( h ) ) );
0111 else
0112     h = [];
0113 end
0114 
0115 while time <= numIm
0116     
0117     if CONST.parallel.show_status
0118         waitbar((numIm-time)/numIm,h,['Linking -- Frame: ',num2str(time),'/',num2str(numIm)]);
0119     end
0120     
0121     if (time == 1)
0122         data_r = [];
0123     else
0124         datarName = [dirname,contents(time-1).name];
0125         data_r = intDataLoader (datarName);
0126     end
0127     
0128     if (time == numIm)
0129         data_f = [];
0130     else
0131         datafName = [dirname,contents(time+1).name];  
0132         data_f = intDataLoader (datafName);
0133         data_f = updateRegionFields (data_f,CONST);  % make regions
0134     end
0135     
0136     datacName = [dirname,contents(time).name];
0137     data_c = intDataLoader (datacName);
0138     data_c = updateRegionFields (data_c,CONST);  % make regions
0139     lastCellCount = cell_count; % to reset cellID numbering when frame is repeated
0140         
0141     if verbose
0142         disp (['Linking for frame ', num2str(time)])
0143     end
0144     
0145     
0146     if ~isempty(data_r)
0147         [data_r.regs.map.f,data_r.regs.error.f,data_r.regs.cost.f,data_r.regs.idsC.f,data_r.regs.idsF.f,data_r.regs.dA.f,data_r.regs.revmap.f] = assignmentFun (data_r, data_c,CONST,1,0);
0148     end
0149     [data_c.regs.map.r,data_c.regs.error.r,data_c.regs.cost.r,data_c.regs.idsC.r,data_c.regs.idsR.r,data_c.regs.dA.r,data_c.regs.revmap.r]  = assignmentFun (data_c, data_r,CONST,0,0);
0150     
0151     %Split any regions that have too much growth
0152     resetRegions = 1;
0153     madeChanges = 0;
0154     
0155     if ~madeChanges
0156         [data_c.regs.map.f,data_c.regs.error.f,data_c.regs.cost.f,data_c.regs.idsC.f,data_c.regs.idsF.f,data_c.regs.dA.f,data_c.regs.revmap.f] = assignmentFun (data_c, data_f,CONST,1,0);
0157         
0158         % error resolution for each frame up to maxIterPerFrame
0159         if curIter >= maxIterPerFrame
0160             ignoreError = 1;
0161         end
0162 
0163 
0164         % error resolution and id assignment
0165         [data_c,data_r,cell_count,resetRegions] = errorRez (time, data_c, data_r, data_f, CONST, cell_count,header, ignoreError, debug_flag);       
0166         curIter = curIter + 1;
0167     end
0168     
0169     if resetRegions
0170         if verbose
0171             disp (['Frame ', num2str(time), ' : segments were reset to resolve error, repeating frame.']);
0172         end
0173         cell_count = lastCellCount;
0174         data_c.regs.ID = zeros(1,data_c.regs.num_regs); % reset cell ids
0175     else
0176         time = time + 1;
0177         ignoreError = 0;
0178         curIter = 1;
0179     end
0180     
0181     if ~isempty(data_r)
0182         dataname=[datarName(1:end-7),filt2];
0183         save(dataname,'-STRUCT','data_r');
0184     end
0185     
0186     dataname=[datacName(1:end-7),filt2];
0187     save(dataname,'-STRUCT','data_c');
0188     
0189 end
0190 
0191 
0192     function data = intDataLoader (dataName)
0193         % intDataLoader : loads the data files.
0194         % if first tries to load the fiele ending with filt2, if it doesn't find it
0195         % it loads the dataName given, and if that is notund either it
0196         % return empty.
0197         
0198         dataNameMod = [dataName(1:end-7),filt2];
0199         fidMod = fopen(dataNameMod);
0200         fid = fopen(dataName);
0201         
0202         if  fidMod ~= -1
0203             data = load(dataNameMod);
0204         elseif  fid ~= -1
0205             data = load(dataName);
0206         else
0207             data = [];
0208         end
0209         fclose('all');
0210     end
0211 
0212 end

Generated on Thu 19-Jan-2017 13:55:21 by m2html © 2005