Processes image in sliding blocks using user-supplied function.
B=nlfilter(A,[m,n],fun)
passes sliding m-by-n blocks to user-supplied function fun. A block is build for every pixel in A, such as it is centered within the block. fun must return a scalar, and it is used to create matrix B. nlfilter pads the m-by-n block at the edges if necessary.Center of block is taken at ceil([m,n]/2).
B=nlfilter(A,[m,n],fun,...)
behaves as described above but passes extra parameters to function fun.
B=nlfilter(A,'indexed',...)
assumes that A is an indexed image, so it pads the image using proper value: 0 for uint8 and uint16 images and 1 for double images. Keep in mind that if 'indexed' is not specified padding is always done using 0.
The following code
nlfilter(eye(10),[3,3],inline("any(x(:)>0)","x")) # creates a "wide" diagonal
Produces the following output
ans = 1 1 1 0 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 1 0 0 0 0 0 0 1 1 1 1 0 0 0 0 0 0 0 1 1 1