Filtering, Feature Detection and Extraction in Computer Vision
Image Fundamentals and Colour Spaces
Image processing and computer vision require an understanding of how images are represented digitally and how various colour models interpret visual data. Several different colour spaces exist, and while models typically consider the RGB (Red, Green, Blue) space by default, treating each channel equivalently, the relationships and transitions between spaces are often non-linear. Choosing the appropriate colour space can lead to significant improvements in computer vision tasks. The three primary spaces discussed are RGB, HSV, and CEILAB. The RGB space is a three-dimensional model comprising Red (R), Green (G), and Blue (B) channels. The HSV space captures information based on Hue (H), Saturation (S), and Value (V). The CEILAB space is particularly useful because it separates intensity from colour, consisting of an Intensity or Lightness channel () and two colour channels, and . In practice, extracting specific channels like the Value channel in HSV or the Lightness channel in CEILAB can provide more robust data for certain algorithms than standard RGB processing.
Understanding Image Noise Models
Digital images are often corrupted by noise during acquisition or transmission, necessitating specific filtering strategies. Different sources of interference result in distinct noise models. Gaussian Noise is synonymous with sensor noise associated with natural images. Poisson Noise is characterized by its association with medical imaging and microscopy. Salt and Pepper Noise, visible as random black and white pixels, is typically caused by sensor errors and transmission faults. Using the MIT Cameraman test image resized to a grid as a baseline, the impact of these noise types is observed numerically. For instance, a clean set of pixels might read values such as , while Salt and Pepper noise introduces extreme values of (pepper) or (salt) into the grid.
Spatial Filtering Techniques
Filtering is a primary solution for seeing through noise and is often visualized as an operation mapping an input image to an output image . A common approach is the sliding window method. Mean Filtering involves moving a window (e.g., a grid) across the image and calculating the average pixel value within that window to replace the center pixel. For example, if a window contains values resulting in a mean of , that value becomes the new pixel in the output image. While mean filtering can reduce noise, it often introduces considerable artifacts and fails to remove noise effectively in extreme cases. Alternatively, Median Filtering replaces the center pixel with the median value of the window. In a grid where Salt and Pepper noise is present, the median filter is highly effective at removing the extreme and values, though it may damage some fine image details.
Quantitative Performance Metrics
To objectively evaluate filtering effectiveness, quantitative comparisons are made between the original image () and the filtered image (). The Mean Squared Error (MSE) is calculated using the formula
where and represent the number of columns and rows. The Peak Signal-to-Noise Ratio (PSNR) provides a logarithmic measure of image quality:
In these equations, for 8-bit images and for normalized images. In a test case, the Mean filter yielded an MSE of and a PSNR of , while the Median filter performed better with an MSE of and a PSNR of .
Linear Filters and Convolution Kernels
Linear filtering is fundamentally a convolution operation. A Kernel () is a small matrix of weights used to transform the image. The general Convolution Equation is expressed as
Various kernels produce different visual effects. A Mean Filter kernel is a grid of uniform values (e.g., all for a kernel). A Gaussian Filter utilizes weights based on the Gaussian distribution to provide smoother blurring:
A typical Gaussian kernel might use weights of at corners, at edges, and at the center. Motion Blur Filters utilize directional weights (e.g., a row or column of ) to simulate movement. Sharpening Filters use kernels where center values are enhanced (such as ) while surrounding values are negative (). A key property of these blur kernels is that their elements sum to , ensuring the overall intensity of the image remains unchanged.
Edge Detection and the Sobel Operator
Edge detection is a critical step in feature extraction, identifying areas where pixel intensity changes rapidly. The Sobel Operator uses two kernels to detect horizontal and vertical edges. The horizontal Sobel kernel is
while the vertical kernel is
Edge detection is mathematically related to the partial derivative of the image function. The derivative measures the rate of change. Since images are discrete grids with a minimum pixel spacing of , the derivative is approximated as . Using reference points and allows for a central difference approximation:
The gradient magnitude is then calculated by combining the results of the edge detection operators in both directions:
Other variations of edge detection kernels include the Roberts, Prewitt, and Frei-Chen operators, each utilizing different weighted grids for intensity gradient calculation.
Feature Hierarchy and Image Frequency
Features are distinctive pieces of information extracted from images and are categorized into a hierarchy. Low-level Features are directly extracted from pixels, such as edges, textures, and corners. Mid-level Features are derived from the low-level data, including object parts or contours. High-level Features consist of hierarchical representations. Image frequency measures the speed at which pixel intensity values change through space; natural images are typically a mixture of high frequencies (edges and fine detail) and low frequencies (smooth regions). This is analyzed in "frequency space" using the Fourier Transform, which decomposes an image into a Spectral Domain comprising Magnitude and Phase. Patterns and textures are encoded in the magnitude, while structure is encoded in the phase. Swapping the phase between two images demonstrates that the structural information follows the phase rather than the magnitude. Low-pass filters remove high frequencies to smooth images, while high-pass filters isolate edges. Threshold-based filters in the frequency domain can leave "ringing artifacts," which are mitigated by using Gaussian frequency filters.
Mathematical Properties and Efficiency of Convolution
Convolution exhibits several key mathematical properties: Commutativity (), Associativity (), and Distributivity (). It also scales linearly with constant values (). A vital property concerns integration: the integral of a convolved signal is the product of the integrals of the individual signals:
The Convolution Theorem states that convolution in the spatial domain is equivalent to point-wise multiplication in the spectral (Fourier) domain:
This theorem is crucial for computational efficiency. Performing convolution on an image with an kernel in the spatial domain requires operations. In contrast, using the Fast Fourier Transform (FFT) to operate in the spectral domain requires approximately operations. For a image with a kernel, the spectral approach is roughly faster than the spatial sliding window approach.
Deep Learning and Boundary Conditions
In computer vision, convolution enables translation invariance, parameter sharing, and composability. However, there is a technical distinction between mathematical convolution and the "convolution" used in deep learning. Deep learning typically employs Cross-Correlation, defined as
Furthermore, deep learning convolution often omits or simplifies boundary conditions, effectively performing a convolution followed by cropping. Traditional computer vision handles image boundaries using several methods: Dirichlet Boundary Conditions (assuming values outside the domain are ), Periodic Boundary Conditions (assuming the image repeats), and Neumann Boundary Conditions (assuming the boundary is a reflection). Finally, while classical computer vision relies on handcrafted filters (like Sobel or Gaussian), deep learning focuses on learned filters where the kernel weights are optimized through training.