1## Copyright (C) 2000 Teemu Ikonen <tpikonen@pcu.helsinki.fi>
2##
3## This program is free software; you can redistribute it and/or modify it under
4## the terms of the GNU General Public License as published by the Free Software
5## Foundation; either version 3 of the License, or (at your option) any later
6## version.
7##
8## This program is distributed in the hope that it will be useful, but WITHOUT
9## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11## details.
12##
13## You should have received a copy of the GNU General Public License along with
14## this program; if not, see <http://www.gnu.org/licenses/>.
15
16## -*- texinfo -*-
17## @deftypefn  {Function File} {} ordfilt2 (@var{A}, @var{nth}, @var{domain})
18## @deftypefnx {Function File} {} ordfilt2 (@var{A}, @var{nth}, @var{domain}, @var{S})
19## @deftypefnx {Function File} {} ordfilt2 (@dots{}, @var{padding})
20## Two dimensional ordered filtering.
21##
22## This function exists only for @sc{matlab} compatibility as is just a wrapper
23## to the @code{ordfiltn} which performs the same function on N dimensions.  See
24## @code{ordfiltn} help text for usage explanation.
25##
26## @seealso{medfilt2, padarray, ordfiltn}
27## @end deftypefn
28
29function A = ordfilt2 (A, nth, domain, varargin)
30
31  if (nargin < 3)
32    print_usage ();
33  elseif (ndims (A) > 2 || ndims (domain) > 2 )
34    error ("ordfilt2: A and DOMAIN are limited to 2 dimensinos. Use `ordfiltn' for more")
35  endif
36  A = ordfiltn (A, nth, domain, varargin{:});
37
38endfunction
39
40%!test
41%! order = 3;
42%! domain = ones (3);
43%! A = zeros (3,3);
44%! B = ones (3,3);
45%! C = [1 1 1; 2 2 2; 3 3 3];
46%! D = C';
47%! E = ones (3,3);
48%! E(2,2) = 2;
49%! F = 3 .* ones (3,3);
50%! F(2,2) = 1;
51%! G = [-1 2 7; -5 2 8; -7 pi 9];
52%! H = [5 2 8; 1 -3 1; 5 1 0];
53%! A_out = [0 0 0; 0 0 0; 0 0 0];
54%! B_out = [0 0 0; 0 1 0; 0 0 0];
55%! C_out = [0 0 0; 0 1 0; 0 0 0];
56%! D_out = [0 0 0; 0 1 0; 0 0 0];
57%! E_out = [0 0 0; 0 1 0; 0 0 0];
58%! F_out = [0 0 0; 0 3 0; 0 0 0];
59%! G_out = [0 0 0; -1 -1 0; 0 0 0];
60%! H_out = [0 0 0; 0 1 0; 0 0 0];
61%! assert (ordfilt2 (A, order, domain), A_out);
62%! assert (ordfilt2 (B, order, domain), B_out);
63%! assert (ordfilt2 (C, order, domain), C_out);
64%! assert (ordfilt2 (D, order, domain), D_out);
65%! assert (ordfilt2 (E, order, domain), E_out);
66%! assert (ordfilt2 (F, order, domain), F_out);
67%! assert (ordfilt2 (G, order, domain), G_out);
68%! assert (ordfilt2 (H, order, domain), H_out);
69