This is a static copy of a profile report

Home

bwboundaries (1721 calls, 8.201 sec)
Generated 05-Nov-2014 07:53:16 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/bwboundaries.m
Copy to new window for comparing multiple runs

Parents (calling functions)

Function NameFunction TypeCalls
tp_surfmapfunction1721
Lines where the most time was spent

Line NumberCodeCallsTotal Time% TimeTime Plot
134
[holes, LabeledHoles] = FindHo...
17216.900 s84.1%
131
[objs , L] = FindObjectBoundar...
17210.741 s9.0%
129
[BW, conn, findholes] = parseI...
17210.401 s4.9%
136
L = L + (LabeledHoles~=0)*leng...
17210.100 s1.2%
142
B = [objs; holes];
17210.020 s0.2%
All other lines  0.040 s0.5%
Totals  8.201 s100% 
Children (called functions)

Function NameFunction TypeCallsTotal Time% TimeTime Plot
bwboundaries>FindHoleBoundariessubfunction17216.890 s84.0%
bwboundaries>FindObjectBoundariessubfunction17210.741 s9.0%
bwboundaries>parseInputssubfunction17210.381 s4.6%
Self time (built-ins, overhead, etc.)  0.190 s2.3%
Totals  8.201 s100% 
Code Analyzer results
No Code Analyzer messages.
Coverage results
[ Show coverage for parent directory ]
Total lines in function150
Non-code lines (comments, blank lines)137
Code lines (lines that can run)13
Code lines that did run8
Code lines that did not run5
Coverage (did run/can run)61.54 %
Function listing
   time   calls  line
1 function [B,L,N,A] = bwboundaries(varargin)
2 %BWBOUNDARIES Trace region boundaries in binary image.
3 % B = BWBOUNDARIES(BW) traces the exterior boundary of objects, as well
4 % as boundaries of holes inside these objects. It also descends into the
5 % outermost objects (parents) and traces their children (objects
6 % completely enclosed by the parents). BW must be a binary image where
7 % nonzero pixels belong to an object and 0-pixels constitute the
8 % background. B is a P-by-1 cell array, where P is the number of objects
9 % and holes. Each cell contains a Q-by-2 matrix, where Q is the number of
10 % boundary pixels for the corresponding region. Each row of these Q-by-2
11 % matrices contains the row and column coordinates of a boundary pixel.
12 % The coordinates are ordered in a clockwise direction.
13 %
14 % B = BWBOUNDARIES(BW,CONN) specifies the connectivity to use when
15 % tracing parent and child boundaries. CONN may be either 8 or 4. The
16 % default value for CONN is 8.
17 %
18 % B = BWBOUNDARIES(...,OPTIONS) provides an optional string input. String
19 % 'noholes' speeds up the operation of the algorithm by having it search
20 % only for object (parent and child) boundaries. By default, or when
21 % 'holes' string is specified, the algorithm searches for both object and
22 % hole boundaries.
23 %
24 % [B,L] = BWBOUNDARIES(...) returns the label matrix, L, as the second
25 % output argument. Objects and holes are labeled. L is a two-dimensional
26 % array of nonnegative integers that represent contiguous regions. The
27 % k-th region includes all elements in L that have value k. The number of
28 % objects and holes represented by L is equal to max(L(:)). The
29 % zero-valued elements of L make up the background.
30 %
31 % [B,L,N,A] = BWBOUNDARIES(...) returns the number of objects found (N)
32 % and an adjacency matrix A. The first N cells in B are object
33 % boundaries. A represents the parent-child-hole dependencies. A is a
34 % square, sparse, logical matrix with side of length max(L(:)), whose
35 % rows and columns correspond to the position of boundaries stored in B.
36 % The boundaries enclosed by a B{m} as well as the boundary enclosing
37 % B{m} can both be found using A as follows:
38 %
39 % enclosing_boundary = find(A(m,:));
40 % enclosed_boundaries = find(A(:,m));
41 %
42 % Class Support
43 % -------------
44 % BW can be logical or numeric and it must be real, 2-D, and nonsparse.
45 % L, and N are double. A is sparse logical.
46 %
47 % Example 1
48 % ---------
49 % Read in and threshold the rice.png image. Display the labeled
50 % objects using the jet colormap, on a gray background, with region
51 % boundaries outlined in white.
52 %
53 % I = imread('rice.png');
54 % BW = im2bw(I, graythresh(I));
55 % [B,L] = bwboundaries(BW,'noholes');
56 % imshow(label2rgb(L, @jet, [.5 .5 .5]))
57 % hold on
58 % for k = 1:length(B)
59 % boundary = B{k};
60 % plot(boundary(:,2), boundary(:,1), 'w', 'LineWidth', 2)
61 % end
62 %
63 % Example 2
64 % ---------
65 % Read in and display binary image blobs.png. Overlay the region
66 % boundaries on the image. Display text showing the region number
67 % (based on the label matrix), next to every boundary. Additionally,
68 % display the adjacency matrix using SPY.
69 %
70 % HINT: After the image is displayed, use the zoom tool in order to read
71 % individual labels.
72 %
73 % BW = imread('blobs.png');
74 % [B,L,N,A] = bwboundaries(BW);
75 % imshow(BW); hold on;
76 % colors=['b' 'g' 'r' 'c' 'm' 'y'];
77 % for k=1:length(B),
78 % boundary = B{k};
79 % cidx = mod(k,length(colors))+1;
80 % plot(boundary(:,2), boundary(:,1), colors(cidx),'LineWidth',2);
81 % %randomize text position for better visibility
82 % rndRow = ceil(length(boundary)/(mod(rand*k,7)+1));
83 % col = boundary(rndRow,2); row = boundary(rndRow,1);
84 % h = text(col+1, row-1, num2str(L(row,col)));
85 % set(h,'Color',colors(cidx),'FontSize',14,'FontWeight','bold');
86 % end
87 % figure; spy(A);
88 %
89 % Example 3
90 % ---------
91 % Display object boundaries in red and hole boundaries in green.
92 %
93 % BW = imread('blobs.png');
94 % [B,L,N] = bwboundaries(BW);
95 % imshow(BW); hold on;
96 % for k=1:length(B),
97 % boundary = B{k};
98 % if(k > N)
99 % plot(boundary(:,2), boundary(:,1), 'g','LineWidth',2);
100 % else
101 % plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);
102 % end
103 % end
104 %
105 % Example 4
106 % ---------
107 % Display parent boundaries in red (any empty row of adjacency
108 % matrix belongs to a parent) and their holes in green.
109 %
110 % BW = imread('blobs.png');
111 % [B,L,N,A] = bwboundaries(BW);
112 % imshow(BW); hold on;
113 % for k=1:length(B),
114 % if(~sum(A(k,:)))
115 % boundary = B{k};
116 % plot(boundary(:,2), boundary(:,1), 'r','LineWidth',2);
117 % for l=find(A(:,k))'
118 % boundary = B{l};
119 % plot(boundary(:,2), boundary(:,1), 'g','LineWidth',2);
120 % end
121 % end
122 % end
123 %
124 % See also BWLABEL, BWLABELN, BWPERIM, BWTRACEBOUNDARY.
125
126 % Copyright 1993-2010 The MathWorks, Inc.
127 % $Revision: 1.1.6.11.2.1 $ $Date: 2011/07/18 00:32:42 $
128
0.40 1721 129 [BW, conn, findholes] = parseInputs(varargin{:});
130
0.74 1721 131 [objs , L] = FindObjectBoundaries(BW, conn);
132
1721 133 if (findholes)
6.90 1721 134 [holes, LabeledHoles] = FindHoleBoundaries(BW, conn);
135 % Generate combined holes+objects label matrix
0.10 1721 136 L = L + (LabeledHoles~=0)*length(objs) + LabeledHoles;
137 else
138 holes = {};
139 end
140
141 % Create the output matrix
0.02 1721 142 B = [objs; holes];
143
144 % Return number of object boundaries
0.01 1721 145 N = length(objs);
146
1721 147 if(nargout > 3)
148 % Produce an adjacency matrix showing parent-hole-child relationships
149 A = CreateAdjMatrix(B, N);
150 end

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