This is a static copy of a profile reportHome
bwperim (18173 calls, 29.301 sec)
Generated 05-Nov-2014 07:52:46 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/bwperim.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 |
67 | p = bwmorph(b,'perim4'); | 12115 | 16.543 s | 56.5% |  |
70 | p = bwmorph(b,'perim8'); | 6058 | 6.359 s | 21.7% |  |
59 | iptcheckconn(conn,mfilename,'C... | 18173 | 1.522 s | 5.2% |  |
46 | b = b ~= 0; | 18173 | 1.472 s | 5.0% |  |
62 | conn = ScalarToArray(conn); | 18173 | 0.781 s | 2.7% |  |
All other lines | | | 2.624 s | 9.0% |  |
Totals | | | 29.301 s | 100% | |
Children (called functions)
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 90 |
Non-code lines (comments, blank lines) | 53 |
Code lines (lines that can run) | 37 |
Code lines that did run | 22 |
Code lines that did not run | 15 |
Coverage (did run/can run) | 59.46 % |
Function listing
time calls line
1 function pout = bwperim(varargin)
2 %BWPERIM Find perimeter of objects in binary image.
3 % BW2 = BWPERIM(BW1) returns a binary image containing only the perimeter
4 % pixels of objects in the input image BW1. A pixel is part of the
5 % perimeter if it nonzero and it is connected to at least one zero-valued
6 % pixel. The default connectivity is 4 for two dimensions, 6 for three
7 % dimensions, and CONNDEF(NDIMS(BW),'minimal') for higher dimensions.
8 %
9 % BW2 = BWPERIM(BW1,CONN) specifies the desired connectivity. CONN may
10 % have the following scalar values:
11 %
12 % 4 two-dimensional four-connected neighborhood
13 % 8 two-dimensional eight-connected neighborhood
14 % 6 three-dimensional six-connected neighborhood
15 % 18 three-dimensional 18-connected neighborhood
16 % 26 three-dimensional 26-connected neighborhood
17 %
18 % Connectivity may be defined in a more general way for any dimension by
19 % using for CONN a 3-by-3-by- ... -by-3 matrix of 0s and 1s. The 1-valued
20 % elements define neighborhood locations relative to the center element of
21 % CONN. CONN must be symmetric about its center element.
22 %
23 % Class Support
24 % -------------
25 % BW1 must be logical or numeric, and it must be nonsparse. BW2 is
26 % logical.
27 %
28 % Example
29 % -------
30 % BW1 = imread('circbw.tif');
31 % BW2 = bwperim(BW1,8);
32 % figure, imshow(BW1)
33 % figure, imshow(BW2)
34 %
35 % See also BWAREA, BWBOUNDARIES, BWEULER, BWTRACEBOUNDARY, CONNDEF, IMFILL.
36
37 % Copyright 1992-2010 The MathWorks, Inc.
38 % $Revision: 5.20.4.12.2.1 $ $Date: 2011/07/18 00:32:50 $
39
0.48 18173 40 iptchecknargin(1,2,nargin,mfilename);
0.10 18173 41 b = varargin{1};
42
0.60 18173 43 iptcheckinput(b, {'logical' 'numeric'}, {'nonsparse'}, ...
44 mfilename, 'BW', 1);
0.21 18173 45 if ~islogical(b)
1.47 18173 46 b = b ~= 0;
0.11 18173 47 end
48
0.04 18173 49 num_dims = ndims(b);
50
0.05 18173 51 if nargout == 0 && num_dims > 2
52 error(message('images:bwperim:invalidSyntax'))
53 end
54
0.04 18173 55 if nargin < 2
56 conn = conndef(num_dims,'minimal');
0.06 18173 57 else
0.10 18173 58 conn = varargin{2};
1.52 18173 59 iptcheckconn(conn,mfilename,'CONN',2);
0.06 18173 60 end
61
0.78 18173 62 conn = ScalarToArray(conn);
63
64 % If it's a 2-D problem with 4- or 8-connectivity, use
65 % bwmorph --- it works without padding the input.
0.20 18173 66 if (num_dims == 2) && isequal(conn, [0 1 0; 1 1 1; 0 1 0])
16.54 12115 67 p = bwmorph(b,'perim4');
68
0.05 6058 69 elseif (num_dims == 2) && isequal(conn, ones(3,3))
6.36 6058 70 p = bwmorph(b,'perim8');
71
72 else
73 % Use a general technique that works for any dimensionality
74 % and any connectivity.
75 num_dims = max(num_dims, ndims(conn));
76 b = padarray(b,ones(1,num_dims),0,'both');
77 b_eroded = imerode(b,conn);
78 p = b & ~b_eroded;
79 idx = cell(1,num_dims);
80 for k = 1 : num_dims
81 idx{k} = 2:(size(p,k) - 1);
82 end
83 p = p(idx{:});
84 end
85
0.04 18173 86 if nargout == 0
87 imshow(p)
0.03 18173 88 else
0.11 18173 89 pout = p;
0.09 18173 90 end
Other subfunctions in this file are not included in this listing.