The Nagao-Matsuyama filter is an example of a complex local neighbourhood operation that uses variance as an indicator of the uniformity within a pixel group.
The result is similar to a convolution with a low-pass filter with the added effect of preserving sharp edges.
[1] [2] There is also a class of neighborhood operations in which the function f has additional parameters which can vary with p: This implies that the result is not shift invariant.
The pseudo code given above suggests that a neighborhood operation is implemented in terms of an outer loop over all image points.
Furthermore, in the case of linear shift-invariant operations, the computation of f at each point implies a summation of products between the image data and the filter coefficients.