comparison inst/nlfilter.m @ 561:c45838839d86

maint: update license to GPLv3 and mention non GPL files
author carandraug
date Mon, 16 Apr 2012 12:49:47 +0000
parents 3da7ef6dd4ee
children 81388819d69a
comparison
equal deleted inserted replaced
560:1d04ebf01532 561:c45838839d86
1 ## Copyright (C) 2004 Josep Mones i Teixidor 1 ## Copyright (C) 2004 Josep Mones i Teixidor <jmones@puntbarra.com>
2 ## 2 ##
3 ## This program is free software; you can redistribute it and/or modify 3 ## This program is free software; you can redistribute it and/or modify it under
4 ## it under the terms of the GNU General Public License as published by 4 ## the terms of the GNU General Public License as published by the Free Software
5 ## the Free Software Foundation; either version 2 of the License, or 5 ## Foundation; either version 3 of the License, or (at your option) any later
6 ## (at your option) any later version. 6 ## version.
7 ## 7 ##
8 ## This program is distributed in the hope that it will be useful, 8 ## This program is distributed in the hope that it will be useful, but WITHOUT
9 ## but WITHOUT ANY WARRANTY; without even the implied warranty of 9 ## ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
10 ## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 10 ## FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
11 ## GNU General Public License for more details. 11 ## details.
12 ## 12 ##
13 ## You should have received a copy of the GNU General Public License 13 ## You should have received a copy of the GNU General Public License along with
14 ## along with this program; If not, see <http://www.gnu.org/licenses/>. 14 ## this program; if not, see <http://www.gnu.org/licenses/>.
15 15
16 ## -*- texinfo -*- 16 ## -*- texinfo -*-
17 ## @deftypefn {Function File} {@var{B} = } nlfilter (@var{A}, [@var{m},@var{n}], @var{fun}) 17 ## @deftypefn {Function File} {@var{B} = } nlfilter (@var{A}, [@var{m},@var{n}], @var{fun})
18 ## @deftypefnx {Function File} {@var{B} = } nlfilter (@var{A}, [@var{m},@var{n}], @var{fun}, ...) 18 ## @deftypefnx {Function File} {@var{B} = } nlfilter (@var{A}, [@var{m},@var{n}], @var{fun}, @dots{})
19 ## @deftypefnx {Function File} {@var{B} = } nlfilter (@var{A},'indexed', ...) 19 ## @deftypefnx {Function File} {@var{B} = } nlfilter (@var{A},'indexed', @dots{})
20 ## Processes image in sliding blocks using user-supplied function. 20 ## Processes image in sliding blocks using user-supplied function.
21 ## 21 ##
22 ## @code{B=nlfilter(A,[m,n],fun)} passes sliding @var{m}-by-@var{n} 22 ## @code{B=nlfilter(A,[m,n],fun)} passes sliding @var{m}-by-@var{n}
23 ## blocks to user-supplied function @var{fun}. A block is build for 23 ## blocks to user-supplied function @var{fun}. A block is build for
24 ## every pixel in @var{A}, such as it is centered within the block. 24 ## every pixel in @var{A}, such as it is centered within the block.
26 ## @var{B}. @var{nlfilter} pads the @var{m}-by-@var{n} block at the 26 ## @var{B}. @var{nlfilter} pads the @var{m}-by-@var{n} block at the
27 ## edges if necessary. 27 ## edges if necessary.
28 ## 28 ##
29 ## Center of block is taken at ceil([@var{m},@var{n}]/2). 29 ## Center of block is taken at ceil([@var{m},@var{n}]/2).
30 ## 30 ##
31 ## @code{B=nlfilter(A,[m,n],fun,...)} behaves as described above but 31 ## @code{B=nlfilter(A,[m,n],fun, @dots{})} behaves as described above but
32 ## passes extra parameters to function @var{fun}. 32 ## passes extra parameters to function @var{fun}.
33 ## 33 ##
34 ## @code{B=nlfilter(A,'indexed',...)} assumes that @var{A} is an indexed 34 ## @code{B=nlfilter(A,'indexed', @dots{})} assumes that @var{A} is an indexed
35 ## image, so it pads the image using proper value: 0 for uint8 and 35 ## image, so it pads the image using proper value: 0 for uint8 and
36 ## uint16 images and 1 for double images. Keep in mind that if 'indexed' 36 ## uint16 images and 1 for double images. Keep in mind that if 'indexed'
37 ## is not specified padding is always done using 0. 37 ## is not specified padding is always done using 0.
38 ## 38 ##
39 ## @seealso{colfilt,blkproc,inline} 39 ## @seealso{colfilt,blkproc,inline}
40 ## @end deftypefn 40 ## @end deftypefn
41
42 ## Author: Josep Mones i Teixidor <jmones@puntbarra.com>
43 41
44 function B = nlfilter(A, varargin) 42 function B = nlfilter(A, varargin)
45 if(nargin<3) 43 if(nargin<3)
46 error("nlfilter: invalid number of parameters."); 44 error("nlfilter: invalid number of parameters.");
47 endif 45 endif
51 p=1; 49 p=1;
52 if(ischar(varargin{1}) && strcmp(varargin{1}, "indexed")) 50 if(ischar(varargin{1}) && strcmp(varargin{1}, "indexed"))
53 indexed=true; 51 indexed=true;
54 p+=1; 52 p+=1;
55 if(isa(A,"uint8") || isa(A,"uint16")) 53 if(isa(A,"uint8") || isa(A,"uint16"))
56 padval=0; 54 padval=0;
57 else 55 else
58 padval=1; 56 padval=1;
59 endif 57 endif
60 else 58 else
61 padval=0; 59 padval=0;
111 endif 109 endif
112 110
113 ## calc end offsets 111 ## calc end offsets
114 me=postpad(1)+prepad(1); 112 me=postpad(1)+prepad(1);
115 ne=postpad(2)+prepad(2); 113 ne=postpad(2)+prepad(2);
116 114
117 ## We concatenate everything to preserve fun return type 115 ## We concatenate everything to preserve fun return type
118 for i=1:as(1) 116 for i=1:as(1)
119 r=feval(fun,A(i:i+me,1:1+ne),varargin{p+1:nargin-1}); 117 r=feval(fun,A(i:i+me,1:1+ne),varargin{p+1:nargin-1});
120 for j=2:as(2) 118 for j=2:as(2)
121 r=horzcat(r,feval(fun,A(i:i+me,j:j+ne),varargin{p+1:nargin-1})); 119 r=horzcat(r,feval(fun,A(i:i+me,j:j+ne),varargin{p+1:nargin-1}));
141 %!assert(nlfilter(uint8(eye(4)),'indexed',[2,3],inline("sum(x(:))","x")),[2,2,1,0;1,2,2,1;0,1,2,2;0,0,1,1]); 139 %!assert(nlfilter(uint8(eye(4)),'indexed',[2,3],inline("sum(x(:))","x")),[2,2,1,0;1,2,2,1;0,1,2,2;0,0,1,1]);
142 %!assert(nlfilter(uint16(eye(4)),'indexed',[2,3],inline("sum(x(:))","x")),[2,2,1,0;1,2,2,1;0,1,2,2;0,0,1,1]); 140 %!assert(nlfilter(uint16(eye(4)),'indexed',[2,3],inline("sum(x(:))","x")),[2,2,1,0;1,2,2,1;0,1,2,2;0,0,1,1]);
143 141
144 % Check if function class is preserved 142 % Check if function class is preserved
145 %!assert(nlfilter(uint8(eye(4)),'indexed',[2,3],inline("int8(sum(x(:)))","x")),int8([2,2,1,0;1,2,2,1;0,1,2,2;0,0,1,1])); 143 %!assert(nlfilter(uint8(eye(4)),'indexed',[2,3],inline("int8(sum(x(:)))","x")),int8([2,2,1,0;1,2,2,1;0,1,2,2;0,0,1,1]));
146
147
148
149 %
150 % $Log$
151 % Revision 1.4 2007/03/23 16:14:37 adb014
152 % Update the FSF address
153 %
154 % Revision 1.3 2007/01/04 23:50:47 hauberg
155 % Put seealso before end deftypefn
156 %
157 % Revision 1.2 2007/01/04 23:37:54 hauberg
158 % Minor changes in help text
159 %
160 % Revision 1.1 2006/08/20 12:59:35 hauberg
161 % Changed the structure to match the package system
162 %
163 % Revision 1.5 2005/09/08 02:00:17 pkienzle
164 % [for Bill Denney] isstr -> ischar
165 %
166 % Revision 1.4 2004/11/15 16:04:20 pkienzle
167 % Fix tests for functions which return boolean matrices
168 %
169 % Revision 1.3 2004/09/03 13:28:32 jmones
170 % Corrected behaviour for int* and uint* types
171 %
172 % Revision 1.2 2004/08/15 19:43:11 jmones
173 % corrected a typo in doc
174 %
175 % Revision 1.1 2004/08/15 19:42:14 jmones
176 % nlfilter: Processes image in siliding blocks using user-supplied function
177 %
178 %