Home > SuperSegger > fluorescence > trackOptiFluor.m

trackOptiFluor

PURPOSE ^

trackOptiFluor calculates the mean background fluorescence for each frame.

SYNOPSIS ^

function trackOptiFluor(dirname,CONST,header)

DESCRIPTION ^

 trackOptiFluor calculates the mean background fluorescence for each frame.
 This is the fluroscence outside the background mask. It does not do any focus
 fitting at this stage. It saves the information in the err/seg
 files under data_c.fl1bg for channel 1 and data_c.fl2bg for channel 2.

 INPUT :
   dirname: seg folder eg. maindirectory/xy1/seg
   CONST: are the 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 trackOptiFluor(dirname,CONST,header)
0002 % trackOptiFluor calculates the mean background fluorescence for each frame.
0003 % This is the fluroscence outside the background mask. It does not do any focus
0004 % fitting at this stage. It saves the information in the err/seg
0005 % files under data_c.fl1bg for channel 1 and data_c.fl2bg for channel 2.
0006 %
0007 % INPUT :
0008 %   dirname: seg folder eg. maindirectory/xy1/seg
0009 %   CONST: are the segmentation constants.
0010 %   header : string displayed with information
0011 %
0012 % Copyright (C) 2016 Wiggins Lab
0013 % Written by Stella Stylianidou & Paul Wiggins.
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 
0031 if ~exist('header','var')
0032     header = [];
0033 end
0034 
0035 
0036 SE = strel( 'disk', 5 );
0037 
0038 
0039 if(nargin<1 || isempty(dirname))
0040     dirname = '.';
0041 end
0042 dirname = fixDir(dirname);
0043 
0044 % Get the track file names...
0045 contents=dir([dirname '*_err.mat']);
0046 num_im = numel(contents);
0047 
0048 if CONST.parallel.show_status
0049     h = waitbar( 0, 'Fluorescence Computation');
0050     cleanup = onCleanup( @()( delete( h ) ) );
0051 else
0052     h = [];
0053 end
0054 
0055 nc = 0;
0056 
0057 if numel(contents) > 0
0058     data_c = loaderInternal([dirname,contents(1).name]);
0059     datacFields = fieldnames(data_c);
0060     nf = numel(datacFields);
0061     % goes through the fields in data_c and calculates the number of fluorescence channels
0062     for j = 1:nf;
0063         if numel(strfind(datacFields{j},'fluor')==1) && ~numel((strfind(datacFields{j},'fluor0')))
0064             nc = nc+1;
0065         end
0066     end
0067 end
0068 
0069 
0070 % loop through all the cells.
0071 if nc > 0
0072     for i = 1:num_im
0073         data_c = loaderInternal([dirname,contents(i).name]);
0074         
0075         % Compute the background fluorescence level in both channel
0076         ss = size( data_c.mask_cell );
0077         
0078         for j = 1 : nc
0079             fluor_name = ['fluor',num2str(j)];
0080             fluor_field = data_c.(fluor_name);
0081             if isfield( data_c, 'crop_box' );
0082                 yycb = max([1,ceil(data_c.crop_box(1))]):min([ss(1),floor(data_c.crop_box(3))]);
0083                 xxcb = max([1,ceil(data_c.crop_box(2))]):min([ss(2),floor(data_c.crop_box(4))]);
0084                 fluor_tmp = fluor_field(yycb,xxcb);
0085                 mask_bg   = data_c.mask_bg(yycb,xxcb);
0086             else
0087                 fluor_tmp = fluor_field;
0088                 mask_bg   = data_c.mask_bg;
0089             end
0090             
0091             bgFluorName = ['fl',num2str(j),'bg'];
0092             back_mask = logical(imdilate(mask_bg,SE));
0093             data_c.(bgFluorName) = mean(fluor_tmp(~back_mask ));
0094         end
0095         
0096         % save the updated err files.
0097         dataname = [dirname,contents(i).name];
0098         save(dataname,'-STRUCT','data_c');
0099         
0100         if CONST.parallel.show_status
0101             waitbar(i/num_im,h,['Fluor Comp--Frame: ',num2str(i),'/',num2str(num_im)]);
0102         else
0103             disp([header, 'Fluor Comp frame: ',num2str(i),' of ',num2str(num_im)]);
0104         end
0105         
0106     end
0107 end
0108 
0109 if CONST.parallel.show_status
0110     close(h);
0111 end
0112 
0113 end
0114 
0115 
0116 function data = loaderInternal( filename )
0117 data = load( filename );
0118 end

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