Image Processing Basics

2D convolution, edge detection.

Darshan N
Updated: 19 March 2026
9 min read

Image processing using DSP techniques forms the foundation of computer vision, medical imaging, satellite analysis, and multimedia systems. For a 2D digital image, the same principles that apply to 1D discrete-time signals, such as convolution, filtering, and frequency analysis, extend naturally into two dimensions. GATE and university examinations regularly test 2D convolution and edge detection as core DSP application topics.

2D Image Processing: Convolution and Edge Detection OverviewInput Image f(x,y)Pixel grid M x NIntensity: 0-255 (8-bit)Kernel h(x,y)3x3 or 5x5 maskSmoothing / Sharpening2D Convolutiong(x,y) = f ** hSlide kernel overentire image planeOutput g(x,y)Filtered imageEdges / smoothedCommon Kernels and Their EffectsGaussian Blur1 2 12 4 2 x (1/16)1 2 1Removes noiseLow-pass filterSobel X (Gx)-1 0 +1-2 0 +2-1 0 +1Horizontal edgesdI/dx gradientSobel Y (Gy)-1 -2 -1 0 0 0+1 +2 +1Vertical edgesdI/dy gradientLaplacian 0 -1 0-1 4 -1 0 -1 0All-direction edgesSecond derivativeEdge magnitude: |G| = sqrt(Gx^2 + Gy^2) Angle: theta = atan2(Gy, Gx)2D convolution complexity: O(M*N*K^2) for M x N image and K x K kernel
Figure 1: Overview of 2D image convolution and standard edge detection kernels used in digital image processing.

Core Concept: 2D Convolution

A digital image is a 2D discrete signal, typically represented as f(x, y), where x and y are spatial coordinates and f gives the pixel intensity at that location. 2D convolution is the fundamental operation that underlies spatial filtering of images. Just as a 1D signal is filtered by convolving it with an impulse response h(n), a 2D image is filtered by convolving it with a 2D kernel (also called a mask or filter matrix).

The 2D discrete convolution is defined as: g(x, y) = sum_m sum_n f(m, n) * h(x-m, y-n). In practice, a small kernel of size K x K (typically 3x3 or 5x5) is slid over the image. At each position, an element-wise product between the kernel and the overlapping image patch is computed, and the sum gives the output pixel value. This operation is computationally feasible because K is much smaller than the image dimensions M x N.

An important distinction: image processing libraries often implement cross-correlation (without flipping the kernel) rather than true convolution. For symmetric kernels such as the Gaussian, this makes no difference. For asymmetric kernels such as Sobel operators, the kernel must be flipped to obtain true convolution. GATE sometimes tests this distinction.

Edge Detection

Edges in an image correspond to locations of rapid intensity change, which mathematically correspond to regions of high spatial gradient. Edge detection identifies these boundaries, which are critical for object recognition and segmentation. The Sobel operator computes the first derivative of intensity in the horizontal (Gx) and vertical (Gy) directions using 3x3 kernels. The edge magnitude is |G| = sqrt(Gx^2 + Gy^2) and edge direction is theta = atan2(Gy, Gx).

The Laplacian operator computes the second derivative of the image intensity. It is isotropic (responds equally to edges in all directions) but is highly sensitive to noise because differentiation amplifies high-frequency noise. In practice, a Gaussian blur is applied before Laplacian edge detection, a combination known as the Laplacian of Gaussian (LoG) or Marr-Hildreth operator.

The Canny edge detector is the most widely used multi-step edge detection algorithm. It involves Gaussian smoothing, gradient computation, non-maximum suppression to thin edges, and hysteresis thresholding to link edges. Though Canny is not a single convolution kernel, understanding its stages requires knowledge of 2D filtering and gradient computation.

Mathematical Expression

For a 2D image f(x,y) of size M x N convolved with a kernel h(m,n) of size K x K, the output is g(x,y) = sum_{m=0}^{K-1} sum_{n=0}^{K-1} h(m,n) * f(x-m, y-n). The 2D Fourier transform relationship is: G(u,v) = F(u,v) * H(u,v), where the multiplication is pointwise. This shows that spatial convolution corresponds to multiplication in the 2D frequency domain, enabling fast filtering using 2D FFT (complexity O(MN log(MN)) instead of O(MN K^2) for direct convolution).

Practical Understanding

Gaussian blurring is a low-pass filter in the spatial frequency domain. It removes high-frequency noise while preserving low-frequency structure. The standard deviation sigma of the Gaussian controls the trade-off between noise removal and detail preservation. A larger sigma smooths more but blurs edges. Edge detection kernels such as Sobel are high-pass filters that amplify high-frequency transitions.

Boundary handling is a practical concern in 2D convolution. When the kernel extends beyond the image border, strategies include zero-padding, reflection padding, or wrapping. Zero-padding is the most common and is the implicit assumption in most GATE-level problems. For an M x N image convolved with a K x K kernel with zero-padding, the output image size remains M x N, while without padding the output shrinks to (M-K+1) x (N-K+1).

Example
Given:
Input image size: 5 x 5 pixels
Kernel size: 3 x 3 (Sobel Gx)
With zero-padding applied

Why this formula applies:
For an M x N image convolved with a K x K kernel:
With zero-padding: output size = M x N (unchanged)
Without zero-padding: output size = (M-K+1) x (N-K+1)

Formula:
Output size (no padding) = (M - K + 1) x (N - K + 1)
Output size (zero-pad)   = M x N

Substitution:
M = 5, N = 5, K = 3
No padding: (5-3+1) x (5-3+1)

Calculation:
= 3 x 3

Final Answer:
Without padding: output is 3 x 3
With zero-padding: output remains 5 x 5
Number of multiplications per output pixel (direct): K^2 = 9
Exam Tip: In GATE, output image size for convolution without padding is (M-K+1) x (N-K+1). The Sobel operator is NOT rotationally symmetric, while the Laplacian is. Gaussian kernel coefficients always sum to 1 for a smoothing filter; edge detection kernels have coefficients summing to 0.

Mechanism: Edge Detection Process

Canny Edge Detection Mechanism Step-by-StepInput Imagef(x,y) grayscaleGaussianSmooth (LP filter)Sobel GradientGx, Gy magnitudeNon-max SuppressThin edges to 1pxHysteresisThresholding Tl, ThSpatial Frequency Interpretation of FiltersGaussian Kernel (LP)H(u,v) = exp(-(u^2+v^2)/(2 sigma^2))Passes low spatial freqsigma: larger = more blurSobel / Edge Kernels (HP)Kernel coefficients sum to 0Passes high spatial frequencyDC response = 0 (uniform areas zero)Laplacian (Band-pass)H(u,v) = -4 pi^2 (u^2 + v^2)Second derivative: very noise sensitiveUse with Gaussian (LoG) for stabilityConvolution as Matrix Sliding: 3x3 Kernel on 5x5 Image ExampleKernel center placed at pixel (x,y). Multiply overlapping region element-wise. Sum = output g(x,y).Total operations (direct): (M-K+1)*(N-K+1)*K^2 = 3*3*9 = 81 multiplications (no padding, 5x5 image, 3x3 kernel)With 2D FFT: O(M*N*log2(M*N)) is faster for large images and large kernels
Figure 2: Canny edge detection pipeline and spatial frequency interpretation of low-pass and high-pass image filters.

Mechanism Summary

  • 2D convolution slides a kernel of size K x K over the image computing a weighted sum at each position. Output size without padding is (M-K+1) x (N-K+1).
  • Gaussian kernel is separable (G = G_x * G_y^T), allowing 2D convolution to be computed as two 1D convolutions, reducing complexity from O(K^2) to O(2K) per pixel.
  • Sobel operator estimates the first derivative. Edge magnitude = sqrt(Gx^2 + Gy^2). Edge direction = atan2(Gy, Gx). Thresholding the magnitude gives binary edge maps.
  • Laplacian detects edges using second derivatives. Zero-crossings of the Laplacian correspond to edge locations. LoG (Laplacian of Gaussian) pre-smooths to reduce noise sensitivity.
  • 2D DFT-based filtering replaces spatial convolution with pointwise multiplication in the frequency domain: G(u,v) = F(u,v) * H(u,v), saving computation for large kernels.

Quick Revision

  • 2D convolution: g(x,y) = sum_m sum_n f(m,n) h(x-m, y-n). Frequency domain equivalent: G = F x H (pointwise).
  • Output size without padding: (M-K+1) x (N-K+1). With zero-padding: M x N unchanged.
  • Gaussian kernel: coefficients sum to 1, low-pass, separable. Sobel/Laplacian: coefficients sum to 0, high-pass or band-pass.
  • Sobel edge magnitude: |G| = sqrt(Gx^2 + Gy^2). Direction: theta = atan2(Gy, Gx).
  • Canny steps: Gaussian smooth, gradient magnitude, non-max suppression, hysteresis thresholding with Tl and Th.
  • Exam trap: Convolution flips the kernel; cross-correlation does not. For symmetric kernels (Gaussian, Laplacian with center symmetry), both are identical. For Sobel, flipping changes the sign of the gradient direction.
  • Separable Gaussian reduces per-pixel cost from K^2 to 2K multiplications, a major practical advantage.

Image Processing Quiz

Challenge your understanding of 2D convolution and edge detection operators.

Question 1 of 3

Q1.The Sobel operator for edge detection computes the gradient magnitude using two 3x3 kernels. What does the Sobel operator approximate?