Neighbourhood operations compute an output pixel from a group of pixels in a local region, in contrast to point operations acting on a single pixel.
- The operator is a sub-image, called a filter, mask, kernel, template or window
- Each element of the mask acts on a corresponding pixel in the local neighbourhood
- The output is saved to a new image, never written back into the input
Process:
- Identify the center pixel the operation applies to
- Align the mask center with the neighbourhood:
- Compute the output pixel from the mask and the selected neighbourhood
- Save to the output image
- Repeat for every pixel in the input image
Linear spatial filtering
The output is a sum of products between the mask and the neighbourhood, equivalent to a matrix dot product.
Here:
- : mask, typically odd sized with dimensions
- : input image
Integer filter coefficients with a scaling factor reduce computational cost:
Properties:
- Translational invariance
The computation is the same everywhere in the image, only the neighbourhood values change. - Locality
The output depends only on pixels within the neighbourhood. - Linearity
Successive linear filters combine into a single equivalent filter, saving computation.
Non-linear spatial filtering
Shares the same algorithm as linear filtering, but computes the output using a non-linear expression: thresholding, sorting, log functions.
- Locality and translational invariance still hold
- Linearity does not hold
Examples:
- if the weighted neighbourhood sum a threshold , else
Handling image boundaries
The neighbourhood doesn’t fit the mask at image boundaries.
- Omit missing pixels
Output is smaller than the input, but requires no algorithm change. - Change mask shape at the edge
Requires extra conditional logic, only works for certain filters. - Pad the image
Add extra rows and columns with white, black or background coloured pixels. - Replicate border pixels
- Wrap pixels around the image
Can cause artefacts.
Convolution and correlation
Correlation:
- Denoted
- Computed directly with the mask as given
- Used for template matching, where directionality matters
Convolution:
- Denoted
- Mask is pre-rotated 180 degrees before computation
- Used for operations such as smoothing, where directionality doesn’t matter