badge icon

This article was automatically translated from the original Turkish version.

Article

Spatial Filtering

Spatial filtering is a widely used method in image processing and signal processing. This technical aims to modify specific characteristics of an image by directly manipulating its pixels. Noise reduction, edge perception, sharpening, or blurring like operations can be performed using spatial filtering.

Spatial Filtering

Spatial filtering is a technique used in digital image processing and signal processing to alter or enhance specific characteristics of an image by directly manipulating its pixel values. This method operates on the spatial domain data of an image; that is, it performs operations on pixel coordinates and intensity values. Spatial filtering differs from frequency domain filtering techniques (such as those based on Fourier transforms) because it uses the raw pixel data of the image without any transformation.

Basic Principle

The foundation of spatial filtering lies in applying a matrix called a "kernel" or "mask" to each pixel of the image. This kernel generates a new output value by combining the value of a central pixel with the values of its neighboring pixels in a weighted manner. The operation is applied across the entire image using a sliding window technique. This process, mathematically termed "convolution," forms the fundamental building of spatial filtering.


When an image is represented as f(x,y) and the kernel as h(m,n), the output image g(x,y) resulting from spatial filtering is calculated using the following formula:


<span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">g</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mclose">)</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:3.1966em;vertical-align:-1.3604em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.6514em;"><span style="top:-1.9em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">m</span><span class="mrel mtight">=</span><span class="mord mtight">−</span><span class="mord mathnormal mtight">a</span></span></span></span><span style="top:-3.05em;"><span class="pstrut" style="height:3.05em;"></span><span><span class="mop op-symbol large-op">∑</span></span></span><span style="top:-4.3em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">a</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.3083em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mop op-limits"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:1.8361em;"><span style="top:-1.8479em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">m</span><span class="mrel mtight">=</span><span class="mord mtight">−</span><span class="mord mathnormal mtight">b</span></span></span></span><span style="top:-3.05em;"><span class="pstrut" style="height:3.05em;"></span><span><span class="mop op-symbol large-op">∑</span></span></span><span style="top:-4.3em;margin-left:0em;"><span class="pstrut" style="height:3.05em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mathnormal mtight">b</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.3604em;"><span></span></span></span></span></span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">h</span><span class="mopen">(</span><span class="mord mathnormal">m</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal">n</span><span class="mclose">)</span><span class="mord">.</span><span class="mord mathnormal" style="margin-right:0.10764em;">f</span><span class="mopen">(</span><span class="mord mathnormal">x</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:0.7778em;vertical-align:-0.1944em;"></span><span class="mord mathnormal">m</span><span class="mpunct">,</span><span class="mspace" style="margin-right:0.1667em;"></span><span class="mord mathnormal" style="margin-right:0.03588em;">y</span><span class="mspace" style="margin-right:0.2222em;"></span><span class="mbin">−</span><span class="mspace" style="margin-right:0.2222em;"></span></span><span class="base"><span class="strut" style="height:1em;vertical-align:-0.25em;"></span><span class="mord mathnormal">n</span><span class="mclose">)</span></span></span></span>

  • f(x,y): Pixel intensity of the original image
  • h(m,n): Weight coefficients of the kernel
  • a and b: Half-widths that define the kernel size (e.g., for a 3x3 kernel, a = b = 1)
  • g(x,y): Pixel value of the filtered output image.


Processing Steps


1- Kernel Selection: For example, a 3x3 averaging filter is used.


<span class="katex"><span class="katex-html" aria-hidden="true"><span class="base"><span class="strut" style="height:0.6944em;"></span><span class="mord mathnormal">h</span><span class="mspace" style="margin-right:0.2778em;"></span><span class="mrel">=</span><span class="mspace" style="margin-right:0.2778em;"></span></span><span class="base"><span class="strut" style="height:3.6em;vertical-align:-1.55em;"></span><span class="mord"><span class="mopen nulldelimiter"></span><span class="mfrac"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:0.8451em;"><span style="top:-2.655em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">9</span></span></span></span><span style="top:-3.23em;"><span class="pstrut" style="height:3em;"></span><span class="frac-line" style="border-bottom-width:0.04em;"></span></span><span style="top:-3.394em;"><span class="pstrut" style="height:3em;"></span><span class="sizing reset-size6 size3 mtight"><span class="mord mtight"><span class="mord mtight">1</span></span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:0.345em;"><span></span></span></span></span></span><span class="mclose nulldelimiter"></span></span><span class="mspace" style="margin-right:0.1667em;"></span><span class="minner"><span class="mopen"><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.05em;"><span class="pstrut" style="height:5.6em;"></span><span style="width:0.875em;height:3.600em;"><svg xmlns="http://www.w3.org/2000/svg" width="0.875em" height="3.600em" viewBox="0 0 875 3600"><path d="M863,9c0,-2,-2,-5,-6,-9c0,0,-17,0,-17,0c-12.7,0,-19.3,0.3,-20,1 c-5.3,5.3,-10.3,11,-15,17c-242.7,294.7,-395.3,682,-458,1162c-21.3,163.3,-33.3,349, -36,557 l0,84c0.2,6,0,26,0,60c2,159.3,10,310.7,24,454c53.3,528,210, 949.7,470,1265c4.7,6,9.7,11.7,15,17c0.7,0.7,7,1,19,1c0,0,18,0,18,0c4,-4,6,-7,6,-9 c0,-2.7,-3.3,-8.7,-10,-18c-135.3,-192.7,-235.5,-414.3,-300.5,-665c-65,-250.7,-102.5, -544.7,-112.5,-882c-2,-104,-3,-167,-3,-189 l0,-92c0,-162.7,5.7,-314,17,-454c20.7,-272,63.7,-513,129,-723c65.3, -210,155.3,-396.3,270,-559c6.7,-9.3,10,-15.3,10,-18z"/></svg></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.55em;"><span></span></span></span></span></span></span><span class="mord"><span class="mtable"><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.21em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span><span style="top:-3.01em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span><span style="top:-1.81em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.55em;"><span></span></span></span></span></span><span class="arraycolsep" style="width:0.5em;"></span><span class="arraycolsep" style="width:0.5em;"></span><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.21em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span><span style="top:-3.01em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span><span style="top:-1.81em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.55em;"><span></span></span></span></span></span><span class="arraycolsep" style="width:0.5em;"></span><span class="arraycolsep" style="width:0.5em;"></span><span class="col-align-c"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.21em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span><span style="top:-3.01em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span><span style="top:-1.81em;"><span class="pstrut" style="height:3em;"></span><span class="mord"><span class="mord">1</span></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.55em;"><span></span></span></span></span></span></span></span><span class="mclose"><span class="delimsizing mult"><span class="vlist-t vlist-t2"><span class="vlist-r"><span class="vlist" style="height:2.05em;"><span style="top:-4.05em;"><span class="pstrut" style="height:5.6em;"></span><span style="width:0.875em;height:3.600em;"><svg xmlns="http://www.w3.org/2000/svg" width="0.875em" height="3.600em" viewBox="0 0 875 3600"><path d="M76,0c-16.7,0,-25,3,-25,9c0,2,2,6.3,6,13c21.3,28.7,42.3,60.3, 63,95c96.7,156.7,172.8,332.5,228.5,527.5c55.7,195,92.8,416.5,111.5,664.5 c11.3,139.3,17,290.7,17,454c0,28,1.7,43,3.3,45l0,9 c-3,4,-3.3,16.7,-3.3,38c0,162,-5.7,313.7,-17,455c-18.7,248,-55.8,469.3,-111.5,664 c-55.7,194.7,-131.8,370.3,-228.5,527c-20.7,34.7,-41.7,66.3,-63,95c-2,3.3,-4,7,-6,11 c0,7.3,5.7,11,17,11c0,0,11,0,11,0c9.3,0,14.3,-0.3,15,-1c5.3,-5.3,10.3,-11,15,-17 c242.7,-294.7,395.3,-681.7,458,-1161c21.3,-164.7,33.3,-350.7,36,-558 l0,-144c-2,-159.3,-10,-310.7,-24,-454c-53.3,-528,-210,-949.7, -470,-1265c-4.7,-6,-9.7,-11.7,-15,-17c-0.7,-0.7,-6.7,-1,-18,-1z"/></svg></span></span></span><span class="vlist-s">​</span></span><span class="vlist-r"><span class="vlist" style="height:1.55em;"><span></span></span></span></span></span></span></span></span></span></span>


4- Result: This process is repeated for every pixel in the image to produce a filtered output image.


Pixel processing between the original and filtered image (Credit: Gonca İnönü)

Purpose of Spatial Filtering

Spatial filtering can be used for various purposes:

  • Noise Reduction: Removing random distortions in the image (e.g., salt and pepper noise).
  • Edge Detection: Highlighting the boundaries of objects in the image.
  • Blurring: Smoothing details to achieve a more homogeneous image.
  • Sharpening: Enhancing details and contrast in the image.

Types of Spatial Filtering

Spatial filtering types are broadly divided into two main categories: low-pass filters and high-pass filters. Based on application method, they are further classified into linear filters and non-linear filters.

Low-Pass Filters

Low-pass filters preserve low-frequency components in an image while suppressing high-frequency components (such as abrupt changes and sharp edges). These filters are commonly used to smooth images and reduce noise.

Mean Filter

The Mean Filter creates a kernel around each pixel, calculates the average of all pixel values within the kernel region, and assigns this average as the new value of the pixel in the filtered image.

Prepared and edited by: Beyza Nur Türkü

Gaussian Filter

The Gaussian Filter blurs the image by combining pixel values with weights based on a Gaussian distribution. Pixel weights vary with distance: pixels closer to the center receive higher weights, while distant pixels receive lower weights.

Prepared and edited by: Beyza Nur Türkü

Median Filter

The Median Filter replaces the value of each pixel with the median value of the pixel values within its kernel.

Prepared and edited by: Beyza Nur Türkü

Minimum Filter

The Minimum Operator or Minimum Filter assigns the minimum value found within a specified region surrounding each pixel as the new value of that pixel.

Prepared and edited by: Beyza Nur Türkü

Maximum Filter

The Maximum Operator or Maximum Filter assigns the maximum value found within a specified region surrounding each pixel as the new value of that pixel.

Prepared and edited by: Beyza Nur Türkü

Disk Filter

In the Disk Filter, the kernel has a circular shape, hence its name.

Prepared and edited by: Beyza Nur Türkü

k-NN Filter

The k-NN Filter (k-Nearest Neighbors Filter) calculates a new value by considering the values of the k most similar neighboring pixels. "Similarity" is typically determined by intensity similarity, and the center pixel's value is updated using the average of these selected neighbors.

Prepared and edited by: Beyza Nur Türkü

High-Pass Filters

High-pass filters emphasize high-frequency components in an image (such as edges and details) while suppressing low-frequency components (flat regions). These filters are commonly used for image sharpening or edge detection.

Sobel Filter

The Sobel Filter highlights edges by calculating gradients of intensity changes. It typically uses two different kernels to compute horizontal and vertical gradients separately, and the combination of these gradients determines the location and strength of edges.

Prepared and edited by: Beyza Nur Türkü

Prewitt Filter

Prewitt Filter, similar to the Sobel Filter, highlights edges by calculating intensity changes in the image.

Prepared and edited by: Beyza Nur Türkü

Laplacian Filter

The Laplacian Filter highlights edges by computing the second derivative of the image, detecting the rate of intensity change. The Laplacian Filter does not provide directional information only but detects the magnitude of intensity changes.

Prepared and edited by: Beyza Nur Türkü

LoG (Laplacian of Gaussian) Filter

The LoG (Laplacian of Gaussian) Filter is a combination of the Gaussian Filter and the Laplacian Filter. First, the image is smoothed using Gaussian blurring, then the Laplacian operator computes the second derivative to highlight edges.

Prepared and edited by: Beyza Nur Türkü

Author Information

Avatar
AuthorBeyza Nur TürküDecember 18, 2025 at 3:59 PM

Tags

Discussions

No Discussion Added Yet

Start discussion for "Spatial Filtering" article

View Discussions

Contents

  • Spatial Filtering

    • Basic Principle

    • Processing Steps

    • Purpose of Spatial Filtering

    • Types of Spatial Filtering

      • Low-Pass Filters

      • Mean Filter

      • Gaussian Filter

      • Median Filter

      • Minimum Filter

      • Maximum Filter

      • Disk Filter

      • k-NN Filter

    • High-Pass Filters

      • Sobel Filter

      • Prewitt Filter

      • Laplacian Filter

      • LoG (Laplacian of Gaussian) Filter

Ask to Küre