This is a static copy of a profile reportHome
region_seg (404 calls, 40131.760 sec)
Generated 05-Nov-2014 07:52:34 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/utilities/preprocessing/3D/ashariff/region_seg.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Function Name | Function Type | Calls |
preprocess | function | 404 |
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
137 | phi = sussman(phi, .5); | 234500 | 34283.851 s | 85.4% |  |
123 | v = sum(I(vpts))/(length(vpts)... | 234500 | 1452.469 s | 3.6% |  |
126 | curvature = get_curvature(phi,... | 234500 | 1385.346 s | 3.5% |  |
114 | idx = find(phi <= 1.2 &... | 234500 | 1033.580 s | 2.6% |  |
121 | vpts = find(phi>0); ... | 234500 | 924.609 s | 2.3% |  |
All other lines | | | 1051.905 s | 2.6% |  |
Totals | | | 40131.760 s | 100% | |
Children (called functions)
Code Analyzer results
Line number | Message |
1 | Input argument 'display' might be unused, although a later one is used. Consider replacing it by ~. |
76 | The value assigned to variable 'display' might be unused. |
98 | Best practice is for CATCH to be followed by an identifier that gets the error information. |
143 | Best practice is for CATCH to be followed by an identifier that gets the error information. |
150 | NUMEL(x) is usually faster than PROD(SIZE(x)). |
150 | For better readability, use newline, semicolon, or comma before this statement. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 175 |
Non-code lines (comments, blank lines) | 99 |
Code lines (lines that can run) | 76 |
Code lines that did run | 46 |
Code lines that did not run | 30 |
Coverage (did run/can run) | 60.53 % |
Function listing
time calls line
1 function seg = region_seg( I, init_mask, max_its, alpha, display, quit_tol, ...
2 param )
3 % Region Based Active Contour Segmentation
4 %
5 % seg = region_seg(I,init_mask,max_its,alpha,display,quit_tol)
6 %
7 % Inputs: I 2D image
8 % init_mask Initialization (1 = foreground, 0 = bg)
9 % max_its Number of iterations to run segmentation for
10 % alpha (optional) Weight of smoothing term
11 % higer = smoother. default = 0.2
12 % display (optional) displays intermediate outputs
13 % default = true
14 % quit_tol (optional) quit if fraction of all points that
15 % move between 10 iterations is <= this
16 % dirFlag Direction of propagation. False - outside-in, True -
17 % inside-out
18 %
19 % Outputs: seg Final segmentation mask (1=fg, 0=bg)
20 %
21 % Description: This code implements the paper: "Active Contours Without
22 % Edges" By Chan Vese. This is a nice way to segment images whose
23 % foregrounds and backgrounds are statistically different and homogeneous.
24 %
25 % Example:
26 % img = imread('tire.tif');
27 % m = zeros(size(img));
28 % m(33:33+117,44:44+128) = 1;
29 % seg = region_seg(img,m,500);
30
31 % Original Author: Shawn Lankton (www.shawnlankton.com)
32 %
33 % Copyright (C) 2012-2014 Murphy Lab
34 % Lane Center for Computational Biology
35 % School of Computer Science
36 % Carnegie Mellon University
37 %
38 % March 15, 2012 R.F. Murphy Added convergence tolerance
39 % July 1, 2012 G.J. Johnson, Allows for 3D images
40 % March 15, 2012 R.F. Murphy Added convergence tolerance
41 % April 24, 2014 I. Cao-Berg Created PLOT_SWITCH that turns on/off display
42 % of results. Default is off and this is a hidden parameter only meant for
43 % developers use.
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
404 63 if nargin == 6
64 param = [];
65 param = ml_initparam( param, struct( 'debug', false ) );
66 param = ml_initparam( param, struct( 'display', false ) );
67 end
68
69 %-- default value for parameter alpha is .1
0.02 404 70 if(~exist('alpha','var'))
71 alpha = .2;
72 end
73
74 %-- default behavior is to display intermediate outputs
404 75 if(~exist('display','var'))
76 display = false;
77 end
404 78 PLOT_SWITCH = false;
79
80 %-- default behavior is to quit if no points moved between 10 iterations
0.02 404 81 if(~exist('quit_tol','var'))
82 quit_tol = 0;
83 end
84 %-- ensures image is 2D double matrix
0.02 404 85 I = im2graydouble(I);
86
87 %-- Create a signed distance map (SDF) from mask
35.90 404 88 phi = mask2phi(init_mask);
404 89 oldphi = phi; % copy for testing exit condition
90
91 %-- show starting mask
92 %icaoberg when these two are set it will save the display to disk. much
93 %faster than making an actual display
404 94 disp( 'Display and debug flags are on. Will attempt to make and save debugging plots to disk' );
404 95 if param.display && param.debug && PLOT_SWITCH
96 try
97 showCurveAndPhi( I, phi, 0 );
98 catch
99 disp( 'Unable to open display. Skipping saving of intermediate results plot.' );
100 end
101 end
102
103 %icaoberg 4/24/2014
404 104 ITERATION_DISPLAY_NUMBER = 100;
105 %--main loop
0.13 404 106 disp( ['Maximum number of iterations set to: ' num2str(max_its)] );
404 107 times = 0;
404 108 for its = 1:max_its
1.34 234500 109 tic
1.09 234500 110 if(mod(its,ITERATION_DISPLAY_NUMBER) == 0)
1.05 2158 111 disp( ['Iteration: ' num2str(its) ] );
0.01 2158 112 end
113
1033.58 234500 114 idx = find(phi <= 1.2 & phi >= -1.2); %get the curve's narrow band
115
3.11 234500 116 if isempty(idx)
117 break;
118 end
119 %-- find interior and exterior mean
585.22 234500 120 upts = find(phi<=0); % interior points
924.61 234500 121 vpts = find(phi>0); % exterior points
136.43 234500 122 u = sum(I(upts))/(length(upts)+eps); % interior mean
1452.47 234500 123 v = sum(I(vpts))/(length(vpts)+eps); % exterior mean
124
48.92 234500 125 F = (I(idx)-u).^2-(I(idx)-v).^2; % force from image information
1385.35 234500 126 curvature = get_curvature(phi,idx); % force from curvature penalty
127
50.63 234500 128 dphidt = F./max(abs(F)) + alpha*curvature; % gradient descent to minimize energy
129
130 %-- maintain the CFL condition
15.19 234500 131 dt = .45/(max(dphidt)+eps);
132
133 %-- evolve the curve
57.91 234500 134 phi(idx) = phi(idx) + dt.*dphidt;
135
136 %-- Keep SDF smooth
34283.85 234500 137 phi = sussman(phi, .5);
138
139 %-- intermediate output
0.70 234500 140 if param.display && param.debug && (mod(its,50) == 0) && PLOT_SWITCH
141 try
142 showCurveAndPhi(I,phi,its);
143 catch
144 disp( 'Unable to open display. Skipping saving of intermediate results plot.' );
145 end
146 end
147
1.01 234500 148 if(~mod(its,10))
102.66 23450 149 pointsmoved = sum(sum(xor(oldphi<=0,phi<=0)));
0.27 23450 150 if pointsmoved <= quit_tol*prod(size(I)) break, end % test for convergence
0.15 23046 151 oldphi = phi; % copy for testing exit condition
0.09 23046 152 end
153
4.50 234096 154 times = times + toc;
1.56 234096 155 if(mod(its,ITERATION_DISPLAY_NUMBER) == 0)
0.01 2122 156 times = times + toc;
1.35 2122 157 disp( ['Elapsed time: ' num2str(times)] );
0.01 2122 158 times = 0;
0.05 2122 159 end
1.79 234096 160 end
161
162 %-- final output
404 163 if param.display && param.debug && PLOT_SWITCH
164 try
165 showCurveAndPhi(I,phi,its);
166 catch err
167 getReport( err, 'extended' );
168 end
169 end
170
171 %icaoberg 9/7/2013
0.30 404 172 close all
173
174 %-- make final mask from SDF
0.44 404 175 seg = phi<=0; %-- Get mask from levelset
Other subfunctions in this file are not included in this listing.