This is a static copy of a profile reportHome
bwmorph (53371 calls, 89.183 sec)
Generated 05-Nov-2014 07:52:49 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/bwmorph.m
Copy to new window for comparing multiple runs
Parents (calling functions)
Lines where the most time was spent
Line Number | Code | Calls | Total Time | % Time | Time Plot |
168 | [c,lut] = feval(fcn, c); | 53371 | 52.973 s | 59.4% |  |
152 | idx = strmatch(opString, match... | 53371 | 24.744 s | 27.7% |  |
91 | iptcheckinput(a,{'numeric' 'lo... | 53371 | 1.722 s | 1.9% |  |
169 | done = ((iter >= n) | isequ... | 53371 | 1.021 s | 1.1% |  |
162 | fcn = deblank(functionStrings(... | 53371 | 0.981 s | 1.1% |  |
All other lines | | | 7.741 s | 8.7% |  |
Totals | | | 89.183 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
bwmorph>dilate | subfunction | 35198 | 40.887 s | 45.8% |  |
strmatch | function | 53371 | 24.224 s | 27.2% |  |
bwmorph>perim4 | subfunction | 12115 | 8.372 s | 9.4% |  |
bwmorph>perim8 | subfunction | 6058 | 2.373 s | 2.7% |  |
iptcheckinput | MEX-file | 53371 | 0.521 s | 0.6% |  |
Self time (built-ins, overhead, etc.) | | | 12.808 s | 14.4% |  |
Totals | | | 89.183 s | 100% | |
Code Analyzer results
Line number | Message |
152 | STRMATCH will be removed in a future release. Use STRNCMP instead. |
Coverage results
[ Show coverage for parent directory ]
Total lines in function | 202 |
Non-code lines (comments, blank lines) | 151 |
Code lines (lines that can run) | 51 |
Code lines that did run | 28 |
Code lines that did not run | 23 |
Coverage (did run/can run) | 54.90 % |
Function listing
time calls line
1 function [cout,lut] = bwmorph(a,op,n)
2 %BWMORPH Morphological operations on binary image.
3 % BW2 = BWMORPH(BW1,OPERATION) applies a specific
4 % morphological operation to the binary image BW1.
5 %
6 % BW2 = BWMORPH(BW1,OPERATION,N) applies the operation N
7 % times. N can be Inf, in which case the operation is repeated
8 % until the image no longer changes.
9 %
10 % OPERATION is a string that can have one of these values:
11 % 'bothat' Subtract the input image from its closing
12 % 'branchpoints' Find branch points of skeleton
13 % 'bridge' Bridge previously unconnected pixels
14 % 'clean' Remove isolated pixels (1's surrounded by 0's)
15 % 'close' Perform binary closure (dilation followed by
16 % erosion)
17 % 'diag' Diagonal fill to eliminate 8-connectivity of
18 % background
19 % 'dilate' Perform dilation using the structuring element
20 % ones(3)
21 % 'endpoints' Find end points of skeleton
22 % 'erode' Perform erosion using the structuring element
23 % ones(3)
24 % 'fill' Fill isolated interior pixels (0's surrounded by
25 % 1's)
26 % 'hbreak' Remove H-connected pixels
27 % 'majority' Set a pixel to 1 if five or more pixels in its
28 % 3-by-3 neighborhood are 1's
29 % 'open' Perform binary opening (erosion followed by
30 % dilation)
31 % 'remove' Set a pixel to 0 if its 4-connected neighbors
32 % are all 1's, thus leaving only boundary
33 % pixels
34 % 'shrink' With N = Inf, shrink objects to points; shrink
35 % objects with holes to connected rings
36 % 'skel' With N = Inf, remove pixels on the boundaries
37 % of objects without allowing objects to break
38 % apart
39 % 'spur' Remove end points of lines without removing
40 % small objects completely
41 % 'thicken' With N = Inf, thicken objects by adding pixels
42 % to the exterior of objects without connected
43 % previously unconnected objects
44 % 'thin' With N = Inf, remove pixels so that an object
45 % without holes shrinks to a minimally
46 % connected stroke, and an object with holes
47 % shrinks to a ring halfway between the hole
48 % and outer boundary
49 % 'tophat' Subtract the opening from the input image
50 %
51 % Class Support
52 % -------------
53 % The input image BW1 can be numeric or logical.
54 % It must be 2-D, real and nonsparse. The output image
55 % BW2 is logical.
56 %
57 % Examples
58 % --------
59 % BW1 = imread('circles.png');
60 % figure, imshow(BW1)
61 % BW2 = bwmorph(BW1,'remove');
62 % BW3 = bwmorph(BW1,'skel',Inf);
63 % figure, imshow(BW2)
64 % figure, imshow(BW3)
65 %
66 % See also ERODE, DILATE, BWEULER, BWPERIM.
67
68 % Copyright 1993-2010 The MathWorks, Inc.
69 % $Revision: 5.28.4.15.2.1 $ $Date: 2011/07/18 00:32:49 $
70
71 % The second output argument, LUT, is intentionally undocumented. In the
72 % initial release of the Image Processing Toolbox, all the operations
73 % supported by bwmorph used a single look-up table, which was returned as
74 % the second output argument. In subsequent releases, however, bug fixes
75 % and enhancements resulted in some operations no longer using a single
76 % look-up table. As a result, the second output argument no longer served
77 % the purpose envisioned in the original design of the bwmorph syntax. To
78 % reduce compatibility problems, the second output argument was retained
79 % in the code, but it has been removed from the documentation. For
80 % operations which do not use a single look-up table, the second output
81 % argument is returned as [].
82
83 %
84 % Input argument parsing
85 %
0.64 53371 86 error(nargchk(2,3,nargin,'struct'));
0.16 53371 87 if (nargin < 3)
0.04 18173 88 n = 1;
0.07 18173 89 end
90
1.72 53371 91 iptcheckinput(a,{'numeric' 'logical'},{'real' 'nonsparse' '2d'}, ...
92 mfilename, 'BW', 1);
0.52 53371 93 if ~islogical(a)
94 a = a ~= 0;
95 end
96
0.50 53371 97 if ischar(op),
98 % BWMORPH(A, 'op', n)
99
100 %
101 % Find out what operation has been requested
102 %
0.36 53371 103 opString = lower(op);
0.24 53371 104 matchStrings = [ ...
105 'bothat '
106 'branchpoints'
107 'bridge '
108 'clean '
109 'close '
110 'diag '
111 'dilate '
112 'endpoints '
113 'erode '
114 'fatten '
115 'fill '
116 'hbreak '
117 'majority '
118 'perim4 '
119 'perim8 '
120 'open '
121 'remove '
122 'shrink '
123 'skeleton '
124 'spur '
125 'thicken '
126 'thin '
127 'tophat '];
0.16 53371 128 functionStrings = [
129 'bothat '
130 'branchpoints'
131 'bridge '
132 'clean '
133 'close '
134 'diag_ '
135 'dilate '
136 'endpoints '
137 'erode '
138 'fatten '
139 'fill_ '
140 'hbreak '
141 'majority '
142 'perim4 '
143 'perim8 '
144 'open '
145 'remove '
146 'shrink '
147 'skel '
148 'spur '
149 'thicken '
150 'thin '
151 'tophat '];
24.74 53371 152 idx = strmatch(opString, matchStrings);
0.31 53371 153 if (isempty(idx))
154 error(message('images:bwmorph:unknownOperation', opString))
0.38 53371 155 elseif (length(idx) > 1)
156 error(message('images:bwmorph:ambiguousMatch', opString))
157 end
158
159 %
160 % Call the appropriate subfunction
161 %
0.98 53371 162 fcn = deblank(functionStrings(idx,:));
0.20 53371 163 c = a;
0.16 53371 164 iter = 1;
0.27 53371 165 done = n == 0;
0.53 53371 166 while (~done)
0.24 53371 167 lastc = c;
52.97 53371 168 [c,lut] = feval(fcn, c);
1.02 53371 169 done = ((iter >= n) | isequal(lastc, c));
0.30 53371 170 iter = iter + 1;
0.75 53371 171 end
172
173 else
174 % BWMORPH(A, lut, n)
175
176 %
177 % Pass on the call to applylut
178 %
179 lut = op;
180 if (isempty(lut))
181 error(message('images:bwmorph:emptyLUT'));
182 end
183 c = a;
184 done = n == 0;
185 iter = 1;
186 while (~done)
187 lastc = c;
188 c = applylut(c, lut);
189 done = ((iter >= n) | isequal(lastc, c));
190 iter = iter + 1;
191 end
192
193 end
194
0.16 53371 195 if (nargout == 0)
196 imshow(c);
0.25 53371 197 else
0.15 53371 198 cout = c;
0.15 53371 199 end
0.22 53371 200 if ((nargout == 2) && isempty(lut))
201 warning(message('images:bwmorph:lutOutput', deblank( matchStrings( idx, : ) )));
202 end
Other subfunctions in this file are not included in this listing.