0% found this document useful (0 votes)
10 views35 pages

Image Preprocessing Techniques Explained

The document discusses various image preprocessing techniques, focusing on image enhancement, noise reduction, and sharpening methods. It details common techniques such as histogram equalization, Gaussian filtering, and median filtering, along with their applications and effects on image quality. Additionally, it covers sharpening techniques like the Laplacian and high-pass filters to enhance image clarity and edge definition.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
10 views35 pages

Image Preprocessing Techniques Explained

The document discusses various image preprocessing techniques, focusing on image enhancement, noise reduction, and sharpening methods. It details common techniques such as histogram equalization, Gaussian filtering, and median filtering, along with their applications and effects on image quality. Additionally, it covers sharpening techniques like the Laplacian and high-pass filters to enhance image clarity and edge definition.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

Image

Preprocess
ing
Image
Preprocessing
Techniques
Image enhancement
techniques
• Used to improve the visual appearance
of an image or to make certain features
more distinguishable.
• Making images more visually
appealing.
• Bringing out specific features.
• Removing noise from images.
• Highlighting interesting details in
images.
Common image enhancement
techniques
• Histogram Equalization
• Contrast Stretching
• Smoothing
• Sharpening
• Noise Reduction
• Edge Enhancement
• Gamma Correction
• Image Inversion
• Bilateral Filtering
• Color Enhancement
• Morphological Operations
Understanding histograms
• Image histogram:
• Graphical representation of the distribution of pixel intensities in an image.
• It plots the number of pixels (frequency) for each intensity value, typically ranging
from 0 (black) to 255 (white) for 8-bit grayscale images.
• Low contrast images:
• In images with low contrast, the histogram is often clustered in a narrow range of
intensity values.
• This clustering results in an image where details are difficult to distinguish, as
there is little variation in brightness.
Histogram
of dark
and
bright
images
Histogram
of low-
contrast
and high-
contrast
images
How Histogram Equalization Works
• Calculation of Cumulative Distribution Function (CDF):
• The CDF is a cumulative sum of the histogram values, which shows the
cumulative probability of intensity values up to a certain level.
• Mapping Intensities:
• The CDF is then normalized to span the full intensity range of the image (e.g., 0
to 255 for an 8-bit image).
• This normalization maps the original pixel intensities to new intensity values that
are spread more evenly across the entire range.
• Transforming the Image:
• Finally, each pixel in the original image is transformed based on the normalized
CDF.
• The result is an image with a more uniform distribution of intensities, leading to
improved contrast.
Comparison of images before and after
histogram equalization
Comparison of images before and after
histogram equalization
Comparison of images before and after
histogram equalization
• Histogram Before Equalization:
• The histogram is narrow, showing a limited range of intensity values.
• After Histogram Equalization:
• The pixel intensities are spread out across the entire range, from 0 to 255.
• The resulting image has higher contrast, making previously hidden details more
visible.
Noise Reduction
• Techniques used to remove or minimize unwanted random variations in
pixel intensity, known as noise, from an image.
• Noise can be introduced during image acquisition, transmission, or
processing, and it can degrade the quality of an image, making it difficult
to interpret or analyze.
Types of Noise – Gaussian Noise
• It is characterized by random variations in intensity that follow a bell
curve distribution.
• Appearance: Appears as fine, grainy variations in intensity across the
image.
• Source: Often caused by thermal noise in sensors or electronic
interference.
Types of Noise – Salt and Pepper
Noise
• Salt-and-pepper noise appears as random occurrences of black and
white pixels in an image.
• Appearance: The image is dotted with bright and dark spots.
• Source: Typically caused by faulty pixels in camera sensors, bit errors
in transmission, or image scanning.
Types of Noise – Speckle Noise
• A granular noise that typically occurs in coherent imaging systems, such
as ultrasound or radar.
• Appearance: The noise looks like granular spots that degrade image
quality, especially in medical imaging.
• Source: Caused by interference between multiple wavefronts.
Noise Comparison
Noise reduction and filtering
• Filtering image data is a standard process used in almost every image
processing system.
• Filters remove noise from images by preserving the details of the same.
• Filters can be divided into two types : Time domain and Frequency
domain
Gaussian Filter
• A type of low-pass filter that uses a Gaussian function to weight the
pixel values in the neighborhood.
• Effect: Reduces Gaussian noise while preserving image structure
better than the mean filter.
• Application: Used in various applications, including photography, video
processing, and computer vision, to reduce noise before further
processing.
Code to apply Gaussian Filter
• import cv2
• from [Link] import cv2_imshow
• # Load noisy image
• img = [Link]('/content/[Link]')
• # Apply Gaussian blur
• # (kernel size must be odd, e.g., (5,5); larger kernel = stronger smoothing)
• # [Link](src, ksize, sigmaX) where ksize is kernel size, sigmaX is standard
• # deviation in X direction
• denoised = [Link](img, (5, 5), 0)

# Show results
• cv2_imshow(img) # Original noisy image
• cv2_imshow(denoised) # Denoised image
Mean Filter
• Reduces noise by averaging the pixel values within a specified
neighborhood. Each pixel is replaced by the mean of its neighboring
pixels.
• Effect: Effective at reducing Gaussian noise, but it can blur edges.
• Application: Simple noise reduction in images where preserving edges
is less critical.
Code to apply Mean Filter
• import cv2
• from [Link] import cv2_imshow
# Load noisy image
• img = [Link]('/content/[Link]')
# Apply Mean filter (average blurring)
# (kernel size must be odd; larger kernel = stronger smoothing)
• denoised = [Link](img, (5, 5))
# Show results
• cv2_imshow(img) # Original noisy image
• cv2_imshow(denoised) # Denoised image
Median Filter
• Reduces noise by replacing each pixel value with the median value of
the pixels in its neighborhood.
• Effect: Particularly effective against salt-and-pepper noise.
• Application: Used in scenarios where edge preservation is important,
such as in medical imaging or document processing.
Code to apply Median Filter
• import cv2
• from [Link] import cv2_imshow
# Load noisy image
• img = [Link]('/content/[Link]')
# Apply Median filter
# Kernel size must be odd (3, 5, 7, ...)
• denoised = [Link](img, 5)
# Show results
• cv2_imshow(img) # Original noisy image
• cv2_imshow(denoised) # Denoised image
Bilateral Filter
• Reduces noise while preserving edges by considering both spatial
proximity and intensity differences. It combines Gaussian filtering with
edge preservation.
• Effect: Reduces noise without blurring edges, making it ideal for
images with important edge information.
• Application: Commonly used in photography, medical imaging, and
other fields where edge preservation is crucial.
Code to apply Bilateral Filter
• import cv2
• from [Link] import cv2_imshow

• # Load noisy image


• img = [Link]('/content/[Link]')

• # Apply Bilateral Filter


• # Parameters: (image, diameter, sigmaColor, sigmaSpace)
• denoised = [Link](img, d=9, sigmaColor=75, sigmaSpace=75)

• # Show results
• cv2_imshow(img) # Original noisy image
• cv2_imshow(denoised) # Denoised image
Wiener Filter
• An adaptive filter that minimizes the mean square error between the
estimated and true image. It is particularly useful in reducing additive
noise.
• Effect: Particularly useful in reducing additive noise.
• Application: Often used in image restoration, especially in the
presence of Gaussian noise.
Code to apply Wiener Filter
• import cv2
• import numpy as np
• from [Link] import wiener
• from [Link] import cv2_imshow

• # Load noisy image (grayscale for Wiener filter)


• img = [Link]('/content/[Link]', cv2.IMREAD_GRAYSCALE)

• # Apply Wiener filter


• # mysize = window size, defaults to (3, 3) if not specified
• denoised = wiener(img, mysize=(5, 5))

• # Convert back to uint8 for display (Wiener output is float64)


• denoised = np.uint8([Link](denoised, 0, 255))

• # Show results
• cv2_imshow(img) # Original noisy image
• cv2_imshow(denoised) # Denoised image using Wiener filter
Best suited filters for noise
Image Sharpening
• A technique used to enhance the edges and fine details in an image,
making them more distinct and clearer.
• The sharpened image is that in which the edges are clearly
distinguishable by the viewer.
• Usually, the intensity and contrast change at the edge. If this change is
significant then the image is said to be sharp. The viewer can clearly
see the background and foreground parts.
Common Sharpening Techniques
• Unsharp Masking
• Laplacian Filter
• High-Pass Filter
• Gradient-based methods (Sobel, Prewitt, Roberts)
Laplacian Filter
• Used in image sharpening to enhance the edges and fine details by
emphasizing regions of rapid intensity change (such as edges).
• It works by highlighting the parts of the image where the intensity values
change the most, which typically occur at object boundaries or
transitions between different textures.
• Laplacian filter is a second-order derivative filter that calculates the rate
of change in intensity in all directions (x and y).
Effects of Laplacian Filter
• Edge Enhancement: The Laplacian filter enhances edges by amplifying the high-
frequency components in the image.
• Improved Clarity: Adding the Laplacian result to the original image increases the
contrast around edges, making details and transitions between different regions
clearer.
High-Pass Filter
• An image processing technique used to enhance the sharpness of an
image by allowing high-frequency components (such as edges and fine
details) to pass through while attenuating the low-frequency components
(smooth or uniform regions).
• This makes the high-pass filter particularly useful for edge detection and
image sharpening.
Working of High-Pass Filter
• High Frequencies (Edges and Fine Details):
• High-frequency components correspond to areas in the image where there is a
rapid change in intensity, such as edges or textures.
• Low Frequencies (Smooth Areas):
• Low-frequency components correspond to smooth or gradually varying areas of
the image, such as backgrounds or large uniform regions.
• A high-pass filter emphasizes the high-frequency components (edges
and fine details) and suppresses the low-frequency components (smooth
areas), making the image sharper.
Effects of High-Pass Filter

You might also like