Mercurial > hg > octave-image
annotate inst/nlfilter.m @ 886:a0c42a32c6c4
Move conversion between each image type to imcast.
* im2double.m, im2int16.m, im2single.m, im2uint16.m, im2uint8.m: move code
into imcast. Fix several small bugs mainly dealing with indexed and logical
images, small precision for Matlab compatibility, and increased performance.
Expanded documentation. Added new tests.
* imcast.m: implement the conversion between each image type instead of being
a wrapper around functions for each conversion. This reduces code duplication,
and places all very similar (but not equal) code together so that a bug fix in
one can be easily notices that requires application in others. Expand
documetation. Add more tests.
* private/imconversion.m, private/im2float.m: remove no longer necessary
function since this has all been moved to imcast.
* COPYING: remove license for private/im2float.m and private/imconversion.m.
* NEWS: make note of bug fixes for this functions.
author | Carnë Draug <carandraug@octave.org> |
---|---|
date | Mon, 24 Mar 2014 22:00:05 +0000 |
parents | eb027eb95855 |
children |
rev | line source |
---|---|
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
1 ## Copyright (C) 2013 Carnë Draug <carandraug@octave.org> |
186 | 2 ## |
561
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
3 ## This program is free software; you can redistribute it and/or modify it under |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
4 ## the terms of the GNU General Public License as published by the Free Software |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
5 ## Foundation; either version 3 of the License, or (at your option) any later |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
6 ## version. |
186 | 7 ## |
561
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
8 ## This program is distributed in the hope that it will be useful, but WITHOUT |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
11 ## details. |
186 | 12 ## |
561
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
13 ## You should have received a copy of the GNU General Public License along with |
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
14 ## this program; if not, see <http://www.gnu.org/licenses/>. |
186 | 15 |
16 ## -*- texinfo -*- | |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
17 ## @deftypefn {Function File} {} nlfilter (@var{A}, @var{block_size}, @var{func}) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
18 ## @deftypefnx {Function File} {} nlfilter (@var{A}, @var{block_size}, @var{func}, @dots{}) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
19 ## @deftypefnx {Function File} {} nlfilter (@var{A}, "indexed", @dots{}) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
20 ## Process matrix in sliding blocks with user-supplied function. |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
21 ## |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
22 ## Executes the function @var{fun} on each sliding block of |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
23 ## size @var{block_size}, taken from the matrix @var{A}. Both the matrix |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
24 ## @var{A}, and the block can have any number of dimensions. This function |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
25 ## is specially useful to perform sliding/moving window functions such as |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
26 ## moving average. |
186 | 27 ## |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
28 ## The output will have the same dimensions @var{A}, each one of its values |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
29 ## corresponding to the processing of a block centered at the same |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
30 ## coordinates in @var{A}, with @var{A} being padded with zeros for the |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
31 ## borders (see below for indexed images). In case any side of the block |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
32 ## is of even length, the center is considered at indices |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
33 ## @code{floor ([@var{block_size}/2] + 1)}. |
186 | 34 ## |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
35 ## The argument @var{func} must be a function handle that takes matrices of |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
36 ## size @var{block_size} as input and returns a single scalar. Any extra |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
37 ## input arguments to @code{nlfilter} are passed to @var{func} after the |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
38 ## block matrix. |
186 | 39 ## |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
40 ## If @var{A} is an indexed image, the second argument should be the |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
41 ## string @qcode{"indexed"} so that any required padding is done correctly |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
42 ## as done by @code{im2col}. |
186 | 43 ## |
824
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
44 ## @emph{Note}: if @var{func} is a column compression function, i.e., it acts |
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
45 ## along a column to return a single value, consider using @code{colfilt} |
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
46 ## which usually performs faster. If @var{func} makes use of the colon |
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
47 ## operator to select all elements in the block, e.g., if @var{func} looks |
833
eb027eb95855
doc: small fixes for Texinfo syntax
Carnë Draug <carandraug@octave.org>
parents:
826
diff
changeset
|
48 ## anything like @code{@@(x) sum (x(:))}, it is a good indication that |
824
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
49 ## @code{colfilt} should be used. In addition, many sliding block operations |
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
50 ## have their own specific implementations (see help text of @code{colfilt} |
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
51 ## for a list). |
a043a7e1745d
Rewrite colfilt to support N-dimensional images and implement distinct blocks.
Carnë Draug <carandraug@octave.org>
parents:
822
diff
changeset
|
52 ## |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
53 ## @seealso{blockproc, col2im, colfilt, im2col} |
186 | 54 ## @end deftypefn |
55 | |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
56 function B = nlfilter (A, varargin) |
186 | 57 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
58 ## Input check |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
59 [p, block_size, padval] = im2col_check ("nlfilter", nargin, A, varargin{:}); |
186 | 60 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
61 if (nargin < p) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
62 print_usage (); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
63 endif |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
64 func = varargin{p++}; |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
65 if (! isa (func, "function_handle")) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
66 error ("nlfilter: FUNC must be a function handle"); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
67 elseif (! isscalar (func (ones (block_size, class (A)), varargin{p:nargin-1}))) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
68 error ("nlfilter: FUNC must take a matrix of size BLOCK_SIZE and return a scalar"); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
69 endif |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
70 ## Remaining params are parameters to fun. We need to place them into |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
71 ## a separate variable, we can't varargin{p:nargin-1} inside the anonymous |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
72 ## function because nargin will have a different value there |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
73 extra_args = varargin(p:nargin -1); |
186 | 74 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
75 ## Pad image as required |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
76 padded = pad_for_sliding_filter (A, block_size, padval); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
77 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
78 ## Get the blocks (one per column) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
79 blks = im2col (padded, block_size, "sliding"); |
186 | 80 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
81 ## New function that reshapes the array into a block before |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
82 ## passing it to the actual user supplied function |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
83 blk_func = @(x, z) func (reshape (blks(x:z), block_size), extra_args{:}); |
561
c45838839d86
maint: update license to GPLv3 and mention non GPL files
carandraug
parents:
274
diff
changeset
|
84 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
85 ## Perform the filtering |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
86 blk_step = 1:(rows (blks)):(rows (blks) * columns (blks)); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
87 B = arrayfun (blk_func, blk_step, blk_step + rows (blks) -1); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
88 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
89 ## Back into its original shape |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
90 B = reshape (B, size (A)); |
186 | 91 |
92 endfunction | |
93 | |
94 %!demo | |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
95 %! ## creates a "wide" diagonal (although it can be performed more |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
96 %! ## efficiently with "imdilate (A, true (3))") |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
97 %! nlfilter (eye (10), [3 3], @(x) any (x(:) > 0)) |
186 | 98 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
99 %!assert (nlfilter (eye (4), [2 3], @(x) sum (x(:))), |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
100 %! [2 2 1 0 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
101 %! 1 2 2 1 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
102 %! 0 1 2 2 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
103 %! 0 0 1 1]); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
104 %!assert (nlfilter (eye (4), "indexed", [2 3], @(x) sum (x(:))), |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
105 %! [4 2 1 2 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
106 %! 3 2 2 3 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
107 %! 2 1 2 4 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
108 %! 4 3 4 5]); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
109 %!assert (nlfilter (eye (4), "indexed", [2 3], @(x, y) sum (x(:)) == y, 2), |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
110 %! logical ([0 1 0 1 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
111 %! 0 1 1 0 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
112 %! 1 0 1 0 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
113 %! 0 0 0 0])); |
186 | 114 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
115 ## Check uint8 and uint16 padding (only the padding since the class of |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
116 ## the output is dependent on the function and sum() always returns double) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
117 %!assert (nlfilter (uint8 (eye (4)), "indexed", [2 3], @(x) sum (x(:))), |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
118 %! [2 2 1 0 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
119 %! 1 2 2 1 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
120 %! 0 1 2 2 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
121 %! 0 0 1 1]); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
122 %!assert (nlfilter (int16 (eye (4)), "indexed", [2 3], @(x) sum (x(:))), |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
123 %! [4 2 1 2 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
124 %! 3 2 2 3 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
125 %! 2 1 2 4 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
126 %! 4 3 4 5]); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
127 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
128 ## Check if function class is preserved |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
129 %!assert (nlfilter (uint8 (eye (4)), "indexed", [2 3], @(x) int8 (sum (x(:)))), |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
130 %! int8 ([2 2 1 0 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
131 %! 1 2 2 1 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
132 %! 0 1 2 2 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
133 %! 0 0 1 1])); |
186 | 134 |
822
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
135 ## Test N-dimensional |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
136 %!test |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
137 %! a = randi (10, 20, 20, 20); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
138 %! ## extra dimensions on matrix only |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
139 %! assert (nlfilter (a, [5 5], @(x) max(x(:))), imdilate (a, ones (5))) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
140 %! ## extra dimensions on both matrix and block |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
141 %! assert (nlfilter (a, [5 5 5], @(x) max(x(:))), imdilate (a, ones ([5 5 5]))) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
142 %! ## extra dimensions and padding |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
143 %! assert (nlfilter (a, [3 7], @(x) max(x(:))), imdilate (a, ones ([3 7]))) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
144 %! assert (nlfilter (a, [3 7 3], @(x) max(x(:))), imdilate (a, ones ([3 7 3]))) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
145 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
146 %!test |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
147 %! a = randi (10, 15, 15, 4, 8, 3); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
148 %! assert (nlfilter (a, [3 4 7 5], @(x) max(x(:))), |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
149 %! imdilate (a, ones ([3 4 7 5]))) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
150 |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
151 ## Just to make sure it's not a bug in imdilate |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
152 %!test |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
153 %! a = randi (10, 15, 15, 4, 3, 8); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
154 %! ord = ordfiltn (a, 3, ones ([3 7 3 1 5])); |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
155 %! assert (nlfilter (a, [3 7 3 1 5], @(x) sort (x(:))(3)), ord) |
896f5b53db6b
Rewrite nlfilter for support of N-dimensional input.
Carnë Draug <carandraug@octave.org>
parents:
600
diff
changeset
|
156 %! assert (nlfilter (a, [3 7 3 1 5], @(x, y) sort (x(:))(y), 3), ord) |