UNIT-II
Image Filtering and Edge Detection
Introduction to Image Filtering
Image filtering is a fundamental process in image processing that involves
modifying or enhancing an image by manipulating its pixel values. The goal is
to either improve the quality of the image or to extract useful information from
it.
1. What is Image Filtering?
Image filtering involves applying a filter (also called a kernel or mask) to an
image to perform operations such as:
Smoothing (to reduce noise)
Sharpening (to enhance edges and fine details)
Edge Detection (to identify object boundaries)
Feature Extraction (to highlight specific characteristics like texture or
patterns)
The filter operates over a neighborhood of pixels and replaces the central pixel
with a new value based on a mathematical rule.
2. Purpose of Image Filtering
Noise Reduction: Remove unwanted variations or disturbances in pixel
values (e.g., from sensors or transmission).
Image Enhancement: Make specific features of an image clearer or
more visible.
Preprocessing for Analysis: Prepare the image for higher-level tasks
like segmentation, recognition, or tracking.
Edge and Boundary Detection: Identify the edges of objects in images,
useful in computer vision.
3. Types of Image Filtering
a. Linear Filters
Output is a linear combination of input pixel values.
Common linear filters:
o Mean Filter (smoothing)
o Gaussian Filter (blurring, low-pass)
o Laplacian Filter (edge enhancement)
b. Non-linear Filters
Output is a non-linear function of neighborhood pixel values.
Common non-linear filters:
o Median Filter (removes salt-and-pepper noise)
o Max/Min Filters
o Bilateral Filter (preserves edges while smoothing)
4. Domains of Filtering
Spatial Domain Filtering: Directly manipulates the image pixels using
kernels or masks (e.g., convolution).
Frequency Domain Filtering: Applies filtering after transforming the
image using Fourier Transform, focusing on specific frequency
components.
5. Filter Characteristics
Kernel Size: Determines how many neighboring pixels are considered.
Symmetry: Some filters are symmetric (e.g., Gaussian), affecting their
behavior.
Edge Handling: Techniques like zero-padding, replication, or reflection
are used to deal with borders of the image.
Conclusion
Image filtering is an essential technique for improving image quality and
extracting meaningful features. It forms the basis of many advanced image
processing operations, including noise reduction, object detection, and image
segmentation.
Spatial Domain Filtering:
Spatial Domain Filtering refers to image processing operations that are applied
directly on the pixels of an image. The value of each output pixel is modified
based on a function of its neighboring pixels, typically using a filter mask
(kernel).
1. What Is the Spatial Domain?
In the spatial domain, an image is represented as a grid of intensity values
(pixels), and filtering involves manipulating these pixel values using
operations such as convolution or correlation.
2. Basic Operation: Convolution
The most common spatial filtering operation is convolution, where a kernel (a
small matrix) is slid over the image, and at each position:
3. Types of Spatial Filters
a. Smoothing (Low-Pass) Filters
These filters reduce noise and minor variations in the image, resulting in a
blurred version.
Mean Filter: Averages pixel values in the neighborhood
Gaussian Filter: Weights central pixels more heavily; useful for
reducing Gaussian noise
b. Sharpening (High-Pass) Filters
These filters highlight edges and fine details by enhancing high-frequency
components.
Laplacian Filter: Uses second derivatives to detect rapid intensity
changes
Unsharp Masking: Subtracts a blurred version of the image from the
original
4. Edge Handling Techniques
When applying a filter to border pixels, you need a strategy for undefined
neighboring values:
Zero-padding: Assume outside pixels are 0
Replication: Repeat the nearest border pixel
Reflection: Mirror image at the borders
5. Applications
Noise removal
Image smoothing before compression
Edge and detail enhancement
Preparation for edge detection and segmentation
Frequency Domain Filtering:
Frequency Domain Filtering is a technique in image processing where
operations are performed on the Fourier transform of an image rather than
directly on its pixels. This approach is particularly useful for analyzing and
modifying the frequency components (such as texture, edges, and patterns) of
an image.
1. What is the Frequency Domain?
Every image contains spatial frequencies:
o Low frequencies correspond to smooth regions (slow changes in
intensity)
o High frequencies correspond to edges and fine details (rapid
changes)
The Fourier Transform converts an image from the spatial domain
(pixels) into the frequency domain (frequency components).
2. Why Use Frequency Domain Filtering?
Certain operations (e.g. large-scale smoothing or sharpening) are more
efficient or more intuitive in the frequency domain.
Easier to design filters that target specific frequency bands.
Ideal for applications like compression, image enhancement, and
feature extraction.
3. Steps in Frequency Domain Filtering
1. Transform the image from spatial to frequency domain using the Fast
Fourier Transform (FFT).
2. Multiply the Fourier-transformed image with a frequency domain filter.
3. Apply the inverse Fourier transform (IFFT) to convert the filtered
result back to the spatial domain.
Filtered Image=IFFT(FFT(Image)×Filter)
4. Common Frequency Domain Filters
a. Low-Pass Filters (Smoothing)
Allow low frequencies (smooth areas) to pass, block high frequencies
(edges, noise)
Used to blur or denoise images
Example: Ideal LPF, Gaussian LPF
b. High-Pass Filters (Sharpening)
Allow high frequencies (edges, details) to pass, block low frequencies
Used to enhance edges and fine structures
Example: Ideal HPF, Butterworth HPF
c. Band-Pass Filters
Allow a range of frequencies to pass, attenuating others
Useful for detecting specific patterns or textures
5. Types of Frequency Filters
Filter Type Characteristics Pros Cons
Ringing artifacts
Ideal Sharp cutoff in frequency Simple, effective
(Gibbs)
Smooth decay, no sharp No ringing, natural
Gaussian Less precise cutoff
cutoff blur
Balanced
Butterworth Tunable cutoff sharpness Moderate ringing
performance
6. Visualization
The magnitude spectrum of the FFT shows frequency content.
Frequencies are often shifted (centered) to bring low frequencies to the
center for analysis.
7. Applications
Image denoising
Texture analysis
Medical imaging (e.g., MRI)
Optical systems
Watermarking
Conclusion
Frequency domain filtering is a powerful alternative to spatial filtering,
especially when targeting specific frequency components. Although
conceptually more complex, it provides deeper control over image
characteristics and is widely used in advanced image processing tasks.
Non-Linear Filters in Image Processing
Non-linear filters are a class of filters where the output pixel value is not a
linear combination of the input pixel values. Instead, they apply non-linear
operations over a neighborhood of pixels to achieve specific effects, especially
noise reduction while preserving edges.
These filters are essential when linear filters (like mean or Gaussian) fail to
preserve important image features, particularly edges and details.
1. Why Use Non-Linear Filters?
Better at removing impulse noise (salt-and-pepper)
Preserve edges and fine details that linear filters often blur
Useful in real-world applications like medical imaging, biometric
systems, and video processing
2. Common Types of Non-Linear Filters
a. Median Filter
Replaces each pixel with the median value of its neighborhood.
Highly effective against salt-and-pepper noise.
Example (3x3 window):
Neighborhood: [34,36,35,120,128,130,255,255,0]→Median: 128
Advantages:
Removes extreme noise
Preserves edges better than mean filter
b. Max and Min Filters
Max Filter: Replaces pixel with maximum value in the neighborhood →
used for bright region enhancement
Min Filter: Replaces pixel with minimum value → used for dark
region enhancement
c. Mode Filter
Replaces pixel with the most frequent value in the neighborhood.
Useful for categorical or quantized images (e.g., binary images)
d. Adaptive Filters
Adjust their behavior based on local image statistics (e.g., variance)
E.g., Adaptive Median Filter: changes the window size depending on
the local noise characteristics
e. Bilateral Filter
Combines spatial proximity and intensity similarity.
Smooths the image while preserving edges.
Non-linear due to the multiplication of spatial and range kernels.
3. Comparison with Linear Filters
Feature Linear Filters Non-Linear Filters
Operation Type Convolution-based Order-statistics or custom
Edge Preservation Poor Good
Noise Removal Moderate Excellent (for impulse noise)
Complexity Lower Higher
4. Applications of Non-Linear Filters
Medical imaging: Enhance soft tissue structures while reducing noise
Surveillance: Clean video frames with environmental noise
Fingerprint and face recognition: Preserve fine biometric details
Satellite imaging: Denoising with edge retention
Conclusion
Non-linear filters offer powerful tools for enhancing image quality in noisy
environments. Their strength lies in noise suppression without sacrificing
important features like edges, making them vital in many real-world image
processing applications.
Sampling and Aliasing in Image Processing
Sampling and aliasing are fundamental concepts in digital image processing
that relate to how continuous images are converted into discrete digital form and
how this process can introduce distortions if not done carefully.
1. What is Sampling?
Sampling refers to the process of converting a continuous image (analog
signal) into a discrete image by taking measurements (samples) at regular
intervals in space (and sometimes time, for video).
In 2D image processing:
The image is divided into a grid, and each grid point corresponds to a
pixel.
The value of the pixel represents the image intensity at that point.
2. What is Quantization?
Often paired with sampling, quantization is the process of mapping sampled
values to a finite set of levels (e.g., mapping a grayscale value to 0–255). This
makes the image storable in digital memory.
3. What is Aliasing?
Aliasing is a type of distortion or artifact that occurs when the sampling rate is
too low to accurately capture the variations in the original signal (image).
This results in misrepresentation of high-frequency content, often appearing
as:
Moiré patterns
Jagged edges (staircase effect)
False patterns or textures
4. Nyquist Sampling Theorem
To avoid aliasing, you must sample at a rate at least twice the highest
frequency in the signal. This is known as the Nyquist rate:
If this condition is not met, high-frequency components are
misinterpreted as low-frequency ones, causing aliasing.
5. Anti-Aliasing (Prevention Techniques)
To prevent aliasing:
Pre-filter the image using a low-pass filter before sampling to remove
high-frequency content.
Use higher-resolution sampling (increased sensor density or DPI).
Bilinear or bicubic interpolation can reduce visible aliasing during
image scaling.
6. Visual Examples
Concept Effect
Undersampling Loss of detail, jagged lines
Aliasing Wavy patterns, false textures
Proper sampling Accurate, smooth image
7. Real-World Applications & Relevance
Digital cameras: Avoid aliasing in sensor design
Medical imaging: Accurate capture of anatomical structures
Computer graphics: Prevent jagged edges in 3D rendering
Remote sensing: Accurate sampling of Earth's surface
Conclusion
Sampling is the gateway from analog to digital imaging, and understanding
aliasing is critical to ensuring that digital images accurately reflect the real
world. Proper sampling rate and anti-aliasing techniques are essential to
maintain image quality and avoid artifacts.
Edge Detection Concepts:
Edge detection is a key technique in image processing and computer vision
used to identify points in an image where brightness changes sharply.
These points typically correspond to object boundaries, surface
discontinuities, or changes in material properties.
1. What is an Edge?
An edge is defined as a significant local change in intensity (gray level) in an
image. It represents the boundary between different regions, such as between
two objects or between an object and the background.
2. Purpose of Edge Detection
Object detection and recognition
Image segmentation
Feature extraction
Scene analysis and interpretation
Edges simplify the image by reducing it to lines or curves that describe shape
and structure.
3. Characteristics of Edges
Location: Where the edge occurs
Magnitude: How sharp or strong the edge is (rate of intensity change)
Orientation: Direction of the edge (horizontal, vertical, diagonal)
4. Types of Edges
Type Description
Step Edge Sudden and large intensity change
Ramp Edge Gradual intensity change across several pixels
Roof Edge Thin peak in intensity, useful for ridges
Ridge Edge Line-like structures, often in textures
5. Edge Models:
First Derivative (Gradient-based):
Measures the rate of change in pixel intensity.
Produces thick edges, may need thinning.
Operators: Sobel, Prewitt, Roberts
Second Derivative (Laplacian-based):
Measures change in the rate of intensity change.
Produces zero-crossings at edge centers.
Operator: Laplacian of Gaussian (LoG)
6. Challenges in Edge Detection
Noise sensitivity: Edges can be distorted or hidden by noise.
Weak edges: Subtle changes might not be detected.
Edge localization: Accurately placing edges at true boundaries is
difficult.
Threshold selection: Choosing intensity change levels to classify edges
can be tricky.
7. Desired Properties of a Good Edge Detector
Good detection: Accurately identify all real edges
Good localization: Edges should be as close as possible to the true
boundaries
Minimal response: One response per edge (avoid false positives)
8. Edge Detection vs. Boundary Detection
Edge Detection: Identifies changes in intensity (low-level feature)
Boundary Detection: Higher-level process that connects edge points to
form complete object contours
Conclusion
Edge detection is a crucial step in image analysis that helps reduce visual data
while preserving meaningful structural content. Understanding the concepts
behind edge formation, types, and detection strategies is foundational for many
advanced applications like object tracking, recognition, and scene
understanding.
Gradient-Based Edge Detection
Gradient-based edge detection is one of the most widely used techniques in
image processing to detect edges by calculating the gradient (rate of change)
of intensity in an image. It identifies edges where the change in pixel intensity
is the highest, which typically corresponds to object boundaries.
1. What is a Gradient?
The gradient of an image is a vector that points in the direction of the
maximum rate of intensity change.
It has two components:
o Magnitude – how strong the edge is
o Direction – the angle of the edge
2. Gradient Magnitude and Direction:
3. Common Gradient Operators
These operators use convolution kernels to approximate derivatives:
Operator Kernels Used (for xx and yy) Notes
Combines smoothing with Most popular; noise
Sobel
differentiation resistant
Prewitt Similar to Sobel but simpler kernels Good for general use
Operator Kernels Used (for xx and yy) Notes
Uses 2×2 kernels;
Roberts Sensitive to noise
detects diagonals well
4. Edge Map Generation Steps
1. Apply Gx and Gy kernels to the image.
2. Compute gradient magnitude ∣∇f∣
3. (Optional) Threshold the magnitude to highlight strong edges.
4. (Optional) Use non-maximum suppression for thin edges.
5. Advantages
Detects both magnitude and orientation of edges
Effective for images with smooth intensity transitions
Simple and computationally efficient
6. Limitations
Sensitive to noise, especially with small kernels
Might detect false edges in textured or noisy areas
Threshold selection for edge maps can be challenging
Conclusion
Gradient-based edge detection is a foundational approach in image analysis that
identifies meaningful structural changes in intensity. Techniques like Sobel and
Prewitt provide a good balance of performance and simplicity, making them
widely used in practice.
Canny Edge Detection Algorithm:
The Canny Edge Detection Algorithm is a multi-stage edge detection
technique developed by John F. Canny in 1986. It is one of the most popular
and effective edge detection algorithms, known for its ability to detect strong
and weak edges while maintaining low noise sensitivity and accurate
localization.
Objectives of the Canny Algorithm
Canny designed his algorithm to meet the following criteria:
1. Good detection – accurately identify real edges
2. Good localization – edge location should be as close as possible to the
actual edge
3. Minimal response – a single edge should not result in multiple edge
responses
Stages of the Canny Edge Detection Algorithm
1. Noise Reduction
Apply a Gaussian filter to smooth the image and reduce noise.
This step helps prevent false edge detection due to random noise.
2. Gradient Calculation
Compute the intensity gradient of the image using a derivative operator
(like Sobel).
Calculate:
o Gradient magnitude: strength of the edge
o Gradient direction: angle of the edge
3. Non-Maximum Suppression
Thin the edges to 1-pixel wide by suppressing non-maximum pixels in
the direction of the gradient.
Keeps only the local maxima in the gradient direction.
Without this step, the edges would appear thick or blurred.
4. Double Thresholding
Apply two thresholds:
o High threshold (T₁): strong edges
o Low threshold (T₂): weak edges that are connected to strong ones
Pixels are classified as:
Strong edge: gradient > T₁
Weak edge: T₂ < gradient < T₁
Non-edge: gradient < T₂
5. Edge Tracking by Hysteresis
Final edge image is produced by tracking weak edges that are
connected to strong edges.
Isolated weak edges are removed; connected ones are retained.
Canny Edge Detection Summary
Step Purpose
1. Gaussian Smoothing Reduce noise
2. Gradient Computation Detect edge strength and direction
3. Non-Maximum Suppression Thin the edges
4. Double Thresholding Separate strong, weak, and non-edges
5. Edge Tracking (Hysteresis) Keep weak edges connected to strong ones
Advantages of Canny Edge Detection
✅ Excellent edge detection quality
✅ Low false detection rate
✅ Good localization and thin edges
✅ Effective in noisy images
Limitations
Computationally more expensive than simpler filters (e.g., Sobel)
Requires tuning of parameters (e.g., thresholds, Gaussian kernel size)
Applications
Object detection
Medical imaging
Lane detection in self-driving cars
Fingerprint recognition
OCR (Optical Character Recognition)
Boundary Detection Techniques in Image Processing
Boundary detection is a higher-level image analysis technique that involves
identifying the complete outline or contour of objects in an image, going
beyond mere edge detection. It is crucial for object segmentation, recognition,
and scene understanding.
1. Difference Between Edge and Boundary Detection
Feature Edge Detection Boundary Detection
Output Points of intensity change Continuous curves outlining objects
Scope Local (pixel-level changes) Global (object-level structure)
Goal Detect edge points Connect edges into meaningful contours
Use Case Feature extraction Shape analysis, segmentation
2. Common Boundary Detection Techniques
✅ 1. Edge Linking
Connects edge points detected (e.g., via Canny or Sobel) to form object
boundaries.
Uses criteria like gradient direction, intensity continuity, or proximity.
Methods:
Chain Code: Encodes the direction of connected edge pixels
Hough Transform: Detects shapes like lines and circles from edge
points
2. Edge Hysteresis
Part of the Canny algorithm that links weak edges to strong edges
based on connectivity.
Helps form complete and accurate boundaries by avoiding broken
edges.
3. Contour Following (Border Tracing)
Traces the boundary pixels of objects starting from a seed point.
Algorithms:
o Moore-Neighbor Tracing
o Suzuki’s Algorithm (OpenCV’s findContours)
Result: Each object’s boundary is identified as a closed polygon.
4. Region-Based Segmentation
Divides the image into regions and then finds boundaries between them.
Techniques:
o Region growing: Starts from seed pixels and expands to neighbors
with similar properties
o Watershed algorithm: Treats the image like a topographic
surface; boundaries are ridges
5. Graph-Based Methods
Models image as a graph with pixels as nodes and similarity as edge
weights.
Finds boundaries by partitioning the graph:
o Normalized Cuts
o Minimum Cut/Max Flow
6. Active Contours (Snakes)
Uses an initial curve (snake) that moves under image forces and internal
smoothness constraints to lock onto object boundaries.
Good for smooth, well-defined shapes
7. Deep Learning-Based Approaches
Use CNNs or transformer models to learn and detect object boundaries
automatically.
Examples:
o Mask R-CNN for instance segmentation
o U-Net for biomedical image boundary detection
Applications of Boundary Detection
Medical imaging (tumor or organ boundary extraction)
Object recognition and classification
Face and fingerprint recognition
Industrial inspection and quality control
Autonomous vehicle vision systems
Challenges
Boundaries in noisy or textured regions may be difficult to detect
Disconnected edges lead to incomplete boundaries
Occlusion and low contrast between objects and background
Conclusion
Boundary detection is a critical step in advanced image understanding. It
leverages and extends edge detection to produce complete, connected outlines
of objects, enabling meaningful segmentation and recognition in a wide variety
of applications.