This is a static copy of a profile report

Home

seg_cell_and_nucleus (202 calls, 41357.345 sec)
Generated 05-Nov-2014 07:52:31 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/utilities/preprocessing/3D/ashariff/seg_cell_and_nucleus.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
percellparamfunction202
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
250
[segcell, top_slice, bot_slice...
20228930.647 s70.0%
303
[segdna, ~, ~, ~] = preprocess...
20211654.300 s28.2%
222
if length(unique(cellim3)) >...
202215.809 s0.5%
296
if length(unique(dnaim3)) >...
202209.009 s0.5%
174
cellim3 = ml_readimage( cell_i...
202113.667 s0.3%
All other lines  233.914 s0.6%
Totals  41357.345 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
preprocessfunction40440584.927 s98.1%
uniquefunction404424.768 s1.0%
ml_readimagefunction808336.445 s0.8%
num2strfunction8080.300 s0.0%
filesepfunction4040.010 s0.0%
Self time (built-ins, overhead, etc.)  10.895 s0.0%
Totals  41357.345 s100% 
Code Analyzer results
Line numberMessage
6Input argument 'display' might be unused, although a later one is used. Consider replacing it by ~.
74The value assigned to variable 'verbose' might be unused.
75The value assigned to variable 'debug' might be unused.
77The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
83The value assigned to variable 'verbose' might be unused.
85Best practice is for CATCH to be followed by an identifier that gets the error information.
86The value assigned to variable 'verbose' might be unused.
92The value assigned to variable 'debug' might be unused.
94Best practice is for CATCH to be followed by an identifier that gets the error information.
95The value assigned to variable 'debug' might be unused.
103Best practice is for CATCH to be followed by an identifier that gets the error information.
125Best practice is for CATCH to be followed by an identifier that gets the error information.
133EXIST with two input arguments is generally faster and clearer than with one input argument.
148Best practice is for CATCH to be followed by an identifier that gets the error information.
168Use of brackets [] is unnecessary. Use parentheses to group, if needed.
184Use of brackets [] is unnecessary. Use parentheses to group, if needed.
199Use of brackets [] is unnecessary. Use parentheses to group, if needed.
250The value assigned here to 'sumslices' appears to be unused. Consider replacing it by ~.
269The value assigned to variable 'sumslices' might be unused.
321The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message.
334The value assigned to variable 'original_segcellsize' might be unused.
352Best practice is for CATCH to be followed by an identifier that gets the error information.
371Best practice is for CATCH to be followed by an identifier that gets the error information.
Coverage results
[ Show coverage for parent directory ]
Total lines in function375
Non-code lines (comments, blank lines)189
Code lines (lines that can run)186
Code lines that did run87
Code lines that did not run99
Coverage (did run/can run)46.77 %
Function listing
   time   calls  line
1 function [segdna,segcell] = seg_cell_and_nucleus( dna_image_file, ...
2 cell_image_file, ...
3 prot_image_file, ...
4 mask_image_file, ...
5 downsample, ...
6 display, ...
7 param, ...
8 currfile )
9
10 % Robert F. Murphy (murphy@cmu.edu)
11 %
12 % Copyright (C) 2012-2014 Murphy Lab
13 % Lane Center for Computational Biology
14 % School of Computer Science
15 % Carnegie Mellon University
16 %
17 % March 21, 2012 R.F. Murphy Fix downsampling; add display param;
18 % Only keep biggest object in each slice
19 % March 22, 2012 R.F. Murphy & Devin Sullivan Find top and bottom slice
20 % separately for cell and nucleus
21 % March 23, 2012 I. Cao-Berg Fixed a bug when getting cellnum from imgdir
22 % March 25, 2012 I. Cao-Berg The method itself checks whether a temporary file exists
23 % March 27, 2012 I. Cao-Berg Removed top and bottom blank slices from DNA and cell images
24 % April 10, 2012 I. Cao-Berg Added parameter structure to hold debug and verbose flags
25 % July 23, 2012 R.F. Murphy Add param to enforce assumption that slice with
26 % largest area is the bottom (appropriate for adherent cells
27 % August 1, 2012 I. Cao-Berg Modified the code so that is saves the bottom slice index
28 % and top slice index of the original image with
29 % respect to segcell
30 % August 2, 2012 D. Sullivan Fixed a bug where the DNA top/bot where saved instead of the
31 % cell membrane
32 % August 30, 2012 G. Johnson Added check_img_dirs to use pre-existing directories to
33 % infer values for missing directories.
34 % Added a check to skip processing for any
35 % binary images.
36 % Moved all processing steps (deconvolution, cropping, etc) to
37 % a single routine for ease of upkeep.
38 % Sept 7, 2012 G Johnson Added t/f flag for check_img_dirs
39 % May 15, 2013 I. Cao-Berg Updated method to support wildcards
40 % July 2, 2013 R.F. Murphy Replaced calls to "boolean" with "logical"
41 % July 13, 2013, G. Johnson Changed logic such that ifthe cell image is
42 % logical, use the protein image for the nuclear
43 % segmentation
44 %
45 % This program is free software; you can redistribute it and/or modify
46 % it under the terms of the GNU General Public License as published
47 % by the Free Software Foundation; either version 2 of the License,
48 % or (at your option) any later version.
49 %
50 % This program is distributed in the hope that it will be useful, but
51 % WITHOUT ANY WARRANTY; without even the implied warranty of
52 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
53 % General Public License for more details.
54 %
55 % You should have received a copy of the GNU General Public License
56 % along with this program; if not, write to the Free Software
57 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
58 % 02110-1301, USA.
59 %
60 % For additional information visit http://murphylab.web.cmu.edu or
61 % send email to murphy@cmu.edu
62
63 % temporaryFolder = [ pwd filesep 'temp' filesep 'preprocessing' ];
202 64 temporaryFolder = [ param.preprocessingFolder ];
202 65 if ~exist( temporaryFolder, 'dir' )
66 mkdir( temporaryFolder );
67 end
68
202 69 segdna = [];
202 70 segcell = [];
71
202 72 if nargin == 6
73 param = [];
74 verbose = false;
75 debug = false;
0.01 202 76 elseif nargin > 8
77 warning('CellOrganizer: Wrong number of input arguments.');
78 return
202 79 else
202 80 try
202 81 verbose = param.verbose;
202 82 if ~islogical( verbose )
83 verbose = false;
84 end
85 catch
86 verbose = false;
87 end
88
202 89 try
202 90 debug = param.debug;
202 91 if ~islogical( debug )
92 debug = false;
93 end
94 catch
95 debug = false;
96 end
97
202 98 try
0.03 202 99 adherent = param.adherent;
100 if ~islogical( adherent )
101 adherent = true;
102 end
202 103 catch
202 104 adherent = true;
202 105 end
106
202 107 end
108
109 %icaoberg 26/1/2014
110 %updated code so that it uses the display variable from parameter structure
111 %rather than the display variable. i kept the same method call to allow
112 %backward compatibility
202 113 if ~isfield( param, 'display' )
114 display = param.display;
202 115 else
0.01 202 116 display = false;
202 117 end
118
119 %icaoberg fixed bug
120 %gj aug 29, 2012
121 %changed img=='/' to img==filesep
202 122 if ~exist( 'currfile', 'var' )
123 try
124 cellnum = param.cellnum;
125 catch
126 cellnum = 0;
127 end
202 128 else
202 129 cellnum = currfile;
202 130 end
131
132 %icaoberg march 26, 2012
0.19 202 133 if exist( [ temporaryFolder ...
134 filesep 'cell' num2str(cellnum) '.mat' ] )
135 load( [ temporaryFolder ...
136 filesep 'cell' num2str(cellnum) '.mat' ] );
137 return
138 end
139
140 %icaoberg 26/1/2014
141 %included these strings in the parameter structure so that preprocess can
142 %use them
0.01 202 143 try
0.02 202 144 param.dna_image_file = dna_image_file;
202 145 param.cell_image_file = cell_image_file;
202 146 param.prot_image_file = prot_image_file;
202 147 param.prot_image_file = mask_image_file;
148 catch
149 disp( 'Unable to save image filenames in parameter structure' );
150 end
151
152 %gj aug 29, 2012
153 % if ~check_img_dirs(imgdir,param)
154 % return;
155 % end
156
157 % if any(round(downsample)~=downsample)
158 % warning('Downsampling vector rounded to integers');
159 % end
160 % downsample=round(downsample);
161
162
163 %%% Process protein image first %%%
202 164 disp( 'Processing protein image' )
165
166 %icaoberg march 12, 2014
202 167 if isa( cell_image_file, 'function_handle' )
168 disp( ['Reading cell image file'] );
202 169 else
202 170 disp( ['Reading cell image file: ' cell_image_file] );
0.01 202 171 end
172
0.01 202 173 try
113.67 202 174 cellim3 = ml_readimage( cell_image_file );
175 catch err
176 disp( [ 'Unable to load image: ' cell_image_file ] );
177 getReport( err, 'extended' )
178 segdna = []; segcell = []; return
179 end
180
181
182 %icaoberg march 12, 2014
202 183 if isa( prot_image_file, 'function_handle' )
184 disp( ['Reading protein image file'] );
202 185 else
0.01 202 186 disp( ['Reading protein image file: ' prot_image_file] );
202 187 end
188
202 189 try
109.94 202 190 improt = ml_readimage( prot_image_file );
191 catch err
192 disp( [ 'Unable to load image: ' prot_image_file ] );
193 getReport( err, 'extended' )
194 segdna = []; segcell = []; return
195 end
196
197 %icaoberg march 12, 2014
202 198 if isa( mask_image_file, 'function_handle' )
199 disp( ['Reading mask image file'] );
202 200 else
0.05 202 201 disp( ['Reading mask image file: ' mask_image_file] );
0.01 202 202 end
203
0.01 202 204 try
2.74 202 205 mask = ml_readimage( mask_image_file );
206 catch err
207 disp( [ 'Unable to load image: ' mask_image_file ] );
208 getReport( err, 'extended' )
209 segdna = []; segcell = []; return
210 end
211
212 %protim3 = tz_maskimg_3d(protim3,mask);
213 %D. Sullivan 6/16/13 making masks optional
214 % if ~isempty(mask)
215 % cellim3 = tz_maskimg_3d( cellim3, mask );
216 % end
217 % clear mask
218
219 %D. Sullivan 6/12/13 make sure the flag calls for this
202 220 if strcmpi(param.train.flag,'all') || strcmpi(param.train.flag,'framework')
221 %grj 3/29/13, improved this block for readability
215.81 202 222 if length(unique(cellim3)) > 2
223 %D. Sullivan 6/6/13 cellfile is never used, old name.
0.09 202 224 cellfile=['cell_image' num2str(cellnum) '.mat'];
225 %D. Sullivan 3/21/13, need to pass the psf in rather than always using
226 %the HeLa one.
227 % [segcell, top_slice, bot_slice, sumslices] = preprocess(cellim3, cellfile, '3DHeLa_Cell_PSF.tif', downsample, adherent, 0.98, 0.02, display);
0.01 202 228 if isfield(param,'psf')
229 psf = param.psf;
202 230 else
231 %icaoberg
232 %removing use of default 3D hela psf
202 233 disp('No PSF specified.');
0.01 202 234 psf = [];
202 235 end
236
237 %D.Sullivan 3/21/13 added zflip flag if the cell was upsidedown.
238 %This lets us know to change the nuclear orientation
239 %default is 0
240
202 241 disp( 'Preprocessing cell image' );
242 %icaoberg 26/1/2014
243 %documented for debugging purposes
244
202 245 top_thresh = 0.98; %the fraction of fluorescence you wish to consider as the top slice
202 246 bot_thresh = 0.02; %the fraction of fluorescence you wish to consider as the bottom slice
247
248 %output filename for active contour segmentation debug plots
0.01 202 249 param.output_filename = param.cell_image_file;
28930.65 202 250 [segcell, top_slice, bot_slice, sumslices,zflip] = preprocess( cellim3, ...
251 cellfile, psf, downsample, adherent, top_thresh, bot_thresh, display, mask, param );
252
253 else
254 %D. Sullivan 6/16/13 - force segcell to be 0/1 valued boolean.
255 segcell = cellim3;
256
257 %murphy 7/2/2012
258 segcell = logical(segcell);
259
260 %D. Sullivan 6/16/13 added downsampling here.
261 fprintf(1,'%s\n','Downsampling image'); tic;
262 segcell = ml_downsize(segcell,downsample,'linear'); toc
263
264 a = find(sum(sum(segcell,1),2));
265 bot_slice = a(1);
266 top_slice = a(end);
267
268 sumslices = cumsum(squeeze(sum(sum(cellim3))));
269 sumslices = sumslices/sumslices(end);
270 end
202 271 end
272 %%% Process DNA image now %%%
273 %protim3 = ml_loadimage([imgdir '/prot/'],'tif');
274 %D. Sullivan 3/21/13 added check on file structure
110.12 202 275 dnaim3 = ml_readimage( dna_image_file );
276
0.01 202 277 if isempty(dnaim3)
278 %G. Johnson 7/13/13 if the cell image is logical, use the protein image
279 %for the nuclear segmentation
280 %G. Johnson 8/2/13 change from logical to contains more than 2 pixel
281 %values
282 disp('Finding nuclear mask')
283 if length(unique(cellim3(:))) > 2
284 dnaim3 = findDnaMask( ml_downsize(cellim3,downsample,'linear'), segcell, param );
285 else
286 dnaim3 = findDnaMask( ml_downsize(improt,downsample,'linear'), segcell, param );
287 end
288 end
289
290 %D. Sullivan 6/16/13 - check that there is a mask
291 % if ~isempty(mask)
292 % dnaim3 = tz_maskimg_3d( dnaim3, mask );
293 % end
294
295 %%%%Preprocessing starts here
209.01 202 296 if length(unique(dnaim3)) > 2
0.13 202 297 dnafile=['dna_image' num2str(cellnum) '.mat'];
298
0.02 202 299 disp( 'Preprocess nuclear image' );
0.01 202 300 param.output_filename = param.dna_image_file;
301 %psf_filename = '3DHeLa_DNA_PSF.tif';
0.01 202 302 psf_filename = '';
11654.30 202 303 [segdna, ~, ~, ~] = preprocess(dnaim3, dnafile, psf_filename, downsample, false, 0.95, 0.05, display, segcell, param );
304
305 %D. Sullivan 6/12/13 moved this code since order of segmentation is now
306 %different
202 307 if zflip
308 segdna = flipdim(segdna,3);
309 end
310
311 else
312
313 %D. Sullivan 3/21/13 make sure segdna is the correct size
314 if all(size(dnaim3)==size(cellim3))
315 %no downsampling has been done yet
316 segdna = ml_downsize(dnaim3,downsample,'linear');
317 elseif all(size(dnaim3) == floor(size(cellim3)./downsample))
318 %all downsampling has been done previously
319 segdna = dnaim3;
320 else
321 warning(['Preprocessed nuc image size does not match cell image size. ',...
322 'This could be caused by manual cropping of nuc image. ',...
323 'Forcing images to the same size. This may cause unexpected results']);
324 dnadownsample = size(dnaim3)./size(cellim3);
325 segdna = ml_downsize(dnaim3,dnadownsample,'linear');
326 end
327
328 %murphy 7/2/2013
329 segdna = logical(segdna);
330
331 end
332
0.01 202 333 if strcmpi(param.train.flag,'all')||strcmpi(param.train.flag,'framework')
202 334 original_segcellsize = size(segcell);
0.41 202 335 segcell = segcell(:,:,bot_slice:top_slice);
0.51 202 336 segdna = segdna(:,:,bot_slice:top_slice);
337
338 % make sure that no part of the nucleus is outside the cell
0.27 202 339 segdna = and(segdna,segcell);
202 340 end
341
202 342 if display
343 try
344 % pause
345 figure;
346 for i=1:size(segdna,3)
347 RGB(:,:,1)=uint8(segdna(:,:,i)*255);
348 RGB(:,:,2)=uint8(segcell(:,:,i)*255);
349 RGB(:,:,3)=uint8(zeros(size(segdna(:,:,i))));
350 imshow(RGB); pause(0.1);
351 end
352 catch
353 end
354 end
355
356 %icaoberg march 26, 2012
202 357 try
0.02 202 358 disp('Saving preprocessed files to disk.');
359
360 %icaoberg 1/8/2012
0.01 202 361 if strcmpi(param.train.flag,'all') || strcmpi(param.train.flag,'framework')
2.42 202 362 save( [ temporaryFolder ...
363 filesep 'cell' num2str(cellnum) '.mat' ], 'segcell', 'segdna', 'downsample', ...
364 'original_segcellsize', 'bot_slice', 'top_slice', 'sumslices', ...
365 'dna_image_file', 'cell_image_file', 'prot_image_file', 'mask_image_file' );
366 else
367 save( [ temporaryFolder ...
368 filesep 'cell' num2str(cellnum) '.mat' ], 'segdna', 'downsample','sumslices', ...
369 'dna_image_file', 'cell_image_file', 'prot_image_file', 'mask_image_file' );
370 end
371 catch
372 disp( 'Unable to save preprocessed files to disk.' );
373 end
374
202 375 end

Other subfunctions in this file are not included in this listing.