0)) + A=padarray(A,prepad,padval,'both'); + endif + else + if(any(prepad>0)) + A=padarray(A,prepad,padval,'pre'); + endif + if(any(postpad>0)) + A=padarray(A,postpad,padval,'post'); + endif + endif + + ## calc end offsets + me=postpad(1)+prepad(1); + ne=postpad(2)+prepad(2); + + ## We concatenate everything to preserve fun return type + for i=1:as(1) + r=feval(fun,A(i:i+me,1:1+ne),varargin{p+1:nargin-1}); + for j=2:as(2) + r=horzcat(r,feval(fun,A(i:i+me,j:j+ne),varargin{p+1:nargin-1})); + endfor + if(i==1) + B=r; + else + B=vertcat(B,r); + endif + endfor + +endfunction + +%!demo +%! nlfilter(eye(10),[3,3],inline("any(x(:)>0)","x")) +%! # creates a "wide" diagonal + +%!assert(nlfilter(eye(4),[2,3],inline("sum(x(:))","x")),[2,2,1,0;1,2,2,1;0,1,2,2;0,0,1,1]); +%!assert(nlfilter(eye(4),'indexed',[2,3],inline("sum(x(:))","x")),[4,2,1,2;3,2,2,3;2,1,2,4;4,3,4,5]); +%!assert(nlfilter(eye(4),'indexed',[2,3],inline("sum(x(:))==y","x","y"),2),[0,1,0,1;0,1,1,0;1,0,1,0;0,0,0,0]!=0); + +% Check uint8 and uint16 padding +%!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]); +%!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]); + +% Check if function class is preserved +%!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])); + + + +% +% $Log$ +% Revision 1.4 2007/03/23 16:14:37 adb014 +% Update the FSF address +% +% Revision 1.3 2007/01/04 23:50:47 hauberg +% Put seealso before end deftypefn +% +% Revision 1.2 2007/01/04 23:37:54 hauberg +% Minor changes in help text +% +% Revision 1.1 2006/08/20 12:59:35 hauberg +% Changed the structure to match the package system +% +% Revision 1.5 2005/09/08 02:00:17 pkienzle +% [for Bill Denney] isstr -> ischar +% +% Revision 1.4 2004/11/15 16:04:20 pkienzle +% Fix tests for functions which return boolean matrices +% +% Revision 1.3 2004/09/03 13:28:32 jmones +% Corrected behaviour for int* and uint* types +% +% Revision 1.2 2004/08/15 19:43:11 jmones +% corrected a typo in doc +% +% Revision 1.1 2004/08/15 19:42:14 jmones +% nlfilter: Processes image in siliding blocks using user-supplied function +% +%