0% found this document useful (0 votes)
16 views146 pages

Chap 2 Image Enhancements and Filtering DD

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)
16 views146 pages

Chap 2 Image Enhancements and Filtering DD

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
You are on page 1/ 146

7

Spatial and Intensity Resolution


Implementation in MATLAB
© Dr. Dafda
❖ Spatial and Gray-level (Intensity) Resolution:
• Spatial resolution is the smallest discernable detail in an image.

• Gray-level resolution is the smallest discernable change in gray(intensity)


level.

• For spatial resolution to say a image has a 512x 512 pixels resolution is
not a meaningful statement without stating the spatial dimensions
encompassed by the image.
❖ Spatial/Coordinate Resolution:

A 512 x 512, 8 bit image subsampled down to size 256 x 256, 128 x 128, 64 x 64 , 32 x 32 and 16 x 16 pixels. The
number of intensity levels kept at 256.
❖ Aliasing (Down Sampling) :

• Shannon sampling theorem tells us that, if the function is sampled at a rate equal
to or greater than twice its highest frequency (fs≥2fm )it is possible to recover
completely the original function from the samples.

• If the function is downsampled, then a phenomenon called aliasing(distortion if


two pattern or spectrum overlap, the overlapped portion is called aliased) corrupts
the sampled image.

• The corruption is in the form of additional frequency components being


introduced into the sampled function. These are called aliased frequencies.
Downsampling results in a “Checker board” pattern due to reduction of samples.
❖ Up Sampling :
• For zooming an image we need to do interpolation. Interpolation is the process of
using know data to estimate values of unknown locations.
(1) Nearest neighbor interpolation:
Assigns the value of closest pixel to the new pixel.

(2) Bilinear interpolation:


Bilinear interpolation considers the closest 2x2 neighborhood of known pixel
values surrounding the unknown pixel. It then takes a weighted average of these 4
pixels to arrive at its final interpolated value.

(3) Bicubic interpolation:


It considers the closest 4 x 4 neighborhood of known pixels and takes the
weighted average of these 16 pixels.
❖ Gray-Level/Intensity Resolution :

Fig: 512 x 512, 256 level(8 bit) image. Further displayed in 128 level (7 bit), 64 level (6 bit), 32 level (5 bit), 16 level (4
bit), 8 level (3 bit), 4 level (2 bit) and 2 level (1 bit), while keeping spatial resolution constant.
Thank You
8
The basics of Intensity
transformations and spatial
filtering and implementation in
MATLAB © Dr. Dafda
• Image enhancement is the process of enhancing image so that the
resultant image is more suitable than original for specific applications.
Image Enhancement

Spatial domain Frequency domain


E.g. Image sharpening using Gaussian
high pass filters, unsharp masking,
Point processing Neighbourhood processing highboost filtering etc.

E.g. Negative Image, contrast E.g. Averaging filter, median filtering


stretching, thresholding etc. etc.
• The spatial domain processes can be denoted by the expression, g(x, y) = T[ f(x, y)], where f(x, y) is the input image,
g(x, y) is the output image, and T is an operator on f defined over a neighborhood of point (x, y).

• The smallest possible neighborhood is of size 1 x 1. Here, g depends only on the value of f at a single point (x, y)
and T becomes s = T(r), where, for simplicity in notation, s and r are variables denoting, respectively, the
intensity of g and f at any point (x, y).

Contrast stretching Thresholding


T function T function
Image with a 3 X 3 spatial mask
❖ Contrast stretching:
❖ Thresholding:
Thank You
9
Image negatives, Log and Power-
Law transformations for DIP and
implementation in MATLAB
© Dr. Dafda
❖ Image Negatives:

• Negative image means inverting the grey levels i.e. black in the original image will
become white and vice-versa.
• The transformation for image negative can be given by,
s=L–1–r
where, s is the output intensity value, L is the highest intensity levels and r is
the input intensity value
• It is particularly suited for enhancing white or gray detail embedded in dark
regions of an image, especially when the black areas are dominant in size
❖ Log transformations:

• s = c log(1 + r)
where, c is constant, s is the output intensity value and r is the input intensity
value
• It maps a narrow range of low intensity values in the input into a wide range of
output levels.
• The opposite is true of higher values of input levels.
• It expands the values of dark pixels in an image while compressing the higher level
values.
• It compresses the dynamic range of images with large variations in pixel values.
• Log reduces contrast of brighter regions.
❖ Power-Law (Gamma) transformations:

• s = c rγ
where c and γ are both positive constants, r =input and s = output
• With fractional values(0<γ<1) of gamma map a narrow range of dark input values
into a wider range of output values, with the opposite being true for higher values
(γ >1)of input levels.
• C=gamma=1 means it is an identity transformations.
• Variety of devices used for image capture , printing, and display respond according
to a power law.
• Process used to correct these power law response phenomena is called gamma
correction.
• Power-law enhances contrast of brighter regions.
Thank You
10

Piecewise linear transformation


function: Contrast stretching in DIP
and implementation in MATLAB
© Dr. Dafda
❖ Piece-wise Linear Transformation:
• Piece-wise Linear Transformation is type of gray level transformation that is used
for image enhancement. It is a spatial domain method. It is used for manipulation
of an image so that the result is more suitable than the original for a specific
application.
• Some commonly used piece-wise linear transformations are:
(1) Contrast Stretching
(2) Intensity Level Slicing
(3) Bit Plane Slicing
❖ Contrast Stretching:
• Contrast is the difference between the highest grey level and low grey level of
an image.
• Low contrast images can result from poor illuminations, Lack of dynamic
range in the imaging sensor, or even the wrong setting of a lens aperture
during image acquisition.
• It expands the range of intensity levels in an image so that it spans the full
intensity range of display devices.
• The contrast can be stretched by making darker portion more darker and
brighter portion more brighter.
For the first part,
𝑠 = 0.5 ∗ 𝑟 − 0 + 0
For the second part,
𝑠 = 2 ∗ 𝑟 − 𝐿𝑇 + (0.5 ∗ 𝐿𝑇)
For the third part,
𝑠 = 0.5 ∗ 𝑟 − 𝑈𝑇 + 0.5 ∗ 𝐿𝑇 +
2 ∗ 𝑈𝑇 − 𝐿𝑇
Thank You
11
Piecewise linear transformation
function: Intensity-level slicing in
DIP and implementation in
MATLAB © Dr. Dafda
❖ Piece-wise Linear Transformation:
• Piece-wise Linear Transformation is type of gray level transformation that is used
for image enhancement. It is a spatial domain method. It is used for manipulation
of an image so that the result is more suitable than the original for a specific
application.
• Some commonly used piece-wise linear transformations are:
(1) Contrast Stretching
(2) Intensity Level Slicing
(3) Bit Plane Slicing
❖ Intensity/Grey Level Slicing:
• Highlighting specific range of intensities in an image.

• Enhances features such as masses of water in satellite imagery and


enhancing flaws in X-ray images.

• It can be Implemented two ways:

1) To display only one value (say, white) in the range of interest and rests
are black which produces binary image.
2) Brightens (or darkens) the desired range of intensities but leaves all
other intensity levels in the image unchanged.
Thank You
12

Piecewise linear transformation


function: Bit-plane slicing in DIP
and implementation in MATLAB
© Dr. Dafda
❖ Piece-wise Linear Transformation:
• Piece-wise Linear Transformation is type of gray level transformation that is used
for image enhancement. It is a spatial domain method. It is used for manipulation
of an image so that the result is more suitable than the original for a specific
application.
• Some commonly used piece-wise linear transformations are:
(1) Contrast Stretching
(2) Intensity Level Slicing
(3) Bit Plane Slicing
(3) Bit Plane Slicing:
• Pixels are digital numbers composed of bits.

• 256 gray scale image is composed of 8 bits.

• Instead of highlighting intensity level ranges, we could highlight the


contribution made to total image appearance by specific bits.

• 8-bit image may be considered as being composed of eight 1-bit planes,


with plane 1 containing the lowest order bit of all pixels in the image
and plane 8 all the highest-order bits.
Thank You
13
Histogram Equalization in DIP
and its implementation in
MATLAB
© Dr. Dafda
❖ Histogram equalization:
• Histogram is the graphical representation of any data.
• Histogram provide a global description of the appearance of an image. It is a
spatial domain method.
• Histogram is the representation of relative frequency of occurrence of various grey
levels of an image.
• Histogram equalization is used for image enhancement.
• Histogram can control the quality of an image by normalizing the histogram values
to a flat profile.
Gray level
Image
3 3 7 7 6
5 2 2 3 4
6 6 4 4 5
5 7 3 6 0
7 6 5 5 4
❖ Steps in Histogram processing
Thank You
14
Histogram Specification
/Matching in DIP and its
implementation in MATLAB
© Dr. Dafda
❖ Histogram Matching/Specification:
• Histogram equalization is automatic and is not always good.
• At many times it is desirable to have an interactive method in which certain grey
levels are highlighted.
• If we modify the grey level of an image that has a uniform PDF, using the inverse
transformation we can get back the original histogram. Using this knowledge, we
can obtain any shape of the grey level histogram by processing the given image.
• The method used to generate a processed image that has a specified histogram is
called histogram matching or specification.
Thank You
15
Fundamentals of Spatial filtering
and Smoothing spatial filters in
DIP and its implementation in
MATLAB © Dr. Dafda
Image Enhancement

Spatial domain Frequency domain


E.g. Image sharpening using Gaussian
high pass filters, unsharp masking,
Point processing Neighbourhood processing highboost filtering etc.

E.g. Negative Image, contrast E.g. Averaging filter, median filtering


stretching, thresholding etc. etc.

• Spatial filtering change the grey level of a pixel (x,y) depending on the
pixel values in a square neighborhood centered at (x,y) using a
matrix(filter, mask, kernel/window).
• There are many things that can be achieved by neighborhood
processing which are not possible with point processing.
Spatial filters

Sharpening spatial filters (HPF)


Smoothing spatial filters (LPF)

Linear filters Non-linear(Order statistics) spatial filter Laplacian linear filter

Averaging filter Weighted averaging filter

Minimum filter Maximum filter Median filter


❖ Averaging Linear Filtering:
• To achieve neighborhood processing, a 3 x 3 mask (or 5 x 5, 7 x 7….)
on the image, multiply each component of the mask with the
corresponding value of the image, add them up and place the value
that we get, at the center. The operation being same as convolution.
• This smoothing process is used for blurring sharp edges.
Input image Output image

Filter mask

• The two noises are replaced with the average of their surrounding points.
The process of reducing the influence of noise is called smoothing or blurring.
Thank You
16

Order statistics/Non-linear filters


in DIP and its implementation in
MATLAB
© Dr. Dafda
Image Enhancement

Spatial domain Frequency domain


E.g. Image sharpening using Gaussian
high pass filters, unsharp masking,
Point processing Neighbourhood processing highboost filtering etc.

E.g. Negative Image, contrast E.g. Averaging filter, median filtering


stretching, thresholding etc. etc.

• Spatial filtering change the grey level of a pixel (x,y) depending on the
pixel values in a square neighborhood centered at (x,y) using a
matrix(filter, mask, kernel/window).
• There are many things that can be achieved by neighborhood
processing which are not possible with point processing.
Spatial filters

Sharpening spatial filters (HPF)


Smoothing spatial filters (LPF)

Linear filters Non-linear(Order statistics) spatial filter Laplacian linear filter

Averaging filter Weighted averaging filter

Minimum filter Maximum filter Median filter


❖ Non-Linear Order statistics Spatial Filtering:
• Median filtering is a nonlinear method used to remove noise from images.
• It is widely used as it is very effective at removing noise while preserving edges.
• It is particularly effective at removing ‘salt and pepper’ type noise.
• The median filter works by moving through the image pixel by pixel, replacing
each value with the median value of neighboring pixels.

Input image Output image

R = median{Zk | k =1,2,3,…..9}
Filter mask
• The effects of median filter are: (1) Noise reduction,
(2) Less blurring than averaging filter
Minimum filter:
R = min{Zk | k =1,2,3,…..9}
It is used for finding the darkest point.
It is used for removing the salt noise.

Maximum filter:
R = max{Zk | k =1,2,3,…..9}
It is used for finding the brightest
point.
It is used for removing the pepper
noise.
Thank You
17

Image Sharpening spatial filters


in DIP and its implementation in
MATLAB © Dr. Dafda
Image Enhancement

Spatial domain Frequency domain


E.g. Image sharpening using Gaussian
high pass filters, unsharp masking,
Point processing Neighbourhood processing highboost filtering etc.

E.g. Negative Image, contrast E.g. Averaging filter, median filtering


stretching, thresholding etc. etc.

• Spatial filtering change the grey level of a pixel (x,y) depending on the
pixel values in a square neighborhood centered at (x,y) using a
matrix(filter, mask, kernel/window).
• There are many things that can be achieved by neighborhood
processing which are not possible with point processing.
Spatial filters

Sharpening spatial filters (HPF)


Smoothing spatial filters (LPF)

Linear filters Non-linear(Order statistics) spatial filter Laplacian linear filter

Averaging filter Weighted averaging filter

Minimum filter Maximum filter Median filter


❖ Sharpening Spatial Filters:
• Sharpening filters are used to highlight fine details (e.g. edges) in an image, or
enhance details that are blurred through errors or imperfect capturing devices.
• Sharpening is opposite of smoothing(averaging). Hence in mathematics, it is given
by partial derivatives(HPF) as averaging is integration(LPF).
• While linear smoothing is based on the weighted summation or integral
operation on the neighborhood, the sharpening is based on the derivative
(gradient) or finite difference.
• In smoothing we try to smooth noise and ignore edges and in sharpening we try
to enhance edges and ignore noise.
❖ Partial derivatives of digital image:
• The first order partial derivative of the digital image f(x,y) are:

• The first derivative must be:


(1) Zero along flat segments (i.e. constant grey levels)
(2) Non-zero at the outset of grey level step or ramp (edges or noise)
(3) Non-zero along segments of continuing changes (i.e. ramps)
• The second order partial derivatives of the digital image f(x,y) are:

• The second derivative must be:


(1) Zero along flat segments (i.e. constant grey levels)
(2) Non-zero at the outset of grey level step or ramp (edges or noise)
(3) Zero along ramps.
• The first derivative detects thick
edges while second derivative detects
thin edges. f ' = f(x+1) - f(x)
• Second derivative has much stronger
response at grey level step than first
derivative. f '' = f(x+1) + f(x-1) - 2f(x)
• Thus we can expect a second order
derivative to enhance fine detail (thin
lines, edges, including noise) much
more than a first order derivative.
❖ The Laplacian filter:
• The Laplacian operator of an image f(x,y) is:

• This equation can be implemented using the 3 x 3 mask:


• As the Laplacian filter is a linear spatial filter, we can apply it using the same
mechanism of convolution. This will produce a Laplacian image that has grayish
edge lines and other discontinuities, all superimposed on a dark, featureless
background.
• Background features can be “recovered” while still preserving the sharpening
effects of the Laplacian simply by adding the original and Laplacian images.
Filter mask Input image Output image

20 20 20 20 20 0 -15 0 0 0
20 5 20 20 20 0 60 0 0 0
20 20 20 20 20 0 -15 0 -15 0
20 20 20 5 20 0 0 0 60 0
20 20 20 20 20 0 0 0 -15 0
Thank You
18
Introduction to Image Enhancement in
the frequency domain and different
steps for filtering in the frequency
domain
© Dr. Dafda
Image Enhancement

Spatial domain Frequency domain


E.g. Image sharpening using Gaussian
high pass filters, unsharp masking,
Point processing Neighbourhood processing highboost filtering etc.

E.g. Negative Image, contrast E.g. Averaging filter, median filtering


stretching, thresholding etc. etc.

• The frequency content of an image refers to the rate at which the


gray levels change in time. Rapidly changing brightness values
correspond to high frequency terms, slowly changing brightness
values correspond to low frequency terms. The Fourier transform is a
mathematical tool that analyses a signal (e.g. images) into its spectral
components depending on its frequency content.
Frequency domain filters

Smoothing frequency filters (LPF) Sharpening frequency filters (HPF)

Ideal LPF Ideal HPF

Butterworth LPF Butterworth HPF


Gaussian LPF Gaussian HPF

High Boost Filter Homomorphic filter


❖ Advantages of filtering in frequency domain:
• The frequency domain filtering is advantageous because it is computationally
faster to perform two 2D Fourier transforms and a filter multiply than to perform
a convolution in the spatial domain.

• Frequency domain gives you control over the whole images, where we can
enhance(eg. Edges) and suppress(eg. Smooth shadow) different characteristics of
the image very easily.

• Frequency domain has a established suit of processes and tools that can be
borrowed directly from signal processing in other domain.

• Image enhancement in the frequency domain is straightforward. The idea of blurring an


image by reducing its high frequency components, or sharpening an image by increasing
the magnitude of its high frequency components is intuitively easy to understand.
Lowpass and Highpass Filters
❖ Filtering in the Frequency Domain

1. Multiply the input image by (-1)^x+y


to center the transform
2. Compute F(u,v), the DFT of input
3. Multiply F(u,v) by a filter H(u,v)
4. Computer the inverse DFT of 3
5. Obtain the real part of 4
6. Multiply the result in 5 by (-1)^(x+y)
Thank You
19
Image Smoothing in frequency
domain filtering and its
Implementation in MATLAB
© Dr. Dafda
❖ Smoothing Filters
Ideal lowpass filters This has a sharp
discontinuity and hence,
Ringing effect is present
Butterworth lowpass Does not have a sharp
filters discontinuity and hence
ringing is only observed
for filters of higher
orders.
Gaussian lowpass filters The profile of GLPF is
not as tight as that of
BLPF and hence no
ringing effect is present.
❖ Ideal Lowpass Filters
Ringing Effect
Ideal Lowpass Filters
Ideal Lowpass Filters
Butterworth Lowpass Filters
Definition:
1
H (u, v) =
1 + D(u, v) / D0 
2n
Example
Ringing Effect
Gaussian Lowpass Filters
Definition:
− D 2 ( u ,v ) / 2 2
H (u, v) = e
Example
More example
Thank You
20
Image Sharpening (HPF) in
frequency domain filtering and its
Implementation in MATLAB
© Dr. Dafda
Frequency domain filters

Smoothing frequency filters (LPF) Sharpening frequency filters (HPF)

Ideal LPF Ideal HPF

Butterworth LPF Butterworth HPF


Gaussian LPF Gaussian HPF

High Boost Filter Homomorphic filter


❖ Sharpening Filters
Ideal highpass filters This has a sharp
discontinuity and hence,
Ringing effect is present
Butterworth highpass Does not have a sharp
filters discontinuity and hence
ringing is only observed
for filters of higher
orders.
Gaussian highpass filters The profile of GHPF is
not as tight as that of
BLPF and hence no
ringing effect is present.
Spatial Representation of Freq. Domain HPF
Ideal High Pass Example
Ideal High Pass (Sharpening) Filters IHPF:
Butterworth High Pass Example
Butterworth High Pass (Sharpening) Filters BHPF:
Gaussian High Pass Example
Gaussian High Pass (Sharpening) Filters GHPF:
Thank You
21
Laplacian, Unsharp
masking/High Boost filtering in
the frequency domain filtering
and its Implementation in
MATLAB © Dr. Dafda
Frequency domain filters

Smoothing frequency filters (LPF) Sharpening frequency filters (HPF)

Ideal LPF Ideal HPF

Butterworth LPF Butterworth HPF


Gaussian LPF Gaussian HPF

High Boost Filter Homomorphic filter


❖ The Laplacian in the Spatial domain:
❖ The Laplacian in the Frequency domain:
❖ High boost filtering in the Frequency domain:
Sometimes it is advantageous to increase the contribution made by the original image to the overall
filtered result. This approach, called high-boost filtering, is a generalization of unsharp masking.
Unsharp masking consists simply of generating a sharp image by subtracting from an image a blurred
version of itself. Using frequency domain terminology, this means obtaining a highpass-filtered image
by subtracting from the image a lowpass-filtered version of itself.

High-boost filtering generalizes this by multiplying f (x, y) by a constant A > 1:

Thus, high-boost filtering gives us the flexibility to increase the contribution made by the image to
the overall enhanced result. This equation may be written as:

Then, using above Eq. we obtain


This result is based on a highpass rather than a lowpass image. When A = 1, high-boost filtering
reduces to regular highpass filtering. As A increases past 1, the contribution made by the image
itself becomes more dominant.

We have Fhp (u,v) = F (u,v) – Flp (u,v). But Flp (u,v) = Hlp (u,v)F(u,v), where Hlp is the transfer
function of a lowpass filter. Therefore, unsharp masking can be implemented directly in the
frequency domain by using the composite filter

Similarly, high-boost filtering can be implemented with the composite filter

with A > 1. The process consists of multiplying this filter by the (centered) transform of the input
image and then taking the inverse transform of the product. Multiplication of the real part of this
result by (-l) x+y gives us the high-boost filtered image fhb (x, y) in the spatial domain.
Thank You
22

Homomorphic Filtering and its


Implementation in MATLAB
© Dr. Dafda
Frequency domain filters

Smoothing frequency filters (LPF) Sharpening frequency filters (HPF)

Ideal LPF Ideal HPF

Butterworth LPF Butterworth HPF


Gaussian LPF Gaussian HPF

High Boost Filter Homomorphic filter


❖ The Homomorphic Filtering:
• Homomorphic filters uses a different approach compared to other frequency
domain filters. It normalizes the brightness across an image and increases
contrast.
• Homomorphic filter can be used to enhance an image due to non-uniform
illumination. Illumination variations can be thought of as a multiplication noise,
and can be reduced by filtering in the log domain.
• To evenly distribute the illumination, the high-frequency components are
increased and the low-frequency components are decreased, because the high
frequency components are assumed to represent mostly the reflectance in the
scene(the amount of light reflected off the object in the scene), whereases the low
frequency components are assumed to represent mostly the illumination in the
scene.
• Hence high pass filtering is used to suppress low frequencies and amplify high
frequencies in the log-intensity domain.
• An image f(x, y) can be expressed as the product of illumination and reflectance
components:
• Equation above cannot be used directly to operate separately on the frequency
components of illumination and reflectance because the Fourier transform of the
product of two functions is not separable; in other words,
If we process Z (u, v) by means of a filter function H (u, v) then, from

In the spatial domain,

Finally, as z (x, y) was formed by taking the logarithm of the original image f (x, y), the inverse
(exponential) operation yields the desired enhanced image, denoted by g(x, y); that is,
Homomorphic filtering approach for image enhancement

If the parameters γL and γH are chosen so that


γL < 1 and γH > 1, the filter function shown tends
to decrease the contribution made by the low
frequencies (illumination) and amplify the
contribution made by high frequencies
(reflectance). The net result is simultaneous
dynamic range compression and contrast
enhancement.
Thank You

You might also like