You are on page 1of 92

UNIT III

IMAGE ENHANCEMENT &


RESTORATION-
SKSMPC22 - DIGITAL IMAGE PROCESSING-SP$

17-12-2021 DIP-SOCS-$P$ 1
IMAGE ENHANCEMENT
• Histogram Equalization modification and specification
• Spatial averaging
• Directional Smoothing
• Median

• Frequency Domain Enhancement: Low Pass, High Pass

17-12-2021 DIP-SOCS-$P$ 2
IMAGE ENHANCEMENT-
Introduction
• Image enhancement is the procedure of improving the quality and
information content of original data before processing

• Process of manipulating the image to that the result is more


suitable than the original for specific applications

• It highlights or sharpens image features such as edges, boundaries, or


contrast to make a graphic display more helpful for display and analysis

17-12-2021 DIP-SOCS-$P$ 3
IMAGE ENHANCEMENT-
Introduction
• Image enhancement includes gray level and contrast manipulation, noise
reduction, edge crispening and sharpening, filtering, interpolation and
magnification, pseudocolouring, and so on

• The greatest difficulty in image enhancement is quantifying the criterion


for enhancement. Therefore, a large number of image enhancement
techniques are empirical and require interactive procedures to obtain
satisfactory results

• Image enhancement remains a very important topic because of its


usefulness in virtually all image processing applications
17-12-2021 DIP-SOCS-$P$ 4
IMAGE ENHANCEMENT-
Introduction
• Example: Low-Light Image Enhancement

Matlab codes: https://www.mathworks.com/help/images/low-light-image-enhancement.html

Python Code: https://towardsdatascience.com/image-enhancement-techniques-using-opencv-and-python-9191d5c30d45


17-12-2021 DIP-SOCS-$P$ 5
IMAGE ENHANCEMENT-
Introduction
Image enhancement techniques can be divided into two broad categories:

Image Enhancement

Spatial Domain Frequency Domain

17-12-2021 DIP-SOCS-$P$ 6
IMAGE ENHANCEMENT-
Introduction
Image enhancement techniques can be divided into two broad categories:

Image Enhancement

Spatial Domain Frequency Domain


•Enhancement the image space that divides an image into •Enhancement obtained by applying the Fourier
uniform pixels according to the spatial coordinates with a Transform to the spatial domain. In the frequency
certain resolution. The spatial domain methods perform domain, pixels are operated in groups as well as
operations on pixels directly indirectly.
17-12-2021 DIP-SOCS-$P$ 7
IMAGE ENHANCEMENT

17-12-2021 DIP-SOCS-$P$ 8
HISTOGRAM

17-12-2021 DIP-SOCS-$P$ 9
HISTOGRAM
• A histogram is a statistical representation of an image
• It doesn’t show any information about where the pixels are located in
the image. Therefore, two different images can have equivalent
histograms

For example, the two images here are different but have identical
histograms because both are 50% white (grayscale value of 255) and
50% black (grayscale value of 0)

17-12-2021 DIP-SOCS-$P$ 10
HISTOGRAM
• In image processing, a histogram shows the number of pixels (or voxels
in the case of a 3D image) for each intensity value in a given image

17-12-2021 DIP-SOCS-$P$ 11
HISTOGRAM
• The histogram of an image represents the relative frequency of
occurrence of the various gray levels in the image

17-12-2021 DIP-SOCS-$P$ 12
HISTOGRAM

17-12-2021 DIP-SOCS-$P$ 13
HISTOGRAM

Keep in Mind

17-12-2021 DIP-SOCS-$P$ 14
HISTOGRAM
• Histogram modelling has been found to be a powerful technique for
image enhancement

• Histogram Equalization

• Histogram Modification

• Histogram Specification

17-12-2021 DIP-SOCS-$P$ 15
HISTOGRAM
Modelling
• Histogram-modelling techniques modify an image so that its histogram has a
desired shape.

• This is useful in stretching the low-contrast levels of images with narrow


histograms.

• Histogram can be plotted in two ways:


• X axis has gray levels & Y axis has number of pixels in each gray level
• X axis has gray levels & Y axis has probability occurrence of gray level

17-12-2021 DIP-SOCS-$P$ 16
HISTOGRAM
Modelling
• Histogram can be plotted in two ways:#1
X axis has gray levels & Y axis
has number of pixels in each
gray level

17-12-2021 DIP-SOCS-$P$ 17
HISTOGRAM
Modelling
• Histogram can be plotted in two ways:#2

X axis has gray levels & Y axis


has probability occurrence of
gray level

P(μk) = nk / n
μk - gray level
nk - Number of pixels in kth gray level
n - Total number of pixels in an image

17-12-2021 DIP-SOCS-$P$ 18
HISTOGRAM EQUALIZATION

17-12-2021 DIP-SOCS-$P$ 19
Histogram Equalization
• In histogram equalization (also known as histogram flattening)

• The goal is to improve contrast in images that might be either blurry or have
a background and foreground that are either both bright or both dark

• Histogram equalization helps sharpen an image

17-12-2021 DIP-SOCS-$P$ 20
Histogram Equalization
• Low contrast images typically have histograms that are concentrated within a tight range
of values

• Histogram equalization can improve the contrast in these images by spreading out the
histogram so that the intensity values are distributed uniformly over a larger intensity
range

• Ideally, the histogram of the output image will be perfectly flat.

Histogram equalization is useful in a number of real-world use cases, such


as x-rays, thermal imagery, and satellite photos

17-12-2021 DIP-SOCS-$P$ 21
Histogram Equalization
The two images below are two examples of what the histogram for an input
image might look like before and after it goes through histogram equalization.

17-12-2021 DIP-SOCS-$P$ 22
Histogram Equalization
• Aims to obtain a uniform histogram for the output image

• Linear stretching is a good technique but not perfect since the shape remains the same

• Most of the time we need a flat histogram

• It can’t be achieved by Histogram Stretching

• Thus, new technique of Histogram Equalization came into use

• Perfect image is one where all gray levels have equal number of pixels

• Here, our objective is not only to spread the dynamic range but also to have equal pixels at all
gray levels.

17-12-2021 DIP-SOCS-$P$ 23
Histogram Equalization
• We have to search for a transform that converts any random
histogram into flat histogram.
S = T(r)
• We have to find ‘T’ which produces equal values in each gray
levels
• The Transform should satisfy two conditions:
(i) T(r) must be single value & monotonically increasing
in the interval, 0 ≤ r ≤ 1.
(ii) 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1
0 ≤ S ≤ 1 for 0 ≤ r ≤ 1
Here, range of r is [0, 1] (Normalized range) instead of [0, 255].

17-12-2021 DIP-SOCS-$P$ 24
Histogram Equalization

17-12-2021 DIP-SOCS-$P$ 25
Histogram Equalization

Applied
Histogram
equalisation

17-12-2021 DIP-SOCS-$P$ 26
Histogram Equalization

Applied
Histogram
equalisation

17-12-2021 DIP-SOCS-$P$ 27
HISTOGRAM MODIFICATION
• Stretch • Shrink • Slide

17-12-2021 DIP-SOCS-$P$ 28
Histogram Modification
• The histogram can be modified by a mapping function
which will stretch, shrink or slide the histogram
• This will change the contrast or brightness of the image

17-12-2021 DIP-SOCS-$P$ 29
Histogram Modification
The graphical representation of histogram stretch

17-12-2021 DIP-SOCS-$P$ 30
Histogram Modification
The graphical representation of histogram Shrink

17-12-2021 DIP-SOCS-$P$ 31
Histogram Modification
The graphical representation of histogram Slide

17-12-2021 DIP-SOCS-$P$ 32
Histogram Modification
STRECH
The mapping equation for histogram stretch:

17-12-2021 DIP-SOCS-$P$ 33
Histogram Modification

• This equation will take an image and stretch the histogram


across the entire gray-level range
o This will increase the contrast of a low-contrast image

• If a stretch is desired over a smaller range, different MAX and


MIN values can be specified

17-12-2021 DIP-SOCS-$P$ 34
Histogram Modification

17-12-2021 DIP-SOCS-$P$ 35
Histogram Modification

17-12-2021 DIP-SOCS-$P$ 36
Histogram Modification
SHRINK

• The opposite of histogram stretch is a histogram shrink,


which will decrease image contrast by compressing the
gray levels
• The histogram shrinking equation is generally the same as
the one for stretching
• But for histogram shrinking, MAX and MIN should be set to the maximum
and minimum of the new, compressed range.

17-12-2021 DIP-SOCS-$P$ 37
Histogram Modification

17-12-2021 DIP-SOCS-$P$ 38
Histogram Modification
SHRINK

17-12-2021 DIP-SOCS-$P$ 39
Histogram Modification
SHRINK

• In general, histogram shrink reduces contrast and may


not seem to be useful as image enhancement tool

• However, there is an image-sharpening technique


algorithm that uses the histogram shrink process as a
part of the enhancement technique

17-12-2021 DIP-SOCS-$P$ 40
Histogram Modification
SLIDE

The histogram slide technique can be used to make an


image either darker or lighter.
Darker: slide histogram towards low end.
Lighter: slide histogram towards high end.
Histogram slide is done by adding or subtracting a fixed
number from all the gray-level values.

17-12-2021 DIP-SOCS-$P$ 41
HISTOGRAM SPECIFICATIONS
• While the goal of histogram equalization is to produce an output
image that has a flattened histogram,
• The goal of histogram Specifications (matching) is to take an input
image and generate an output image that is based upon the shape of a
specific (or reference) histogram
• Histogram Specification is also known as histogram Matching
• Histogram equalization can be considered as a special case of
histogram matching
in which we want to force an image to have a uniform histogram (rather than
just any shape as is the case for histogram matching)

17-12-2021 DIP-SOCS-$P$ 42
HISTOGRAM SPECIFICATIONS

17-12-2021 DIP-SOCS-$P$ 43
HISTOGRAM SPECIFICATIONS

17-12-2021 DIP-SOCS-$P$ 44
HISTOGRAM SPECIFICATIONS

17-12-2021 DIP-SOCS-$P$ 45
Spatial averaging
• Many image enhancement techniques are based on spatial operations
performed on local neighbourhoods of input pixels.

• The image is convolved with a finite impulse response filter called


spatial mask.

• where y(m, n) and v(m, n) are the


input and output images
• W is a suitably chosen window, and
a (k, l) are the filter weights

17-12-2021 DIP-SOCS-$P$ 46
Spatial averaging
• Each pixel is replaced by its average with the average of its nearest
four pixels

17-12-2021 DIP-SOCS-$P$ 47
Spatial averaging
 Spatial averaging is used for noise smoothing, low-pass filtering, and sub-sampling
of images
◦ Suppose the observed image is given as
y(m,n) = u(m,n) + η(m,n)
◦ where η(m,n) is white noise with zero mean and variance σ2ᶯ
◦ where η¯(m, n) is the spatial average of η(m,n) It is a simple matter to show that
η¯(m, n) has zero mean and variance σ2ᶯ/ Nw
◦ If the noiseless image u(m, n) is constant over the window W, then spatial
averaging results in an improvement in the output signal-to-noise ratio by a factor
of Nw.

17-12-2021 DIP-SOCS-$P$ 48
Spatial averaging

◦ The size of the window W is limited


due to the fact that u (m, n) is not
really constant

◦ Spatial averaging introduces a


distortion in the form of blurring

17-12-2021 DIP-SOCS-$P$ 49
Directional Smoothing
In practice the size of window w is limited due to the fact that u(m,n) is not really constant,
so that spatial averaging introduces a distortion in the form of blurring.

• To protect the edges from blurring while smoothing, a directional


averaging filter can be useful.

Directional smoothing filter

17-12-2021 DIP-SOCS-$P$ 50
Directional Smoothing
• Spatial averages v (m, n : θ) are calculated in several directions

• a direction θ* is found such that |y(m, n) - v(m, n: θ*)| is minimum.


Then v(m, n) = v(m, n : θ* )gives the desired result

17-12-2021 DIP-SOCS-$P$ 51
Directional Smoothing

17-12-2021 DIP-SOCS-$P$ 52
Median Filtering
 The input pixel is replaced by the median of the pixels contained in a
window around the pixel
v(m,n)= median{y(m-k,n-1),(k,l)єW}
 The algorithm for median filtering requires arranging the pixel values in
the window in increasing or decreasing order and picking the middle
value
 Generally the window size is chosen so that Nw is odd.
 If Nw is even, then the median is taken as the average of the two values
in the middle.
 Typical windows are 3 x 3, 5 x 5, 7 x 7, or the five-point window
considered for spatial averaging

17-12-2021 DIP-SOCS-$P$ 53
 Example
◦ Let {y (m)} = {2, 3, 8, 4, 2} and W = [ -1, 0, 1].
◦ The median filter output is given by
◦ v (0) 2 (boundary value)
v (l) = median {2, 3, 8} = 3
v (2) = median {3, 8, 4} = 4
v (3) = median {8, 4, 2} = 4
v (4) = 2 (boundary value)
◦ Hence {v (m)} = {2, 3, 4, 4, 2}.
◦ If W contains an even number of pixels-for example,
W = [-1, 0, 1,2]-then v(0) = 2, v (l) = 3
v (2) = median {2, 3, 8, 4}= (3 + 4)/2 = 3.5, and so on
◦ gives {v (m)} = {2, 3, 3.5, 3.5, 2}.

17-12-2021 DIP-SOCS-$P$ 54
• The median filter has the following properties:
• It is a nonlinear filter. Thus for two sequences x (m) and y (m)
median{x(m) + y (m)} ≠ median{x (m)} + median{y (m)}

• It is useful for removing isolated lines or pixels while


preserving spatial resolutions

• Its performance is poor when the number of noise pixels in the


window is greater than or half the number of pixels in the
window
• A practical two-dimensional median filter is the separable median
filter, which is obtained by successive one-dimensional median
filtering of rows and columns.
12/17/2021 School of computer sciences 55
• compares median filtering with spatial averaging for
images containing binary noise

12/17/2021 School of computer sciences 56


Frequency Domain
Enhancement

17-12-2021 DIP-SOCS-$P$ 57
Frequency Domain Enhancement
• In Frequency domain methods the image is first transferred into
frequency domain

• It means that, the Fourier Transform of the image is computed first

• All the enhancement operations are performed on the Fourier


Transform of the image and then the inverse Fourier Transform is
performed to get the resultant image

17-12-2021 DIP-SOCS-$P$ 58
Frequency Domain Enhancement
• These enhancement operations are performed in order to modify the
image brightness, contrast or the distribution of the grey levels

• As a consequence the pixel value (intensities) of the output image will


be modified according to the transformation function applied on the
input values

17-12-2021 DIP-SOCS-$P$ 59
Frequency Domain Enhancement
• The Image enhancement simply means, transforming an image F into
Image G using T [where T is the transformation function]

• The values of pixels in image F and G are denoted by the r and s


respectively,
s=T(r)

17-12-2021 DIP-SOCS-$P$ 60
Frequency Domain Enhancement

Frequency domain filtering operations

17-12-2021 DIP-SOCS-$P$ 61
Frequency Domain Enhancement

We can therefore directly design a transfer function and implement the enhancement
in the frequency domain

17-12-2021 DIP-SOCS-$P$ 62
Filtering
• The concept of filtering is easier to visualize in the frequency domain

• Enhancement of image can be done in the Frequency domain, based on its DFT

• Filtering can be divided into two categories namely

Low Pass Filtering High Pass Filtering

17-12-2021 DIP-SOCS-$P$ 63
Filtering

17-12-2021 DIP-SOCS-$P$ 64
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 65
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 66
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 67
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 68
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 69
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 70
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 71
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 72
Low Pass Filtering

17-12-2021 DIP-SOCS-$P$ 73
Low Pass Filtering :

•Butterworth low pass filter


•Gaussian low pass filter

17-12-2021 DIP-SOCS-$P$ 74
Low Pass Filtering : Butterworth low
pass filter

17-12-2021 DIP-SOCS-$P$ 75
Low Pass Filtering : Butterworth low
pass filter

17-12-2021 DIP-SOCS-$P$ 76
Low Pass Filtering : Butterworth low
pass filter

17-12-2021 DIP-SOCS-$P$ 77
Low Pass Filtering : Butterworth low
pass filter

Ringing is an image artifact that may appear when Doing Deconvolution under certain
conditions. It produces dark and light ripples around bright features of an image

17-12-2021 DIP-SOCS-$P$ 78
Low Pass Filtering : Gaussian low pass
filter

17-12-2021 DIP-SOCS-$P$ 79
Low Pass Filtering : Gaussian low pass
filter

17-12-2021 DIP-SOCS-$P$ 80
Low Pass Filtering : Gaussian low pass
filter
Example

17-12-2021 DIP-SOCS-$P$ 81
High Pass Filtering

17-12-2021 DIP-SOCS-$P$ 82
High Pass Filtering

17-12-2021 DIP-SOCS-$P$ 83
High Pass Filtering

17-12-2021 DIP-SOCS-$P$ 84
High Pass Filtering

17-12-2021 DIP-SOCS-$P$ 85
High Pass Filtering

17-12-2021 DIP-SOCS-$P$ 86
High Pass Filtering

17-12-2021 DIP-SOCS-$P$ 87
High Pass Filtering : example of IHPF

17-12-2021 DIP-SOCS-$P$ 88
High Pass Filtering : example of BHPF &
GHPF

17-12-2021 DIP-SOCS-$P$ 89
Low Pass High Pass
Filtering Filtering

An image can be smoothed in the Frequency An image can be smoothed in the Frequency
domain by reducing the High-frequency domain by reducing the low-frequency
content of its Fourier transform content of its Fourier transform

17-12-2021 DIP-SOCS-$P$ 90
Low Pass High Pass
Filtering Filtering

17-12-2021 DIP-SOCS-$P$ 91

You might also like