72 min total

Computer Vision & OpenCV

Image filtering

Image filtering

Digitization: Converting continuous image signals into discrete form

Image Sampling + Quantization Digital Image

Discretizing: process of transferring continuous data into discrete data

An image maps grid coordinates to pixel values: a grayscale image maps (x, y) to one intensity, while a color image maps each coordinate to a channel vector.

G is the image domain: the set of grid coordinates (x,y). V is the set of possible pixel values. For grayscale, V contains intensities; for RGB, each value is a three-channel vector.

Sampling and quantization axes

Grayscale image: f(10, 20) = (128) means pixel at(10, 20) has intensity of 128(mid-gray)

RGB image: f(10, 20) = (255, 128, 64)

At pixel (10, 20), the RGB channels are R = 255, G = 128, and B = 64.

For this 8-bit RGB example, red 255 is at maximum intensity, green 128 is near the middle of the range, and blue 64 is relatively low. Each channel ranges from 0 to 255.

Domain: Means all set of Pixel coordinates (x, y) an image can take

For an image 69 pixels wide and 420 pixels high, integer x coordinates range from 0 to 68 and y coordinates from 0 to 419.

Sampling: Discretizing the domain

Image intensity represented as a surface

Discretizing the domain refers to restricting the range of coordinate values.

Upsampling increases pixel dimensions through interpolation; it does not by itself recover missing detail.

Downsampling reduces pixel dimensions and should include appropriate filtering to limit aliasing.

Range: refers to output values of the function

8-bit image, intensity values→0-255

Grayscale quantization at 256, eight, and four levels

16-bit image, intensity values→0-65,535

Quantization: Discretizing the range

Discretizing the range refers to restricting the range of intensity values.

Resolution comparison at three pixel densities

Spatial resolution describes image detail. Pixel dimensions describe the digital image, while pixel or dot density describes how it is displayed or printed.

Display and print densities vary; 72 and 300 pixels or dots per inch are examples rather than universal settings.

Grayscale images: contains only one channel (Intensity values)

Pixel values range (0-255), 0 = black, 255 = white

Grayscale images has 1 value per pixel

Color images: contains three channels RGB

Each channel has values range (0-255)

Color images has 3 values per pixel

Image Histogram: graphical representation of distribution of pixel intensities in an image

X-axis: represents intensity levels for each channel

Y-axis: represents frequency of pixels at each channel

Image and its intensity histogram

Uses

  • Analyze intensity distribution
  • Feature extraction
  • Image matching
  • Image normalization

Noise in images: unwanted variations in pixels due to light, camera electronics, surface reflections, lens imperfections.

Noise is random and occurs with some probability distribution

Types of Noise

1. Additive Noise

2. Multiplicative Noise

Additive Gaussian noise adds random samples from a Gaussian distribution to image intensities. It is different from smoothing with a Gaussian kernel.

Gaussian Smoothing: Image is convolved with Gaussian kernel

Types of Noise Distributions

Gaussian probability density

1. Gaussian Noise

Noise follows a Gaussian distribution

Zero-mean Gaussian noise is parameterized by its variance σ².

This is the normalized zero-mean Gaussian noise density. A proportional exponential omits its normalization constant. Gaussian noise is random corruption; Gaussian filtering is a smoothing operation.

Where σ represents the standard deviation, controlling the spread of the distribution.

2. Uniform Noise

Noise values are distributed uniformly over a defined range.

Uniform probability density

3. Salt and pepper Noise

Salt-and-pepper noise replaces affected pixels with bright (salt) or dark (pepper) values. The two probabilities need not be equal.

Image filtering: Process of computing a function of a local neighborhood around each pixel in an image

  • Enhance images ⨁Information extraction
  • Pattern detection

h[m, n] - output pixel at pos (m, n) f[k, l] - filter

I[m+k, n+l] - neighboring pixels of original image at (m, n) k, l - filter's kl size

  • Correlation: linear operation that computes a similarity measure between an image and a kernel (filter). No flipping of the kernel.

Cross-correlation multiplies each image patch by the unflipped kernel and sums the products.

For a 3×3 patch, flatten both patch and kernel in the same order; the response is their dot product.

Image patch and filter grid used for cross-correlation
  • Convolution: kernel is flipped both horizontally and vertically before applying it to the image.

Convolution reverses the kernel along both axes relative to cross-correlation.

Horizontal and vertical kernel flips for convolution
  • Template matching
  • Computes Similarity bw signals
  • Feature Matching

Notation: f is the image and h is the kernel.

Convolution is associative: F∗(G∗I)=(F∗G)∗I

Convolution modifies the signal by flipping the kernel then shifting it over the input image while computing weighted sum. Used in edge detection, blurring, sharpening Correlation measure how similar a kernel is to portions of an image by directly shifting it without flipping. Used in template matching

  • Gaussian filter: is a smoothing filter that applies Gaussian function to blur an image, reducing noise.
One- and two-dimensional Gaussian curves
  • Most common model
  • Smooth function, infinite derivates
  • Symmetric
  • Fourier transform of Gaussian is Gaussian
  • Convolution of Gaussian with itself is Gaussian
  • Gaussian is separable, 2D convolutions can be performed by two 1D convolutions

These are unnormalized samples of a Gaussian with σ = 1; divide by the sum before using a normalized smoothing kernel.

Worked Gaussian kernel

Normalize the kernel by dividing each entry by their sum, approximately 4.8976.

Gaussian-kernel calculation, cell by cell

(x,y)x²+y²ExponentUnnormalized value
(-1,-1)2−2/20.3679
(0,-1)1−1/20.6065
(1,-1)2−2/20.3679
(-1,0)1−1/20.6065
(0,0)0−0/21.0000
(1,0)1−1/20.6065
(-1,1)2−2/20.3679
(0,1)1−1/20.6065
(1,1)2−2/20.3679

Each coordinate is evaluated separately, then every weight is divided by the same normalization sum.

The notebook rounded intermediate weights and recorded 151.5. Using the normalized weights above gives approximately 151.37, or 151.4 to one decimal place.

  • Box filtering: when kernel is filled with equal values and result at each pixel is mean of its neighbors. Box filter performs blurring(mean filtering)