Home > SuperSegger > batch > trackOptiSkipMerge.m

trackOptiSkipMerge

PURPOSE ^

trackOptiSkipMerge : adds skipped frames back into the time series.

SYNOPSIS ^

function trackOptiSkipMerge(dirname_xy,skip,CONST,header)

DESCRIPTION ^

 trackOptiSkipMerge : adds skipped frames back into the time series.
 It makes the _err.mat files with the fluor images corresponding 
 to the current time step. The new _err files are placed in seg_full.
 Frame skip is useful for reducing errors which you have a high frame rate. 

 INPUT : 
   dirname_xy: is the xy directory
   skip: frames mod skip are processed 
   CONST: segmentation constants
   header : string displayed with information

 Copyright (C) 2016 Wiggins Lab 
 Written by Stella Stylianidou & Paul Wiggins.
 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 trackOptiSkipMerge(dirname_xy,skip,CONST,header)
0002 % trackOptiSkipMerge : adds skipped frames back into the time series.
0003 % It makes the _err.mat files with the fluor images corresponding
0004 % to the current time step. The new _err files are placed in seg_full.
0005 % Frame skip is useful for reducing errors which you have a high frame rate.
0006 %
0007 % INPUT :
0008 %   dirname_xy: is the xy directory
0009 %   skip: frames mod skip are processed
0010 %   CONST: segmentation constants
0011 %   header : string displayed with information
0012 %
0013 % Copyright (C) 2016 Wiggins Lab
0014 % Written by Stella Stylianidou & Paul Wiggins.
0015 % University of Washington, 2016
0016 % This file is part of SuperSegger.
0017 %
0018 % SuperSegger is free software: you can redistribute it and/or modify
0019 % it under the terms of the GNU General Public License as published by
0020 % the Free Software Foundation, either version 3 of the License, or
0021 % (at your option) any later version.
0022 %
0023 % SuperSegger is distributed in the hope that it will be useful,
0024 % but WITHOUT ANY WARRANTY; without even the implied warranty of
0025 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0026 % GNU General Public License for more details.
0027 %
0028 % You should have received a copy of the GNU General Public License
0029 % along with SuperSegger.  If not, see <http://www.gnu.org/licenses/>.
0030 
0031 if ~exist('header','var')
0032     header = [];
0033 end
0034 
0035 if nargin < 2 || isempty( skip )
0036     skip = 1; % don't skip frames
0037 end
0038 
0039 file_filter = '*.tif';
0040 dirname_xy = fixDir(dirname_xy);
0041 
0042 % Reset n values in case directories have already been made.
0043 contents = dir([dirname_xy,'fluor*']);
0044 num_dir_tmp = numel(contents);
0045 nc = 1;
0046 num_c = 1;
0047 
0048 % reset values for nc
0049 for i = 1:num_dir_tmp
0050     if (contents(i).isdir) && (numel(contents(i).name) > numel('fluor'))
0051         num_c = num_c+1;
0052         nc = [nc, str2double(contents(i).name(numel('fluor')+1:end))+1];
0053     end
0054 end
0055 
0056 % Process data....
0057 
0058 contents=dir([dirname_xy,'phase',filesep,file_filter]);
0059 num_im = numel(contents);
0060 
0061 nz = zeros(1, num_im);
0062 nt = zeros(1, num_im);
0063 
0064 % reset nz values
0065 for i = 1:num_im;
0066     nameInfo = ReadFileName( contents(i).name );    
0067     nt(i) = nameInfo.npos(1,1);
0068     nz(i) = nameInfo.npos(4,1);
0069 end
0070 
0071 nt = sort(unique(nt));
0072 nz = sort(unique(nz));
0073 num_t = numel(nt);
0074 num_z = numel(nz);
0075 
0076 if nz(1)==-1
0077     nz = 1;
0078 end
0079 
0080 if ~exist([dirname_xy,'seg_full'],'dir')
0081     mkdir( [dirname_xy,'seg_full'] );
0082 end
0083 
0084 if CONST.parallel.show_status
0085     h = waitbar( 0, ['Merging Skipped frames xy: 0/',num2str(num_t)]);
0086     cleanup = onCleanup( @()( delete( h ) ) );
0087 else
0088     h=[];
0089 end
0090 
0091 %parfor i=1:num_t;
0092 for i=1:num_t;
0093     intSkipPar(i,dirname_xy,nameInfo,nt,nc,nz,skip,num_c,num_z);
0094     if CONST.parallel.show_status
0095         waitbar(i/num_t,h,...
0096             ['Merging Skipped frames t: ',num2str(i),'/',num2str(num_t)]);
0097     else
0098         disp( [header, 'skipMerge: No status bar. Frame ',num2str(i), ...
0099             ' of ', num2str(num_t),'.']);
0100     end
0101     
0102 end
0103 if CONST.parallel.show_status
0104     close(h);
0105 end
0106 end
0107 
0108 
0109 function intSkipPar(i,dirname_xy,nameInfo,nt,nc,nz,skip,num_c,num_z)
0110 % intSkipPar : makes the _err files for the frames skipped for each xy.
0111 %
0112 % INPUT :
0113 %       i : index for frame number (time), used as nt(i)
0114 %       dirname_xy : path for xy directory
0115 %       nameInfo : information about name of the files
0116 %       nt : list of time values
0117 %       nc : list of unique channel values
0118 %       nz : list of unique z values
0119 %       skip : number of frames skipped during segmentation
0120 %       num_c : total channel number
0121 %       num_z : total z-axis positions
0122 
0123 
0124 % make the segment file name and check if it already exists
0125 nameInfo_tmp               = nameInfo;
0126 nameInfo_tmp.npos([2,4],:) = 0;
0127 nameInfo_tmp.npos(1,1)     = nt(i);
0128 name                       = MakeFileName( nameInfo_tmp );
0129 nameInfo_tmp               = ReadFileName(name);
0130 name                       = name(1:max(nameInfo_tmp.npos(:,3)));
0131 
0132 dataname2 =[dirname_xy,'seg_full', filesep,name,'_seg.mat'];
0133 
0134 nameInfo_tmp = nameInfo;
0135 nameInfo_tmp.npos(1,1) = nt(i);
0136 nameInfo_tmp.npos(4,1) = 1;
0137 name = MakeFileName(nameInfo_tmp);
0138 
0139 % do the min merge of z phase
0140 phase = imread( [dirname_xy,'phase',filesep,name] );
0141 for k = 2:num_z
0142     nameInfo_tmp.npos(4,1) = nz(k);
0143     name  = MakeFileName(nameInfo_tmp);
0144     phase =  min(phase, double(imread( [dirname_xy,'phase',filesep,name] )));
0145 end
0146 
0147 % Loads the reference _err file for the image already segmented
0148 i_ref = nt(i)-mod(i-1,skip);
0149 nameInfo_tmp_ref = nameInfo;
0150 nameInfo_tmp_ref.npos([2,4],:) = 0;
0151 nameInfo_tmp_ref.npos(1,1) = i_ref;
0152 name_ref = MakeFileName( nameInfo_tmp_ref );
0153 nameInfo_tmp_ref = ReadFileName(name_ref);
0154 name_ref  = name_ref( 1:max(nameInfo_tmp_ref.npos(:,3)));
0155 dataname_ref = [dirname_xy,'seg', filesep,name_ref,'_err.mat'];
0156 data = load(dataname_ref);
0157 
0158 % loads the data reference for the min merge of z phase, sets tha name and
0159 % nameInfo, and the fluorescence field from the image to be merged.
0160 if mod(i-1,skip)
0161     data.phase = phase;
0162     data.basename = name;
0163     nameInfo_tmp = nameInfo;
0164     for k = 2:num_c
0165         % load fluor image for each channel X and put it in data.fluorX
0166         nameInfo_tmp.npos(1,1) = nt(i);
0167         nameInfo_tmp.npos(2,1) = nc(k);
0168         nameInfo_tmp.npos(4,1) = 1;
0169         name = MakeFileName( nameInfo_tmp );
0170         fluorImage = imread( [dirname_xy,'fluor',num2str(nc(k)-1),filesep,name]);
0171         data.(['fluor',num2str(nc(k)-1)]) = fluorImage;
0172     end    
0173 end
0174 
0175 save(dataname2,'-STRUCT','data');
0176 
0177 end

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