CV Unit 1
CV Unit 1
1.2.Color Models
• RGB (Red, Green, Blue):
• Description: Combines red, green, and blue light to create colors.
• Example: Colors on computer screens and digital cameras.
• CMYK (Cyan, Magenta, Yellow, Black):
• Usage: Mainly in printing to achieve a wide range of colors.
2.1.Sampling
• Definition: Sampling refers to capturing the continuous spatial information of an image
at discrete points called pixels.
• Example: Imagine taking a photograph with a digital camera.
o The camera sensor captures the image by sampling the scene at regular intervals,
converting light intensity at each point into digital values.
• Sampling Rate: Determined by pixel density (resolution).
o Higher resolution = more pixels = finer details.
2.2.Quantization
• Definition: Quantization involves assigning discrete digital values (often in bits) to each
sample obtained through sampling.
• Example: If an image is captured with 8bit quantization:
o Each pixel can have one of 256 possible intensity levels (0 to 255 in grayscale).
o For color images, quantization applies separately to each color channel (RGB
or CMYK).
• Impact of Quantization:
o Higher bit depth (more bits per pixel) results in more shades of color and better
image quality.
Image processing involves a series of steps to enhance, analyse, and understand images. It is
widely used in fields like medical imaging, remote sensing, computer vision, and more. The
process typically includes various stages, each with specific techniques and methods to
manipulate and improve the quality of an image.
Details:
• The image is typically represented as a grid of pixels.
• Each pixel has a value corresponding to the intensity or color of the image at that point.
• The resolution and quality of the image depend on the sensor's specifications.
Techniques:
• Noise Reduction: Using filters (e.g., Gaussian, median) to remove noise.
• Contrast Enhancement: Adjusting the brightness and contrast.
• Normalization: Scaling pixel values to a standard range.
Details:
• This step aims to improve the image quality for better analysis.
• Common techniques include smoothing, sharpening, and histogram equalization.
3.1.3. Segmentation
• Definition: Segmentation involves dividing the image into meaningful regions or
objects.
• Example: Separating the foreground (e.g., a person) from the background (e.g., a room).
Techniques:
• Thresholding: Converting an image to binary by setting a threshold.
• Edge Detection: Using operators like Sobel or Canny to find edges.
• Region-based Segmentation: Dividing the image based on similarities in intensity or
color.
Details:
• The goal is to simplify the image and focus on specific parts for further analysis.
• This step is crucial for object detection and recognition tasks.
Techniques:
• Edge Features: Detecting edges using gradient operators.
• Shape Features: Identifying geometric shapes and contours.
• Texture Features: Analysing the surface texture using methods like GLCM (Gray Level
Cooccurrence Matrix).
Details:
• Features are used to describe the objects in the image.
• These features are essential for classification and recognition.
Techniques:
• Boundary Representation: Using curves or polygons to describe the shape.
• Region Representation: Using properties like area, centroid, and moments.
Details:
• The choice of representation depends on the application.
• Effective representation is key for accurate analysis and interpretation.
Techniques:
• Classification: Using machine learning algorithms (e.g., SVM, neural networks) to
classify objects.
• Pattern Matching: Comparing features with a known set of patterns.
Details:
• This step is crucial for applications like face recognition, object detection, and medical
diagnosis.
• The accuracy of recognition depends on the quality of feature extraction and
representation.
3.1.7. Postprocessing
• Definition: Postprocessing involves refining the results obtained from recognition and
interpretation.
• Example: Removing false positives from detected objects.
Techniques:
• Morphological Operations: Using operations like dilation and erosion to clean up the
results.
• Filtering: Applying filters to enhance the final output.
Details:
• Postprocessing helps in improving the accuracy and reliability of the results.
• It is often tailored to specific applications and requirements.
4. Image acquisition
4.2.2. Scanners:
• Description: Convert physical documents or images into digital form.
• Example: Flatbed scanners for documents, film scanners for negatives.
• Process: Reflective or transmissive light scans the document, converted into digital data
(often grayscale or color).
• File Formats: JPEG, PNG, TIFF, RAW, etc., store images with varying levels of
compression and quality.
• Compression: Lossy (JPEG) vs. lossless (PNG, TIFF) compression methods impact
image fidelity and file size.
5. Color Image representation
5.1.Introduction
Color image representation involves the methods and formats used to digitally store and
manipulate color information in images. Understanding how color is represented in digital
images is crucial for various applications in image processing, computer vision, and graphics.
• Color Models
• Color Spaces
• Color Channels
• Bit Depth
• Color Conversion
• Definition: A color model is a mathematical model describing the way colors can be
represented as tuples of numbers.
Examples:
• RGB Model: A color is represented as a combination of red, green, and blue values,
e.g., (255, 0, 0) for pure red.
• CMYK Model: Used in printing where colors are mixed using four inks, e.g., (0, 1, 1,
0) for pure cyan.
Examples:
• sRGB: Standard color space for web images, ensuring colors look consistent across
different devices.
• Adobe RGB: Preferred for print media because it covers more shades of green and cyan.
5.1.3. Color Channels
Details:
• In the RGB model, there are three channels: Red, Green, and Blue.
• Each channel is a grayscale image representing the intensity of that color component.
Example:
• An RGB image of a sunset will have three separate matrices for R, G, and B, each
storing intensity values ranging from 0 to 255.
• Definition: Bit depth refers to the number of bits used to represent the color of a single
pixel.
Example:
• 8bit per channel RGB image: Each color channel has 256 possible values, leading to
over 16 million possible colors (256 x 256 x 256).
Common Conversions:
• RGB to Grayscale: Reduces the image to one channel by averaging the RGB values.
• RGB to HSV: Useful for color-based segmentation and filtering.
Example:
• Converting an RGB image to grayscale can be done using a weighted sum of the RGB
values: Grey = 0.2989 * R + 0.5870 * G + 0.1140 * B.
plt.imshow(rgb_image)
plt.title("RGB Color Model Example")
plt.show()
Conversion:
6.2.Basic Concepts
• Pixel Intensity: Refers to the brightness or color value of a pixel, typically represented
as a numerical value (e.g., grayscale intensity from 0 to 255).
• Intensity Transform Function: A mapping function (T) that assigns new intensity values
to pixels based on their original values.
Example:
Function:
6.3.4. Thresholding:
• Purpose: Converts grayscale image into binary image (black and white).
• Method: Pixels are classified as foreground (white) or background (black) based on a
threshold value.
• Example:
6.4.Implementation in Image Processing
6.7.Applications
Histogram processing is a crucial technique in the field of digital image processing. It involves
the manipulation of an image's histogram to enhance its visual quality. A histogram represents
the distribution of pixel intensities in an image. By understanding and modifying this
distribution, we can achieve various image enhancement goals, such as improving contrast and
brightness.
7.2.Understanding Histograms
• X-axis: Represents the intensity values (ranging from 0 to 255 for an 8bit grayscale
image).
• Y-axis: Represents the frequency (number of pixels) corresponding to each intensity
value.
For a grayscale image, the histogram gives a quick visual insight into the distribution of shades
of grey.
• Histogram Equalization
• Histogram Matching (Specification)
Histogram equalization is a technique used to improve the contrast of an image. This method
spreads out the most frequent intensity values, thereby increasing the global contrast of the
image. It's especially useful for images that are either too dark or too bright.
Example:
Consider a simple 3x3 grayscale image with the following pixel values:
• The histogram for this image would have high peaks at 50, 100, and 150.
• Calculate the CDF for these intensity values.
• Use the CDF to map the old intensity values to new ones, resulting in a more uniformly
distributed histogram.
Histogram matching aims to transform the histogram of an input image to match the histogram
of a target image. This technique is useful when we want to give one image the appearance of
another.
• Compute Histograms: Calculate the histograms for both the input and target images.
• Compute CDFs: Calculate the CDFs for both histograms.
• Map Intensity Values: Create a mapping from the input image's intensity values to the
target image's intensity values using their respective CDFs.
Example:
If we have an input image with a flat histogram and a target image with a bellshaped histogram:
7.4.Practical Example
Original Image:
Histogram:
100: 3 pixels
150: 3 pixels
200: 3 pixels
Histogram Equalization:
• Compute CDF:
o For 100: CDF = 3/9 = 0.33
o For 150: CDF = 6/9 = 0.67
o For 200: CDF = 9/9 = 1.00
New Image:
By examining the histograms before and after processing, we can see the impact of histogram
equalization. The original image has distinct peaks, while the processed image has a more
uniform distribution of pixel intensities, resulting in improved contrast.
8. Spatial Filtering
8.2.Basic Concepts
• Filter: A filter is a matrix (also called a kernel or mask) that is applied to an image to
produce a new image. The filter is typically smaller than the image and is moved across
the image to apply its effects.
• Linear Filters: These filters apply a linear transformation to the pixel values. Common
linear filters include:
o Averaging Filter (Mean Filter): Used for noise reduction by averaging the pixel values
within a neighbourhood.
o Gaussian Filter: A type of averaging filter that gives more weight to the central pixels,
producing a smoother blur.
o Laplacian Filter: Used for edge detection by highlighting areas of rapid intensity
change.
• Non-linear Filters: These filters apply a nonlinear transformation to the pixel values.
Common nonlinear filters include:
o Median Filter: Used for noise reduction by replacing each pixel value with the median
of the neighbouring pixel values. It is particularly effective for removing saltandpepper
noise.
o Max Filter: Replaces each pixel value with the maximum value in the neighborhood.
o Min Filter: Replaces each pixel value with the minimum value in the neighborhood.
8.4.Steps in Spatial Filtering
• Select a Filter: Choose an appropriate filter (kernel) based on the desired effect (e.g.,
smoothing, sharpening, edge detection).
• Define the Neighbourhood: Determine the size of the neighbourhood (e.g., 3x3, 5x5)
that the filter will operate on.
• Apply Convolution: Move the filter across the image, applying the convolution
operation at each pixel position to compute the new pixel value.
• Handle Border Pixels: Decide how to handle the borders of the image where the filter
extends beyond the edge. Common approaches include padding with zeros, replicating
the edge pixels, or wrapping around.
8.5. Examples
• Averaging Filter
An averaging filter smooths an image by averaging the pixel values within a neighbourhood.
For a 3x3 averaging filter, the kernel is:
When applied to an image, the filter computes the average of the pixel values in the 3x3
neighbourhood and assigns this average value to the central pixel.
• Gaussian Filter
A Gaussian filter provides a weighted average of the pixel values in a neighbourhood, with
weights determined by the Gaussian function. For a 3x3 Gaussian filter with a standard
deviation σ, the kernel might look like:
This filter smooths the image while preserving edges better than the simple averaging filter.
• Laplacian Filter
A Laplacian filter detects edges by highlighting areas of rapid intensity change. A common
3x3 Laplacian kernel is:
Applying this filter emphasizes edges and fine details in the image.
• Median Filter
A median filter replaces each pixel value with the median value of the neighbouring pixels.
For a 3x3 neighbourhood, if the pixel values are [10, 20, 30, 40, 50, 60, 70, 80, 90], the median
value is 50. This filter effectively removes salt-and-pepper noise.
8.6.Practical Considerations
• Kernel Size: Larger kernels provide more smoothing but can also blur important details.
The choice of kernel size depends on the specific application and desired outcome.
• Filter Weights: The weights of the filter determine its effect. For example, a Gaussian
filter with higher central weights will preserve more details while smoothing the image.
• Edge Handling: Proper handling of the image borders is crucial to avoid artifacts.
Padding with zeros, replicating edges, or other methods can be used to address this
issue.
9. Fourier Transforms and Its Properties
9.2.Basic Concepts
• Fourier Transform:
For a continuous signal f(t) the Fourier Transform F(ω) is defined as:
For a discrete signal f[n], the Discrete Fourier Transform (DFT) is defined as:
For a discrete signal, the Inverse Discrete Fourier Transform (IDFT) is:
• Linearity:
The Fourier Transform of a sum of signals is the sum of their Fourier Transforms.
If f(t) and g(t) have Fourier Transforms F(ω) and G(ω) respectively, then:
F{af(t)+bg(t)}=aF(ω)+bG(ω)
Example: For f(t)=cos(2πt) and g(t)=sin(2πt) the Fourier Transforms are:
F{cos(2πt)}=π[δ(ω−2π)+δ(ω+2π)]
F{sin(2πt)}=jπ[δ(ω−2π)−δ(ω+2π)]
• Shift:
Shifting a signal in the time domain results in a phase shift in the frequency domain.
If f(t) has a Fourier Transform F(ω), then:
F{f(t−t0)}=F(ω)e−jωt0
F{e−(t−t0)2}=e−jωt0F{e−t2}
• Scaling:
Scaling a signal in the time domain results in an inverse scaling in the frequency domain.
If F(t) has a Fourier Transform F(ω), then:
1
F{f(at)}=∣𝑎∣ 𝐹(𝜔/𝑎)
1
F{e−(at)2}= F{e−t2}
∣𝑎∣
• Convolution:
The convolution of two signals in the time domain corresponds to multiplication in the
frequency domain.
If f(t) and g(t) have Fourier Transforms F(ω) and G(ω), then:
F{f(t)∗g(t)}=F(ω)⋅G(ω)
Example: For f(t)=cos(2πt) and g(t)=sin(2πt), the convolution in the time domain is:
F{cos(2πt)∗sin(2πt)}=π[δ(ω−2π)+δ(ω+2π)]⋅jπ[δ(ω−2π)−δ(ω+2π)]
• Multiplication:
Multiplication of two signals in the time domain corresponds to convolution in the frequency
domain.
If f(t) and g(t) have Fourier Transforms F(ω) and G(ω), then:
1
F{f(t)⋅g(t)}= 2π(F∗G)(ω)
Example: For f(t)=cos(2πt) and g(t)=sin(2πt), the multiplication in the time domain is:
• Duality:
The Fourier Transform exhibits a duality property where the roles of the time and frequency
domains can be interchanged.
If f(t) has a Fourier Transform F(ω), then:
F{F(t)}=2πf(−ω)
• Parseval's Theorem:
Parseval's theorem states that the total energy of a signal in the time domain is equal to the total
energy in the frequency domain.
If f(t) has a Fourier Transform F(ω), then:
9.4.Applications
• Signal Analysis:
Fourier Transforms are used to analyse the frequency components of signals, helping
identify periodicities, harmonics, and other characteristics.
• Image Processing:
In image processing, the Fourier Transform is used for tasks such as filtering, image
compression, and edge detection. The 2D Fourier Transform is applied to images to
analyse their frequency content.
• Audio Processing:
In audio processing, the Fourier Transform helps analyse sound signals, detect
frequencies, and perform operations like equalization and noise reduction.
9.5.Examples
Example of Fourier Transform:
10.1. Introduction
In digital image processing, frequency domain filters and the Hough transformation are
powerful techniques used for different purposes. Frequency domain filters are applied to
manipulate the frequency content of an image, while the Hough transformation is a feature
extraction technique used to detect geometric shapes like lines and circles in an image.
• Frequency Domain:
o The frequency domain represents an image in terms of its frequency
components rather than its spatial components.
o Each point in the frequency domain corresponds to a specific frequency present
in the image.
• Fourier Transform:
o The Fourier Transform converts an image from the spatial domain to the
frequency domain.
o The Inverse Fourier Transform converts it back to the spatial domain.
10.5. Examples
• LowPass Filtering:
Consider an image with noise. Applying a Gaussian LowPass Filter can smooth the image and
reduce noise.
The filter function in the frequency domain is:
where D(u,v) is the distance from the origin in the frequency domain and D0 is the cutoff
frequency.
• High-Pass Filtering:
To enhance edges in an image, apply an Ideal High-Pass Filter.
The filter function in the frequency domain is:
where D(u,v) is the distance from the origin and D0 is the cutoff frequency.
Part 2: Hough Transformation
• Purpose:
The Hough transformation is used to detect geometric shapes, such as lines and circles,
in an image.
• Hough Space:
The Hough transformation maps points in the image space to curves in the Hough space
(parameter space).
• Equation of a Line:
In the Cartesian coordinate system, a line can be represented as y=mx+by = mx + by=mx+b.
Parameter Space Mapping: For each edge point (x,y), calculate the corresponding (ρ,θ), values
and vote in the accumulator array.
Peak Detection: Identify peaks in the accumulator array, which correspond to potential lines in
the image.
• Example:
Consider an image with several lines. Using the Hough transformation, each edge point votes
for all possible lines passing through it. Peaks in the Hough space indicate the presence of lines.
• Equation of a Circle:
o A circle with radius r and centre (a,b) can be represented as (x−a)2+(y−b)2=r2.
• Computational Complexity:
The Hough transformation can be computationally intensive, especially for large
images and complex shapes. Optimizations and efficient algorithms can be used to
speed up the process.
• Noise Sensitivity:
Frequency domain filtering can help reduce noise before applying the Hough
transformation to improve detection accuracy.
• Parameter Selection:
The choice of filter parameters (e.g., cutoff frequency) and Hough transformation
parameters (e.g., accumulator resolution) can significantly impact the results.
11.Image Noise and Restoration
11.1. Introduction
In digital image processing, noise refers to random variations in the pixel values of an image.
Noise can degrade the quality of an image, making it difficult to analyse and interpret. Image
restoration involves techniques to reduce or eliminate noise, aiming to recover the original,
clean image.
Additive Noise:
The noisy image g(x,y) is the sum of the original image f(x,y) and the noise n(x,y):
o Mean Filter:
➢ Averages the pixel values in a neighbourhood to smooth the image.
➢ Effective for Gaussian noise but can blur edges.
➢ Kernel example for a 3x3 mean filter:
o Median Filter:
➢ Replaces each pixel value with the median of the pixel values in the neighbourhood.
➢ Effective for salt-and-pepper noise.
➢ Example: For a 3x3 neighbourhood [10, 20, 30, 40, 50, 60, 70, 80, 90], the median is
50.
o Gaussian Filter:
➢ Weighs the pixel values in the neighbourhood according to a Gaussian distribution.
➢ Provides a smoother result than the mean filter.
➢ Kernel example for a 3x3 Gaussian filter:
where D(u,v) is the distance from the origin in the frequency domain.
Wiener Filter:
➢ Minimizes the mean square error between the estimated image and the original image.
➢ Adaptive filter that considers both the local image variance and the noise variance.
➢ Filter function:
where Sf(u,v) is the power spectral density of the original image and Sn(u,v) is the power
spectral density of the noise.
• Restoration Using Image Models: Assumes a model for the degradation and seeks to
invert it.
o Inverse Filtering:
➢ Directly inverts the degradation process.
➢ Suitable when the degradation function is known.
➢ Filter function:
1
H(u,v)= 𝐷(𝑢,𝑣)
o Regularized Filtering:
➢ Extends inverse filtering by incorporating a regularization term to handle noise and
other imperfections.
➢ Balances between fidelity to the degraded image and smoothness of the restored image.
➢ Regularization function:
where D*(u, v) is the complex conjugate of the degradation function, α is the regularization
parameter, and P(u, v) is the Fourier transform of the regularization term.
11.5. Examples
g(x,y)=f(x,y)⋅n(x,y),n(x,y)∼Multiplicative noise
Filtered Image=H(u,v)⋅G(u,v)
where H(u, v) is the Wiener filter function and G(u, v) is the Fourier transform
of the noisy image.
*******