This is a static copy of a profile reportHome
imfill (12118 calls, 140.474 sec)
Generated 05-Nov-2014 07:52:50 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/imfill.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 |
143 | I2 = imreconstruct(marker, mas... | 12118 | 110.313 s | 78.5% |  |
124 | [I,locations,conn,do_fillholes... | 12118 | 12.227 s | 8.7% |  |
132 | mask = padarray(mask, ones(1,n... | 12118 | 10.565 s | 7.5% |  |
144 | I2 = imcomplement(I2); | 12118 | 1.482 s | 1.1% |  |
141 | mask = imcomplement(mask); | 12118 | 1.302 s | 0.9% |  |
All other lines | | | 4.586 s | 3.3% |  |
Totals | | | 140.474 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
imreconstruct | function | 12118 | 110.112 s | 78.4% |  |
imfill>parse_inputs | subfunction | 12118 | 12.027 s | 8.6% |  |
padarray | function | 12118 | 10.334 s | 7.4% |  |
imcomplement | function | 36354 | 3.465 s | 2.5% |  |
Self time (built-ins, overhead, etc.) | | | 4.536 s | 3.2% |  |
Totals | | | 140.474 s | 100% | |
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 158 |
Non-code lines (comments, blank lines) | 128 |
Code lines (lines that can run) | 30 |
Code lines that did run | 19 |
Code lines that did not run | 11 |
Coverage (did run/can run) | 63.33 % |
Function listing
time calls line
1 function [I2,locations] = imfill(varargin)
2 %IMFILL Fill image regions and holes.
3 % BW2 = IMFILL(BW1,LOCATIONS) performs a flood-fill operation on
4 % background pixels of the input binary image BW1, starting from the
5 % points specified in LOCATIONS. LOCATIONS can be a P-by-1 vector, in
6 % which case it contains the linear indices of the starting locations.
7 % LOCATIONS can also be a P-by-NDIMS(IM1) matrix, in which case each row
8 % contains the array indices of one of the starting locations.
9 %
10 % BW2 = IMFILL(BW1,'holes') fills holes in the input image. A hole is
11 % a set of background pixels that cannot be reached by filling in the
12 % background from the edge of the image.
13 %
14 % I2 = IMFILL(I1) fills holes in an intensity image, I1. In this
15 % case a hole is an area of dark pixels surrounded by lighter pixels.
16 %
17 % Interactive use
18 % ---------------
19 % BW2 = IMFILL(BW1) displays BW1 on the screen and lets you select the
20 % starting locations using the mouse. Use normal button clicks to add
21 % points. Press <BACKSPACE> or <DELETE> to remove the previously selected
22 % point. A shift-click, right-click, or double-click selects a final
23 % point and then starts the fill; pressing <RETURN> finishes the selection
24 % without adding a point. Interactive use is supported only for 2-D images.
25 %
26 % The syntax [BW2,LOCATIONS] = IMFILL(BW1) can be used to get the starting
27 % points selected using the mouse. The output LOCATIONS is always in the
28 % form of a vector of linear indices into the input image.
29 %
30 % Specifying connectivity
31 % -----------------------
32 % By default, IMFILL uses 4-connected background neighbors for 2-D
33 % inputs and 6-connected background neighbors for 3-D inputs. For
34 % higher dimensions the default background connectivity is
35 % CONNDEF(NUM_DIMS,'minimal'). You can override the default
36 % connectivity with these syntaxes:
37 %
38 % BW2 = IMFILL(BW1,LOCATIONS,CONN)
39 % BW2 = IMFILL(BW1,CONN,'holes')
40 % I2 = IMFILL(I1,CONN)
41 %
42 % To override the default connectivity and interactively specify the
43 % starting locations, use this syntax:
44 %
45 % BW2 = IMFILL(BW1,0,CONN)
46 %
47 % CONN may have the following scalar values:
48 %
49 % 4 two-dimensional four-connected neighborhood
50 % 8 two-dimensional eight-connected neighborhood
51 % 6 three-dimensional six-connected neighborhood
52 % 18 three-dimensional 18-connected neighborhood
53 % 26 three-dimensional 26-connected neighborhood
54 %
55 % Connectivity may be defined in a more general way for any dimension by
56 % using for CONN a 3-by-3-by- ... -by-3 matrix of 0s and 1s. The 1-valued
57 % elements define neighborhood locations relative to the center element of
58 % CONN. CONN must be symmetric about its center element.
59 %
60 % Class Support
61 % -------------
62 % The input image can be numeric or logical, and it must be real and
63 % nonsparse. It can have any dimension. The output image has the
64 % same class as the input image.
65 %
66 % Examples
67 % --------
68 % Fill in the background of a binary image from a specified starting
69 % location:
70 %
71 % BW1 = logical([1 0 0 0 0 0 0 0
72 % 1 1 1 1 1 0 0 0
73 % 1 0 0 0 1 0 1 0
74 % 1 0 0 0 1 1 1 0
75 % 1 1 1 1 0 1 1 1
76 % 1 0 0 1 1 0 1 0
77 % 1 0 0 0 1 0 1 0
78 % 1 0 0 0 1 1 1 0]);
79 % BW2 = imfill(BW1,[3 3],8)
80 %
81 % Fill in the holes of a binary image:
82 %
83 % BW4 = im2bw(imread('coins.png'));
84 % BW5 = imfill(BW4,'holes');
85 % figure, imshow(BW4), figure, imshow(BW5)
86 %
87 % Fill in the holes of an intensity image:
88 %
89 % I = imread('tire.tif');
90 % I2 = imfill(I,'holes');
91 % figure, imshow(I), figure, imshow(I2)
92 %
93 % See also BWSELECT, IMRECONSTRUCT, ROIFILL.
94
95 % Copyright 1993-2010 The MathWorks, Inc.
96 % $Revision: 1.10.4.12.2.1 $ $Date: 2011/07/18 00:34:03 $
97
98 % Grandfathered syntaxes:
99 % IMFILL(I1,'holes') - no longer necessary to use 'holes'
100 % IMFILL(I1,CONN,'holes') - no longer necessary to use 'holes'
101
102 % Testing notes
103 % =============
104 % I - real, full, nonsparse, numeric array, any dimension
105 % - Infs OK
106 % - NaNs not allowed
107 %
108 % CONN - valid connectivity specifier
109 %
110 % LOCATIONS - the value 0 is used as a flag to indicate interactive
111 % selection
112 % - can be either a P-by-1 double vector containing
113 % valid linear indices into the input image, or a
114 % P-by-ndims(I) array. In the second case, each row
115 % of LOCATIONS must contain a set of valid array indices
116 % into the input image.
117 % - can be empty.
118 %
119 % 'holes' - match is case-insensitive; partial match allowed.
120 %
121 % If 'holes' argument is not provided, then the input image must be
122 % binary.
123
12.23 12118 124 [I,locations,conn,do_fillholes] = parse_inputs(varargin{:});
125
0.03 12118 126 if do_fillholes
0.08 12118 127 if islogical(I)
128 mask = uint8(I);
0.02 12118 129 else
0.03 12118 130 mask = I;
0.01 12118 131 end
10.56 12118 132 mask = padarray(mask, ones(1,ndims(mask)), -Inf, 'both');
133
0.03 12118 134 marker = mask;
0.16 12118 135 idx = cell(1,ndims(I));
0.12 12118 136 for k = 1:ndims(I)
0.32 24236 137 idx{k} = 2:(size(marker,k) - 1);
0.10 24236 138 end
1.22 12118 139 marker(idx{:}) = Inf;
140
1.30 12118 141 mask = imcomplement(mask);
1.13 12118 142 marker = imcomplement(marker);
110.31 12118 143 I2 = imreconstruct(marker, mask, conn);
1.48 12118 144 I2 = imcomplement(I2);
1.05 12118 145 I2 = I2(idx{:});
146
0.16 12118 147 if islogical(I)
148 I2 = I2 ~= 0;
149 end
150
151 else
152 mask = imcomplement(I);
153 marker = mask;
154 marker(:) = 0;
155 marker(locations) = mask(locations);
156 marker = imreconstruct(marker, mask, conn);
157 I2 = I | marker;
158 end
Other subfunctions in this file are not included in this listing.