doSeg : Segments and saves data in the seg.mat files in the seg/ directory. If the seg files are already found it does not repeat the segmentation. It calls the segmentation function found in CONST.seg.segFun to achieve this. The images are not ideally segmented at this stage because they do not use temporal information, i.e. what came before or after, to optimize the segment choices; this comes at the linking stage. After it segments the data it copies the fluor fields into the data structure and saves this structure in the seg directory. INPUT : i : frame number nameInfo : nc : array of channel numbers nz : array of z values nt : array of time frames num_z : number of z's num_c : number of channels dirname_xy : xy directory clean_flag : redo segmentation if set to true skip : how many frames to skip CONST : segmentation constants header : information string crop_box : alignment information Copyright (C) 2016 Wiggins Lab Written by Paul Wiggins & 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/>.
0001 function [err_flag] = doSeg(i, nameInfo, nc, nz, nt, num_z, num_c, ... 0002 dirname_xy, skip, CONST, header, crop_box) 0003 % doSeg : Segments and saves data in the seg.mat files in the seg/ directory. 0004 % If the seg files are already found it does not repeat the segmentation. 0005 % It calls the segmentation function found in CONST.seg.segFun to achieve 0006 % this. The images are not ideally segmented at this stage because they do 0007 % not use temporal information, i.e. what came before or after, to optimize 0008 % the segment choices; this comes at the linking stage. 0009 % After it segments the data it copies the fluor fields into the data 0010 % structure and saves this structure in the seg directory. 0011 % 0012 % INPUT : 0013 % i : frame number 0014 % nameInfo : 0015 % nc : array of channel numbers 0016 % nz : array of z values 0017 % nt : array of time frames 0018 % num_z : number of z's 0019 % num_c : number of channels 0020 % dirname_xy : xy directory 0021 % clean_flag : redo segmentation if set to true 0022 % skip : how many frames to skip 0023 % CONST : segmentation constants 0024 % header : information string 0025 % crop_box : alignment information 0026 % 0027 % Copyright (C) 2016 Wiggins Lab 0028 % Written by Paul Wiggins & Stella Stylianidou. 0029 % University of Washington, 2016 0030 % This file is part of SuperSegger. 0031 % 0032 % SuperSegger is free software: you can redistribute it and/or modify 0033 % it under the terms of the GNU General Public License as published by 0034 % the Free Software Foundation, either version 3 of the License, or 0035 % (at your option) any later version. 0036 % 0037 % SuperSegger is distributed in the hope that it will be useful, 0038 % but WITHOUT ANY WARRANTY; without even the implied warranty of 0039 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 0040 % GNU General Public License for more details. 0041 % 0042 % You should have received a copy of the GNU General Public License 0043 % along with SuperSegger. If not, see <http://www.gnu.org/licenses/>. 0044 0045 0046 % Init 0047 data = []; 0048 0049 % make the segment file name and check if it already exists 0050 nameInfo_tmp = nameInfo; 0051 nameInfo_tmp.npos([2,4],:) = 0; 0052 nameInfo_tmp.npos(1,1) = nt(i); 0053 name = MakeFileName( nameInfo_tmp ); 0054 nameInfo_tmp = ReadFileName(name); 0055 name = name( 1:max(nameInfo_tmp.npos(:,3))); % has format imagename-tXX 0056 0057 data.basename = name; 0058 0059 if ~exist([dirname_xy,'seg',filesep],'dir') 0060 mkdir([dirname_xy,'seg',filesep]); 0061 end 0062 0063 dataname=[dirname_xy,'seg',filesep,name,'_seg.mat']; 0064 0065 0066 if ~exist(dataname,'file') 0067 nameInfo_tmp = nameInfo; 0068 nameInfo_tmp.npos(1,1) = nt(i); 0069 nameInfo_tmp.npos(4,1) = 1; % z value 0070 name = MakeFileName(nameInfo_tmp); 0071 namePhase = [dirname_xy,'phase',filesep,name]; 0072 phase = imread( namePhase ); 0073 0074 if num_z > 1 % if there are z frames 0075 phaseCat = zeros( [size(phase), num_z], 'uint16' ); 0076 phaseCat(:,:,1) = phase; 0077 0078 for iz = 2:num_z 0079 nameInfo_tmp.npos(4,1) = iz; 0080 name = MakeFileName(nameInfo_tmp); 0081 phaseCat(:,:,iz) = imread( [dirname_xy,'phase',filesep,name] ); 0082 end 0083 phase = mean( phaseCat, 3); 0084 end 0085 0086 if ~mod(i-1,skip) 0087 0088 if CONST.superSeggerOpti.segmenting_fluorescence 0089 % for segmenting fluorescence images 0090 % the images are inverted and the debris removal is turned off. 0091 CONST.superSeggerOpti.remove_debris = 0; 0092 CONST.superSeggerOpti.remove_microcolonies = 0; 0093 phase = max(phase(:)) - phase; 0094 end 0095 0096 % do the segmentation here 0097 [data, ~] = CONST.seg.segFun( phase, CONST, header, dataname, crop_box); 0098 if ~isempty( crop_box ) 0099 data.crop_box = crop_box; 0100 end 0101 0102 % Copy fluor data into the seg data structure 0103 nameInfo_tmp = nameInfo; 0104 for k = 2:num_c 0105 nameInfo_tmp.npos(1,1) = nt(i); 0106 nameInfo_tmp.npos(2,1) = nc(k); 0107 nameInfo_tmp.npos(4,1) = 1; 0108 name = MakeFileName( nameInfo_tmp ); 0109 fluor_tmp = imread( [dirname_xy,'fluor',num2str(nc(k)-1),filesep,name] ); 0110 data.(['fluor',num2str(nc(k)-1)])=fluor_tmp; 0111 end 0112 0113 save(dataname,'-STRUCT','data'); % Save data structure into the seg file. 0114 end 0115 else 0116 disp([dataname, ' already exists.']); 0117 end 0118 0119 end