Module 4: Image Restoration
Noise in Image
• The principal sources of noise in digital images arise during
image acquisition and/or transmission.
• The performance of imaging sensors is affected by a variety of
environmental factors. For instance, in acquiring images with
camera, light levels and sensor temperature are major factors
affecting the amount of noise in the resulting image.
• Images are corrupted during transmission principally by interference
in the transmission channel. For example, an image transmitted
using a wireless network might be corrupted by lightning or other
atmospheric disturbance.
•f(x,y) is the original image before any degradation occurs.
•The image passes through a system H (called the degradation
function).
•Degradation refers to deterministic distortions that occur to an image
during acquisition, transmission, or processing. Examples: Motion blur (due
to camera shake), Out-of-focus blur (due to lens), Atmospheric blur (in
satellite images)
•Noise refers to random, unpredictable variations in the pixel values of the
image. Examples: Electronic interference, Thermal noise in sensors
•The result after degradation and noise is:
•A restoration algorithm/filters are applied to g(x,y) to approximate
Noise Models
A noise model are like a mathematical fingerprint of the noise.
They describe the shape, size, and chance of different types of noise, so
we can understand and remove it from the image.
1) Gaussian noise
•Gaussian noise is a type of noise that is generated by adding random
values that are normally distributed with a mean of zero and a
standard deviation σ to the input data.
•Imagine you're capturing an image, and the sensor randomly adds tiny
values to each pixel.
These random values:
Are usually centered around 0 (mean = 0)
Most of them are small, but a few can be bigger
The amount of spread is controlled by standard deviation σ
•This kind of randomness follows a Gaussian (normal) distribution.
Here z is possible noise value
2) Rayleigh Noise
F(Probability Density Function) of Rayleigh noise is given by
gh noise is a type of noise where: The values start from a certain point (not f
se and then fall off quickly, And they never go below a certain value.
possible noise value
rting point (minimum value for noise)
ead/shape of the curve (like variance)
The probability of getting the value z as noise
•For values less than a the noise does not exist: p(z)=0
•For values greater than or equal to a:The function increases to a peak
Then decreases quickly (exponentially)
3) Erlang (Gamma) Noise
Erlang (Gamma) noise is a type of noise where the values are always
positive, and the noise is caused by the combined effect of many
small random events happening one after another. i.e Noise
occurs in steps or layers,” not all at once.
Think of it like raindrops hitting a surface — each drop adds a little, and
together they build up the total noise.
z is a possible noise value (like a raindrop size).
a controls how quickly the noise drops off.
b controls how many small effects are combining (more layers = bigger
Mean (average noise value)
noise).
Variance (how much it spreads)
4) Exponential Noise
Exponential noise is a type of noise
where:
All values are positive
Small noise values are very
common Let’s plug in a few values (assume a=1):
Large noise values are rare, but
Interpretati
•z:possible
possible noise value (initially starts at 0) z p(z)
on
•a: rate parameter (controls how fast the noise 0 drops) 1.00 Very likely
•p(z): probability of getting noise value z 1 0.367 Likely
2 0.135 Less likely
3 0.049 Rare
4 0.018 Very rare
Extremely
5 0.0067
5) Uniform Noise
•Uniform noise is a type of noise where every value within a certain
range has the same chance of being chosen
•It has constant probability between two limits: a and b
•Values outside the range have zero probability
6) Salt and Pepper Noise
•Salt and Pepper Noise is a type of noise seen in digital images where
random pixels are suddenly set to black (pepper) or white (salt), while
the rest of the image remains unchanged.
k = number of bits (e.g., 8 for 8-bit images)
2^k - 1 = maximum pixel value (255 in 8-bit)
Ps= probability of salt (white noise)
Pp= probability of pepper (black noise)
V = any normal pixel value (not corrupted)
Image Restoration in Spatial
•In spatial domain image restoration, we estimate the original image
Domain
f(x,y) from the noisy observation g(x,y), where:
g(x,y): noisy observed image
f(x,y): original (unknown) image
η(x,y): additive noise
•We apply spatial filtering techniques to estimate f(x,y).
•Spatial filtering is appropriate when only additive noise is present
This can be done using different
filters:
[Link] filters
[Link] mean
Mean filters are filter: filters that reduce noise by averaging
smoothing
the values of neighboring pixels. These filters are applied over a
window (or kernel) around each pixel.
•This computes the average of all pixels in a neighborhood centered at (x,y)
•m×n: dimensions of the filter window (e.g., 3×3, 5×5).
•g(r,c): pixel values in the noisy input image.
•r,c: window coordinate variables
•Sxy: neighborhood (region) around the point (x,y) over which the filter is
applied
•. restored image (filtered output)
b. Geometric mean filter
•Multiplies all pixel values in the neighborhood and takes the
mn-th root.
•Reduces the impact of outliers compared to arithmetic mean.
•Better at preserving edge details.
•Less image
c. Harmonic meandetails are lost using GMF as compared
filter: to AMF
•The harmonic mean filter
reduces the impact of
•m×n: dimensions of the filter window large pixel values
•g(r,c): pixel values in the noisy input image.
•r,c: window coordinate variables
•Sxy: Neighborhood (region) around the point (x,y) over which the filter is
applied
•. Restored image (filtered output)
•The harmonic mean filter reduces the impact of large pixel
values.
•It is good for Gaussian Noise and salt noise.
•It doesn't perform well on pepper noise (low-value noise),
because low values have a stronger influence on the harmonic mean.
Since one of the pixel values
is 0, the harmonic mean
becomes undefined (division
by zero)
import cv2
import numpy as np
import [Link] as plt
img = [Link]("input/noisy_image.png",
cv2.IMREAD_GRAYSCALE)
kernel_size = 3
pad = kernel_size // 2
padded = [Link](img, pad, pad, pad,
pad, cv2.BORDER_REPLICATE)
filtered_img = np.zeros_like(img,
dtype=np.float64)
for i in range([Link][0]):
for j in range([Link][1]):
region = padded[i:i+kernel_size,
j:j+kernel_size].astype(np.float64)
region[region == 0] = 1
denominator = [Link](1.0 / region)
if denominator != 0:
filtered_img[i, j] = (kernel_size *
kernel_size) / denominator
else:
filtered_img[i, j] = img[i, j] # fallback to
original pixel
# Show results
[Link](figsize=(10, 4))
[Link](1, 2, 1)
[Link](img, cmap='gray')
[Link]("Original (with noise)")
[Link](1, 2, 2)
[Link](filtered_img, cmap='gray')
[Link]("Harmonic Mean Filtered")
plt.tight_layout()
[Link]()
d. Contraharmonic mean filter:
• : Output (filtered) pixel value at
position (x,y) Q Behavior
•g(r,c): Input image intensity at location (r,c)
Removes pepper noise
•Sxy: Neighborhood (e.g., 3×3 window) around
Q>0 (i.e., very dark or 0-
pixel (x,y)
•Q: Order of the filter (controls what type of value pixels)
noise is suppressed) Removes salt noise
Q<0 (i.e., very bright or
255-value pixels)
Becomes Arithmetic
Q=0
Mean Filter
Q=− Becomes Harmonic
1 Mean Filter
) Order-Statistic Filters:
•These are non-linear filters used in image processing, particularly for
noise removal.
•They operate on a neighborhood (e.g., 3×3 window) and use
ranking (ordering) of pixel values rather than averaging.
Median Filter:
•This filter takes all pixel values in the window around (x, y) and sorts
them in ascending order to pick the middle value (median)
Max Filter
•Looks at the neighboring pixels and picks the largest value i.e it
finds the brightest points in the image
Min Filter
•Looks at the neighboring pixels and picks the smallest value i.e it
finds the dark points in the image
d . Midpoint filter
•Takes the maximum and minimum pixel values in the
neighborhood. Calculates the average of those two values. It is not
the full mean, just the average of extreme values.
•Best to deal with Gaussian and uniform noise
e. Alpha-trimmed filter
moves extreme values (outliers like salt & pepper noise).
ard d/2 smallest and d/2 largest values before averaging.
mean of the remaining values is computed and used as the output
:The sorted pixel values in the neighborhood (after trimming)
sider Input 3×3 Matrix
1) Flatten the matrix into a list
[10,10,255,10,10,10,0,10,10]
2) Sort the values: [0,10,10,10,10,10,10,10,255]
3) Choose d=2 (means trim 1 lowest and 1 highest
value) i.e 0 ,255
4) Apply Alpha-Trimmed Mean Formula for remaining
values
•The 0 (salt) and 255 (pepper) noise values are
discarded.
•The average is taken only from clean, consistent
values.
import cv2
import numpy as np
import [Link] as plt
# Read noisy image
img = [Link]("input/[Link]", cv2.IMREAD_GRAYSCALE)
# Zero padding for 5x5 filter
padded = [Link](img, 2, 2, 2, 2, cv2.BORDER_CONSTANT,
value=0)
output = np.zeros_like(img)
d = 4 # trim 2 lowest + 2 highest
ksize = 5
for i in range([Link][0]):
for j in range([Link][1]):
window = padded[i:i+ksize, j:j+ksize].flatten()
[Link]()
trimmed = window[d//2 : len(window) - d//2]
output[i, j] = [Link](trimmed)
# Display
[Link](figsize=(10,5))
[Link](1,2,1), [Link](img, cmap='gray'),
[Link]("Original (Noisy)")
[Link](1,2,2), [Link](output,
cmap='gray'), [Link]("Alpha-Trimmed (5x5,
d=4)")
[Link]()
3. Adaptive Filters:
• Filters discussed so far do not consider the local image
characteristics, such as noise level or intensity variation in different
parts of the image.
•Adaptive filters adjust their behavior based on local statistical
characteristics (like mean, variance) within a small region (filter
window or kernel).
•Provide better performance because they adapt to local image
a. Adaptive Local Noise Reduction Filter
variations.
• •But
The complicated
Adaptive Local Noise of
in terms Reduction Filterand
computation reduces noise by adapting to
implementation.
the local statistics (Local mean and Local variance) of the image
around each pixel.
•This filter is used to remove noise from images, especially when
the noise is not the same everywhere in the image.
•Here Mean represents a measure of average gray level in the
region
:Estimated value of the original pixel (x, y) after filterin
•Noise Variance( ) : It is the estimated strength of the noise in
the entire image. It is usually constant (does not change from pixel to
pixel).
•Local Variance( ): It is the variance (contrast) of pixel values in a
small local window around a pixel (like 3×3 or 5×5 block). It changes
from place to place in the image.
There is no noise in the image. No filtering is needed.
If local variance is much bigger than noise variance.
It assumes that the variation is due to real edges or details, n
So, we keep the pixel as it is to preserve the edge.
If local variance is almost equal to the noise level
It means this region is smooth, and that small variation is mainly due
So, we smooth it using the average of nearby pixels.
b. Adaptive median filter:
• The adaptive median-filtering algorithm uses two processing levels,
denoted level A and level B, at each point (x, y)
• Removes salt-and-pepper noise
• Reducing distortion (excessive thinning/thickening of object
boundaries)
INVERSE FILTERING
•Inverse filtering is a basic image restoration technique used to recover
an original image that has been degraded due to blurring or other
distortions.
•When H(u,v) is known, the simplest approach to restoration is direct
inverse filtering.
Steps in Inverse Filtering:
1. Model the Degradation Process: The observed (degraded) image
g(x,y) is represented as:
2. Frequency Domain Representation: Apply the Fourier Transform to
the equation, transforming the convolution into multiplication:
3. Formulate the Inverse Filter: Assuming noise N(u,v) is negligible,
the restored image in the frequency domain can be estimated as:
4. Apply Inverse Fourier Transform
Example : A 1D degraded signal g(x) = [1, 3, 3, 1]. Restore the
original signal f(x) when the blurring signal h(x) = [1, 1]
ep 1: Compute the 1D DFT of degraded signal
ompute the DFT of the blurring kernel with zero padding
ourier transform, zero-padding is done to make its length equal to the signal (len
pply Inverse Filtering : We recover the frequency representation of the origin
tep 4: Compute Inverse DFT of F(x)
•The inverse DFT matrix is:
MINIMUM MEAN SQUARE ERROR/
WEINER FILTERING
•The main limitation of inverse filtering is that it is very sensitive to
noise.
•In inverse filtering just divide the image by the blur function(H)
•Wiener filter does not reverse the blur blindly like inverse filtering.
•Wiener filter understands how much noise is there using statistical
tools, and adjusts the filtering accordingly.
•Wiener filtering, also known as minimum mean square error
filtering, uses statistical information about the signal and noise to
improve image restoration.
• It treats both images and noise as random processes.
•A random process means that image pixels and noise values are not
fixed but have wiener filtering treats them like probability-based data
•We want to recover the original image f from a corrupted image g,
which has been blurred and has noise added.
•So, we try to find an estimate of the original image such that the
mean square error between f and is as small as possible.
•The goal is to minimize the expected squared error between the
original and estimated signals
•The Wiener filter gives that estimate using
import cv2
import numpy as np
import [Link] as plt
from [Link] import wiener
image = [Link]('[Link]',
cv2.IMREAD_GRAYSCALE)
mean = 0
std_dev = 20
noise = [Link](mean, std_dev,
[Link])
noisy_img = [Link](np.float32) + noise
noisy_img = [Link](noisy_img, 0,
255).astype(np.float32)
filtered = wiener(noisy_img, (5, 5))
filtered = [Link](filtered, 0, 255).astype(np.uint8)
noisy_img_uint8 = noisy_img.astype(np.uint8)
[Link](figsize=(12, 4))
[Link](1, 3, 1), [Link]("Original")
[Link](image, cmap='gray')
[Link](1, 3, 2), [Link]("Noisy")
[Link](noisy_img_uint8, cmap='gray')
[Link](1, 3, 3), [Link]("Wiener Filtered")
[Link](filtered, cmap='gray')
1)
3
2)
4)
1)
2)
3)
4)
can be expressed as H(u,v)⋅ H∗(u,v). Now substitute this in
above formula:
If H=A+Bj (where A is the real part and B is the imaginary part), then
conjugate H∗=A−Bj.
Final Weiner Filter is
Apply
Image morphing
Image Morphing is an image processing technique used for the
metamorphosis(gradual transformation) from one image to another.
The idea is to get a sequence of intermediate images which when put
together with the original images would represent the change from one
image to the other.
•Since image blending is the same for all morphing algorithms, the
difference lies in the image warping process.
A morphing process consists of three
steps:
1. Warping (distortion)
2. Tweening (interpolation, interim
images)
[Link]
tep 1. Cross dissolving (cross-fading)
(distortion)
Warping is the transformation and distortion (stretching) of an image.
There are two ways to warp an image. They are
a. Forward Mapping
b. Reverse Mapping
a. Forward Mapping
In this method, each pixel in the source image is mapped to an
appropriate place in the destination image.
Thus, some pixels in the destination image may not be mapped.
We need interpolation to determine these pixel values.
b. Reverse Mapping
This method goes through each pixel in the destination image and
samples an appropriate source image pixel.
Thus, all destination image pixels are mapped to some source image
pixel.
This mapping has been used in the Beier/Neely line-morphing
Step 2. Tweening
method.
The second part of the morphing algorithm uses tweening.
This is a simple linear interpolation that transfers the position of each
point in the original image to its new position.
Warping assigns a new position in the target image to each point of
the original image. Tweening transfers each point in the original image
to the new position calculated by warping.
An animation can be generated by linear interpolation
ep 3. Cross dissolving (cross-fading)
After the geometry alignment it is possible to obtain a simple
metamorphosis transformation between the two objects by using linear
interpolation