This is a static copy of a profile reportHome
imclearborder (1721 calls, 6.068 sec)
Generated 05-Nov-2014 07:52:50 using cpu time.
function in file /usr1/opt/matlab/7.13/toolbox/images/images/imclearborder.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 |
86 | im2 = imerode(im2,conn); | 1721 | 3.265 s | 53.8% |  |
85 | im2 = padarray(im2, ones(1,ndi... | 1721 | 1.412 s | 23.3% |  |
101 | im2 = imreconstruct(marker, im... | 1721 | 0.691 s | 11.4% |  |
77 | [im,conn] = parse_inputs(varar... | 1721 | 0.310 s | 5.1% |  |
91 | im2 = im2(idx{:}); | 1721 | 0.070 s | 1.2% |  |
All other lines | | | 0.320 s | 5.3% |  |
Totals | | | 6.068 s | 100% | |
Children (called functions)
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 106 |
Non-code lines (comments, blank lines) | 84 |
Code lines (lines that can run) | 22 |
Code lines that did run | 16 |
Code lines that did not run | 6 |
Coverage (did run/can run) | 72.73 % |
Function listing
time calls line
1 function im2 = imclearborder(varargin)
2 %IMCLEARBORDER Suppress light structures connected to image border.
3 % IM2 = IMCLEARBORDER(IM) suppresses structures that are lighter than
4 % their surroundings and that are connected to the image border. IM can
5 % be an intensity or binary image. The output image, IM2, is intensity or
6 % binary, respectively. The default connectivity is 8 for two dimensions,
7 % 26 for three dimensions, and CONNDEF(NDIMS(BW),'maximal') for higher
8 % dimensions.
9 %
10 % For intensity images, IMCLEARBORDER tends to reduce the overall
11 % intensity level in addition to suppressing border structures.
12 %
13 % IM2 = IMCLEARBORDER(IM,CONN) specifies the desired connectivity.
14 % CONN may have the following scalar values:
15 %
16 % 4 two-dimensional four-connected neighborhood
17 % 8 two-dimensional eight-connected neighborhood
18 % 6 three-dimensional six-connected neighborhood
19 % 18 three-dimensional 18-connected neighborhood
20 % 26 three-dimensional 26-connected neighborhood
21 %
22 % Connectivity may be defined in a more general way for any dimension by
23 % using for CONN a 3-by-3-by- ... -by-3 matrix of 0s and 1s. The 1-valued
24 % elements define neighborhood locations relative to the center element of
25 % CONN. CONN must be symmetric about its center element.
26 %
27 % Note
28 % ----
29 % A pixel on the edge of the input image might not be considered to be
30 % a "border" pixel if a nondefault connectivity is specified. For
31 % example, if CONN = [0 0 0; 1 1 1; 0 0 0], elements on the first and
32 % last row are not considered to be border pixels because, according to
33 % that connectivity definition, they are not connected to the region
34 % outside of the image.
35 %
36 % Class support
37 % -------------
38 % IM can be a numeric or logical array of any dimension, and it must be
39 % nonsparse and real. IM2 has the same class as IM.
40 %
41 % Examples
42 % --------
43 % This example shows how to clear the border of an intensity image:
44 %
45 % I = imread('rice.png');
46 % I2 = imclearborder(I);
47 % imshow(I), figure, imshow(I2)
48 %
49 % This example shows how to clear the border of a binary image:
50 %
51 % BW = im2bw(imread('rice.png'));
52 % BW2 = imclearborder(BW);
53 % imshow(BW), figure, imshow(BW2)
54 %
55 % See also IMRECONSTRUCT.
56
57 % Copyright 1993-2005 The MathWorks, Inc.
58 % $Revision: 1.10.4.5 $ $Date: 2006/03/13 19:43:55 $
59
60 % Algorithm reference: P. Soille, Morphological Image Analysis:
61 % Principles and Applications, Springer, 1999, pp. 164-165.
62
63 % Input-output specs
64 % ------------------
65 % IM: N-D, real, full matrix
66 % any numeric or logical nonsparse type
67 % if islogical(IM), treated as binary
68 % empty ok
69 % Infs ok
70 % if logical, NaNs are ok and treated as 0s, otherwise
71 % not allowed.
72 %
73 % CONN: connectivity
74 %
75 % IM2: Same class and size as IM
76
0.31 1721 77 [im,conn] = parse_inputs(varargin{:});
0.05 1721 78 conn = conn2array(conn);
79
1721 80 marker = im;
81
82 % Now figure out which elements of the marker image are connected to the
83 % outside, according to the connectivity definition.
0.02 1721 84 im2 = true(size(marker));
1.41 1721 85 im2 = padarray(im2, ones(1,ndims(im2)), 0, 'both');
3.26 1721 86 im2 = imerode(im2,conn);
0.03 1721 87 idx = cell(1,ndims(im2));
0.03 1721 88 for k = 1:ndims(im2)
0.02 3442 89 idx{k} = 2:(size(im2,k) - 1);
0.04 3442 90 end
0.07 1721 91 im2 = im2(idx{:});
92
93 % Set all elements of the marker image that are not connected to the
94 % outside to the lowest possible value.
1721 95 if islogical(marker)
0.05 1721 96 marker(im2) = false;
97 else
98 marker(im2) = -Inf;
99 end
100
0.69 1721 101 im2 = imreconstruct(marker, im, conn);
0.01 1721 102 if islogical(im2)
0.03 1721 103 im2 = im & ~im2;
104 else
105 im2 = imsubtract(im,im2);
106 end
Other subfunctions in this file are not included in this listing.