This is a static copy of a profile reportHome
filter2 (2 calls, 0.022 sec)
Generated 05-Aug-2011 13:03:16 using cpu time.
function in file /usr/local/MATLAB/R2011a/toolbox/matlab/datafun/filter2.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 |
41 | stencil = rot90(b,2); | 2 | 0.011 s | 50.0% |  |
33 | if (~isa(x,'float')), x = dou... | 2 | 0.011 s | 50.0% |  |
80 | end | 2 | 0 s | 0% |  |
79 | end | 1 | 0 s | 0% |  |
71 | y = round(conv2(hcol, hrow, x,... | 1 | 0 s | 0% |  |
All other lines | | | 0 s | 0% |  |
Totals | | | 0.022 s | 100% | |
Children (called functions)
Function Name | Function Type | Calls | Total Time | % Time | Time Plot |
rot90 | function | 2 | 0 s | 0% |  |
Self time (built-ins, overhead, etc.) | | | 0.022 s | 100.0% |  |
Totals | | | 0.022 s | 100% | |
Code Analyzer results
No Code Analyzer messages.Coverage results
[ Show coverage for parent directory ]
Total lines in function | 80 |
Non-code lines (comments, blank lines) | 40 |
Code lines (lines that can run) | 40 |
Code lines that did run | 30 |
Code lines that did not run | 10 |
Coverage (did run/can run) | 75.00 % |
Function listing
time calls line
1 function y = filter2(b,x,shape)
2 %FILTER2 Two-dimensional digital filter.
3 % Y = FILTER2(B,X) filters the data in X with the 2-D FIR
4 % filter in the matrix B. The result, Y, is computed
5 % using 2-D correlation and is the same size as X.
6 %
7 % Y = FILTER2(B,X,'shape') returns Y computed via 2-D
8 % correlation with size specified by 'shape':
9 % 'same' - (default) returns the central part of the
10 % correlation that is the same size as X.
11 % 'valid' - returns only those parts of the correlation
12 % that are computed without the zero-padded
13 % edges, size(Y) < size(X).
14 % 'full' - returns the full 2-D correlation,
15 % size(Y) > size(X).
16 %
17 % FILTER2 uses CONV2 to do most of the work. 2-D correlation
18 % is related to 2-D convolution by a 180 degree rotation of the
19 % filter matrix.
20 %
21 % Class support for inputs B,X:
22 % float: double, single
23 %
24 % See also FILTER, CONV2.
25
26 % Copyright 1984-2006 The MathWorks, Inc.
27 % $Revision: 5.13.4.5 $ $Date: 2010/09/02 13:35:21 $
28
2 29 error(nargchk(2,3,nargin,'struct'));
2 30 if nargin<3, shape = 'same'; end
31
2 32 if (~isa(b,'float')), b = double(b); end
0.01 2 33 if (~isa(x,'float')), x = double(x); end
34
2 35 code = [shape,' ']; code = code(1);
2 36 if isempty(find(code=='svf', 1))
37 error(message('MATLAB:filter2:InvalidParam'));
38 end
39
2 40 [mx,nx] = size(x);
0.01 2 41 stencil = rot90(b,2);
2 42 [ms,ns] = size(stencil);
43
44 % 1-D stencil?
2 45 if (ms == 1)
46 y = conv2(1,stencil,x,shape);
2 47 elseif (ns == 1)
48 y = conv2(stencil,1,x,shape);
2 49 else
2 50 if (ms*ns > mx*nx)
51 % The filter is bigger than the input. This is a nontypical
52 % case, and it may be counterproductive to check the
53 % separability of the stencil.
1 54 y = conv2(x,stencil,shape);
1 55 else
1 56 separable = false;
1 57 if all(isfinite(stencil(:)))
58 % Check rank (separability) of stencil
1 59 [u,s,v] = svd(stencil);
1 60 s = diag(s);
1 61 tol = length(stencil) * eps(max(s));
1 62 rank = sum(s > tol);
1 63 separable = (rank ==1);
1 64 end
1 65 if separable
66 % Separable stencil
1 67 hcol = u(:,1) * sqrt(s(1));
1 68 hrow = conj(v(:,1)) * sqrt(s(1));
1 69 if (all(all((round(stencil) == stencil))) && all(all((round(x) == x))))
70 % Output should be integer
1 71 y = round(conv2(hcol, hrow, x, shape));
72 else
73 y = conv2(hcol, hrow, x, shape);
74 end
75 else
76 % Nonseparable stencil
77 y = conv2(x,stencil,shape);
78 end
1 79 end
2 80 end