This is a static copy of a profile reportHome
ml_rcthreshold (404 calls, 11.916 sec)
Generated 05-Nov-2014 07:52:50 using cpu time.
function in file /usr0/home/jenkins/workspace/cellorganizer-demo3D11-glnx64/utilities/2D/tztoolbox/ml_rcthreshold.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 |
73 | img = uint16((img- imgMin)/img... | 404 | 3.965 s | 33.3% |  |
119 | sum3 = sum([MovingIndex:MaxInd... | 5286 | 2.483 s | 20.8% |  |
84 | histo = imhist(img(:),bins); | 404 | 1.722 s | 14.5% |  |
121 | sum4 = sum(histo(MovingIndex:M... | 5286 | 1.061 s | 8.9% |  |
116 | sum1 = sum([MinIndex:MovingInd... | 5286 | 0.901 s | 7.6% |  |
All other lines | | | 1.782 s | 15.0% |  |
Totals | | | 11.916 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
imhist | function | 404 | 1.702 s | 14.3% |  |
Self time (built-ins, overhead, etc.) | | | 10.214 s | 85.7% |  |
Totals | | | 11.916 s | 100% | |
Code Analyzer results
Line number | Message |
86 | The value assigned to variable 'hsum' might be unused. |
104 | The first argument of WARNING should be a message identifier. Using a message identifier allows users better control over the message. |
116 | Use of brackets [] is unnecessary. Use parentheses to group, if needed. |
119 | Use of brackets [] is unnecessary. Use parentheses to group, if needed. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 134 |
Non-code lines (comments, blank lines) | 81 |
Code lines (lines that can run) | 53 |
Code lines that did run | 43 |
Code lines that did not run | 10 |
Coverage (did run/can run) | 81.13 % |
Function listing
time calls line
1 function threshold = ml_rcthreshold(img)
2 % ML_RCTHRESHOLD - Find a threshold for IMAGE
3 % ML_RCTHRESHOLD(IMAGE) - input is output from nihscale(image)
4 % output is threshold value using same algorithm as nih image
5 % Ridler and Calvard (IEEE tans. on Systems, man, cybernetics
6 % SMC-8 no 8 aug 1978)
7 % Trussel (same journal) SMC-9 no 5 may 1979
8 %
9 % Basically, the algorithm moves the proposed threshold from the
10 % minimum non-zero bin of the histogram to the maximum non-zero bin.
11 % While doing so, it calculates the 'center of mass' separately
12 % for that part of the histogram below the proposed threshold and
13 % that part above. While the proposed threshold is less than
14 % the mean of these two centers of mass, the algorithm continues.
15 % When this condition no longer holds, the proposed threshold is
16 % rounded to give a final result.
17 %
18 % If <= one intensity value is nonzero output threshold will be 1/2
19 % and error message will be printed to screen
20 %
21 % 20 Aug 98 - M.V. Boland. Modified from version written by W. Dirks.
22 %
23 % Sometime in Year 2000, MV and RFM noticed that the algorithm
24 % had not been implemented properly. Corrected by MV and RFM.
25
26 % Copyright (C) 2006 Murphy Lab
27 % Carnegie Mellon University
28 %
29 % This program is free software; you can redistribute it and/or modify
30 % it under the terms of the GNU General Public License as published
31 % by the Free Software Foundation; either version 2 of the License,
32 % or (at your option) any later version.
33 %
34 % This program is distributed in the hope that it will be useful, but
35 % WITHOUT ANY WARRANTY; without even the implied warranty of
36 % MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
37 % General Public License for more details.
38 %
39 % You should have received a copy of the GNU General Public License
40 % along with this program; if not, write to the Free Software
41 % Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
42 % 02110-1301, USA.
43 %
44 % For additional information visit http://murphylab.web.cmu.edu or
45 % send email to murphy@cmu.edu
46
47 %Modified by T. Zhao to fix bugs
48 % July 2, 2012 Gregory Johnson - modified to accept images of arbitrary bit depth by converting them do 16-bit
49
404 50 converted = false;
0.01 404 51 if strcmp(class(img),'uint8')
52 %disp ('Image is uint8, using 256 bin histogram');
53 bins = 256;
54
404 55 elseif strcmp(class(img),'uint16')
56 %disp ('Image is uint16, using 65536 bin histogram');
57 bins = 65536;
404 58 else
59 %disp ('Can''t determine bit depth. Converting to 16-bit')
404 60 bins = 65536 ;
61
404 62 img = double(img);
63
64
65
0.38 404 66 imgMin = min(img(:));
0.32 404 67 imgMax = max(img(:));
68
0.01 404 69 imgDiff = imgMax - imgMin;
70
71
72
3.97 404 73 img = uint16((img- imgMin)/imgDiff * bins);
74
404 75 converted = true;
0.01 404 76 end
77
0.01 404 78 imgsize=size(img);
79
0.01 404 80 if length(imgsize)>2
81 img=reshape(img,imgsize(1),prod(imgsize(2:end)));
82 end
83
1.72 404 84 histo = imhist(img(:),bins);
85
0.04 404 86 hsum = sum(histo);
87
88
0.20 404 89 histo(1) = [];
404 90 histo(bins-1) = 0;
91
92
0.22 404 93 whitepos=find(histo>0);
94
404 95 MinIndex=1;
404 96 MaxIndex=1;
404 97 if ~isempty(whitepos)
404 98 MinIndex=whitepos(1);
404 99 MaxIndex=whitepos(end);
404 100 end
101
404 102 if (MinIndex >= MaxIndex)
103 threshold = MinIndex;
104 warning('There is <= 1 nonzero pixel intensity');
105 return;
106 end;
107
404 108 MovingIndex = MinIndex+1;
109
404 110 Prev = MinIndex;
404 111 while (Prev ~= MovingIndex)
0.06 5286 112 if (MovingIndex >= MaxIndex)
113 break;
114 end;
115
0.90 5286 116 sum1 = sum([MinIndex:MovingIndex-1]' .* ...
117 histo(MinIndex:MovingIndex-1)) ;
0.41 5286 118 sum2 = sum(histo(MinIndex:MovingIndex-1)) ;
2.48 5286 119 sum3 = sum([MovingIndex:MaxIndex]' .* ...
120 histo(MovingIndex:MaxIndex)) ;
1.06 5286 121 sum4 = sum(histo(MovingIndex:MaxIndex)) ;
122
0.02 5286 123 Prev = MovingIndex;
5286 124 loweravg=sum1/sum2;
0.02 5286 125 higheravg=sum3/sum4;
126
0.04 5286 127 MovingIndex = ceil((loweravg + higheravg)/2) ;
0.02 5286 128 end
129
404 130 threshold = MovingIndex;
131
404 132 if converted
404 133 threshold = (threshold/bins * imgDiff) + imgMin;
404 134 end