Unit Ii - CC

Download as pdf or txt
Download as pdf or txt
You are on page 1of 200

DIGITAL IMAGE PROCESSING

“THE USE OF A DIGITAL COMPUTER TO PROCESS DIGITAL IMAGES THROUGH AN ALGORITHM”


OUTLINE OF UNIT II
 Introduction to Spatial Domain
 Gray level transformations

SRM Institute of Science and Technology 06-02-2024 3


IMAGE ENHANCEMENT
• Image Enhancement Techniques -> To improve the visual quality of an image by
emphasizing certain features, reducing unwanted elements, and making the image more
suitable for specific purposes.

• For example:
• This can include reducing noise, sharpening details (revealing blurred details), adjusting
contrast and brightness, and highlighting specific areas of interest.

• Two fundamental approaches for image enhancement:


• Spatial domain

• Frequency domain
SRM Institute of Science and Technology 06-02-2024 4
EX - IMAGE ENHANCEMENT

Histogram Equalization-Spreading out most frequent


intensity values Contrast Stretching

Image Smoothing
Edge Enhancement 5
SRM Institute of Science and Technology
06-02-2024
HOW TO DO IMAGE ENHANCEMENT?

• Two fundamental approaches for image enhancement:

• Spatial domain

• Frequency domain

SRM Institute of Science and Technology 06-02-2024 6


INTRODUCTION TO SPATIAL DOMAIN
• Spatial domain

• Spatial domain refers to the image plane itself, and techniques involve the
direct manipulation of pixel values within the image.
• These methods operate on individual pixel values and their neighboring
pixels.
• They include techniques like histogram equalization, contrast stretching,
filtering (e.g., Gaussian, median, or mean filtering), and edge enhancement
(e.g., using the Laplacian or Sobel operators).
• These methods work directly with the pixel values and can be intuitive to
understand and implement.
SRM Institute of Science and Technology 06-02-2024 7
ILLUSTRATION OF SPATIAL DOMAIN FOR GRAYSCALE IMAGE
An image can be represented in the form of a 2D matrix where each element of the matrix
represents pixel intensity. This state of 2D matrices that depict the intensity distribution of an
image is called Spatial Domain. It can be represented as shown below-

SRM Institute of Science and Technology 06-02-2024 8


ILLUSTRATION OF SPATIAL DOMAIN FOR COLOR IMAGE
For the RGB image, the spatial domain is represented as a 3D vector of 2D matrices. Each 2D matrix
contains the intensities for a single color as shown below-

SRM Institute of Science and Technology 06-02-2024 9


FREQUENCY DOMAIN/ TRANSFORM DOMAIN
• Frequency domain / Transform Domain
• Frequency domain methods involve transforming the image from the spatial domain to
the frequency/transform domain using techniques called the Fourier Transform.
• The term frequency in an image tells about the rate of change of pixel values.

• This transformation allows the image's frequency components (high and low
frequencies) to be analyzed and manipulated.
• Once in the frequency domain, enhancements can be applied, such as noise reduction
through frequency filtering or sharpening using high-frequency emphasis.
• After applying the desired enhancements, the image can be transformed back to the
spatial domain using the inverse Fourier Transform.

SRM Institute of Science and Technology 06-02-2024 10


FREQUENCY DOMAIN/ TRANSFORM DOMAIN

Why we need a domain other than spatial domain ?


Many times, image processing tasks are best performed in a domain other than the spatial domain. Moreover,
it is easy to detect some features in a particular domain,i.e., a new information can be obtained in other
domains.

SRM Institute of Science and Technology 06-02-2024 11


MATHEMATICAL MODEL OF FREQUENCY / TRANSFORM DOMAIN

• f(x, y) is the input image in the spatial domain.

• g(x, y) is the processed image in the spatial domain.

• T: Represents the transformation of converting the image from spatial domain to frequency
domain using mathematical operations.
• Ex of transformation: Fourier transform, Inverse Fourier transform

• R: Represents an operations on a set of input frequencies.


• Ex of operations: Filtering, Deconvolution, Fourier analysis

SRM Institute of Science and Technology 06-02-2024 12


TYPES OF FREQUENCY COMPONENTS

 Frequency components is divided into two major types

 High frequency components

 High frequency components correspond to edges in an image.

 Low frequency components

 Low frequency components in an image correspond to smooth

regions.

SRM Institute of Science and Technology 06-02-2024 13


APPLICATIONS OF IMAGE ENHANCEMENT
Spatial domain techniques Frequency domain techniques

1. Image Denoising: Spatial domain methods like 1. Image Compression: Transform-based


median filtering, Gaussian filtering, and mean filtering techniques like Discrete Cosine Transform (DCT)
are commonly used to reduce/remove noise in and wavelet transform are central to image
images. compression algorithms such as JPEG and
JPEG2000.
2. Image Sharpening: Techniques such as unsharp
masking and Laplacian sharpening are applied to 2. Noise Reduction: Frequency domain filtering,
enhance edges and fine details. such as Wiener filtering and frequency domain
averaging, is effective for reducing noise.
3. Edge Detection: Operators like Sobel, Prewitt, and
Roberts are used to detect edges and boundaries in 3. Image Deconvolution: Frequency domain
images. techniques can be used to restore images by
attempting to reverse the effects of blurring.
4. Contrast Enhancement: Spatial domain techniques
like histogram equalization and contrast stretching 4. Super-Resolution: Frequency domain methods
are employed to improve image contrast. can play a role in increasing the resolution of
images.
5. Image Restoration: Simple restoration tasks, such as
removing small artifacts and scratches, can be 5. Image Fusion: Combining information from
performed effectively in the spatial domain. multiple images, such as in multispectral image
fusion, can benefit from frequency domain
6. Simple Blurring and Smoothing: Techniques like processing.
box filtering and Gaussian blurring are used to blur or
smooth images. 6. Image Enhancement with Global Information:
Techniques that require analyzing the frequency
content of the entire image, such as global
contrast enhancement, can be suited for the
frequency domain. 06-02-2024 14
SRM Institute of Science and Technology
MATHEMATICAL MODEL OF SPATIAL DOMAIN
• Spatial domain -> The aggregate of pixels composing an image.

• Spatial domain methods are procedures that operate directly on these pixels.

• Spatial domain processes will be denoted by the expression

g (x, y) = T [f (x, y)]


• where f(x, y) is the input image (Pixel intensity where x, y are the co-ordinate of the pixel in the
2D matrix)

• T is an operator on f (Different operations are carried out in this value)defined over some
neighborhood of (x, y). Ex: Addition 5 to all pixels

• g(x, y) is the processed image / g (x,y) is the new intensity after adding 5 to I(x,y)

• T can process a group of input images, such as calculating the sum of pixel values for K images on a
neighborhood around the coordinates (x, y) to reduce noise.

• Neighborhood of a point (x,y) can be defined by using a square/rectangular or circular subimage


area centered at (x,y) 06-02-2024 15
SRM Institute of Science and Technology
MATHEMATICAL MODEL OF SPATIAL DOMAIN
 The principal approach in defining a neighborhood about a point (x, y) is to use a square or
rectangular sub image area centered at (x, y), as shown in below figure.

 The center of the sub image is moved from pixel to pixel starting, say, at the top left corner. The
operator T is applied at each location (x, y) to yield the output, g, at that location. The process
utilizes only the pixels in the area of the image spanned by the neighborhood.

06-02-2024 16
SRM Institute of Science and Technology
CATEGORIES OF SPATIAL DOMAIN

 Intensity Transformation / Point Operations


 This operates on single pixel of an image.
 These operations involve applying the same transformation to each pixel in a
grayscale image, based on its original pixel value and independent of its
location or neighboring pixels.
 Spatial Filtering
• This deals with performing operations such as image sharpening, by working
in a neighborhood of every pixel in an image.
• The output value of these operations is dependent on the values of the function
f(x,y) and its neighborhood.
06-02-2024 17
SRM Institute of Science and Technology
IMAGE TRANSFORMATION

SRM Institute of Science and Technology 06-02-2024 18


GRAY LEVEL TRANSFORMATION / POINT OPERATION
 Enhancing an image provides better contrast and a more detailed image as
compare to non enhanced image.

 Image enhancement has many applications. It is used to enhance medical images,


images captured in remote sensing, images from satellite...

s = T ( r ) -> Transformation function

 where r is the pixels of the input image and s is the pixels of the output image.

 T is a transformation function that maps each value of r to each value of s.

 Transformation is a function that takes the values of pixels from one set and maps
them to another set through specific operations.
SRM Institute of Science and Technology 06-02-2024 19
EX OF IMAGE TRANSFORMATION – CONTRAST STRETCHING
 For instance, if the function T(r) follows the pattern illustrated in Fig. 2(a), it would enhance the contrast of an
image. This is achieved by making darker levels even darker and brighter levels even brighter compared to
the original image.

 This process, known as contrast stretching, involves compressing pixel values below a threshold "m" into a
narrower range, which makes them appear darker.

 Conversely, pixel values above "m" are spread out, making them appear brighter. In the case shown in Fig.
2(b), T(r) can even produce a two-level (binary) image, creating distinct regions with just two levels of
brightness. Such a mapping is termed a thresholding function.

06-02-2024 20
SRM Institute of Science and Technology
GRAY LEVEL TRANSFORMATION / INTENSITY TRANSFORMATION
 Its done for image enhancement.

 It involves applying a function to the pixel values of an image to achieve desired changes in

contrast, brightness, or other visual properties. The goal of gray-level transformation is to enhance
or modify the appearance of an image for better visualization or analysis by adjust contrast, and
reveal important details.
 Mathematically, gray-level transformation can be represented as follows:

s=T(r)
 where:
• r is the original pixel value (input intensity / before processing).
• s is the transformed pixel value (output intensity / after processing).
• T is the transformation function that maps input intensities to output intensities.

SRM Institute of Science and Technology 06-02-2024 21


TYPES OF GRAY LEVEL TRANSFORMATION
 There are two basic gray level transformation.

• Linear Transformation - This involves applying a linear function to the pixel values

• Types are Identity transformation and Negative transformation.

• A common example is contrast stretching, where pixel values are linearly mapped to

a wider range to enhance contrast.

• Non-Linear

• Logarithmic Transformation: Enhances details in bright and dark regions.

• Gamma Correction: Adjusts brightness and contrast using a power-law function.

• Histogram Equalization: Enhances contrast by redistributing intensity values using logarithmic

transformation.

SRM Institute of Science and Technology 06-02-2024 22


GRAY LEVEL TRANSFORMATION
The overall graph of these transitions has been shown below.

SRM Institute of Science and Technology 06-02-2024 23


IDENTITY TRANSFORMATION
 In identity transformation, each value in the input image is directly
mapped to the other value of output image; it remains unchanged. It
can be expressed using the following equation: r= T(r)
Where:
• T(r) -> the transformed pixel value / point processing operation
• r ->original pixel value.

 In this equation, the identity transformation maps each pixel value r in


the input image to itself, resulting in the same pixel value in the output
image; no change occurs to the pixel values of the image.

SRM Institute of Science and Technology 06-02-2024 24


IDENTITY TRANSFORMATION

 Applications
 Comparing transformed images to the original using the identity
transformation helps evaluate the impact of different techniques both
numerically and visually.
 The identity transformation acts as a benchmark during the development of
image processing algorithms, aiding in testing and verifying the transformations.

SRM Institute of Science and Technology 06-02-2024 25


NEGATIVE TRANSFORMATION
 Negative transformation is invert of identity transformation.
 In negative transformation, each value of the input image is subtracted from the L-1
and mapped onto the output image.
s = (L – 1) – r
 L -> the maximum intensity level of pixel values in the image.
 L is typically 256, representing pixel values from 0 (black) to 255 (white) in gray
scale.
 r-> original pixel value of an input image before transformation

06-02-2024 26
SRM Institute of Science and Technology
NEGATIVE TRANSFORMATION

SRM Institute of Science and Technology 06-02-2024 27


LOGARITHMIC TRANSFORMATION
 Logarithmic transformation is divided into two types:
1.Log transformation - >Replacing each pixel value with its log value
2.Inverse log transformation ->Finding inverse of log transformation

 Logarithmic transformation: s = c log(r + 1)


 s and r -> pixel values for input and output image. And c is constant.
In the formula, we can see that 1 is added to each pixel value this is
because if pixel intensity is zero in the image then log(0) is infinity so,
to have minimum value one is added.
 Application: To increase the visibility of details in darker areas and
reducing the overall brightness of the image by Expands the dark
pixels in the image while compressing the brighter pixels.

06-02-2024 28
SRM Institute of Science and Technology
LOGARITHMIC TRANSFORMATION

X 0 5 10 20 100 125 127 200 225

y - 0.69 1 1.3 2 2.09 2 2.3 2.35


SRM Institute of Science and Technology 06-02-2024 29
GAMMA / POWER-LAW TRANSFORMATION

•s: This typically represents the output signal or value.


•c: This is a constant factor that scales the input value.
•r: This is the input variable or value.
•γ (gamma): This is the exponent to which the input value (r) is raised.

•Here, γ is gamma, by which this transformation factor is known as gamma


transformation.
•Variation in the value of γ varies the enhancement of the images
06-02-2024 30
SRM Institute of Science and Technology
GAMMA / POWER-LAW TRANSFORMATION

Plots of the equation s=cr^γ for various values of γ


(c=1 in all cases)
06-02-2024 31
SRM Institute of Science and Technology
GAMMA / POWER-LAW TRANSFORMATION
 The Gamma (γ) or Power-Law transformation is a commonly used
image enhancement technique that adjusts the intensity values of an
image based on a power function.

 This transformation can be applied to change the overall brightness


/ visibility / contrast of an image.

 The main benefit of using Gamma is the more natural look of images
and the ability to differentiate between dark tones in a darker
image.

06-02-2024 32
SRM Institute of Science and Technology
GAMMA / POWER-LAW TRANSFORMATION

06-02-2024 33
SRM Institute of Science and Technology
WHAT IS HISTOGRAM?
 In digital image processing, the histogram is used for graphical representation of a digital image. A graph is
a plot by the number of pixels for each tonal value. Nowadays, image histogram is present in digital
cameras. Photographers use them to see the distribution of tones captured.
 In a graph, the horizontal axis of the graph is used to represent tonal variations whereas the vertical axis is
used to represent the number of pixels in that particular pixel.
 Black and dark areas are represented in the left side of the horizontal axis, medium grey color is
represented in the middle, and the vertical axis represents the size of the area.
 Spatial Domain Methods: Histogram Processing
 Histogram equalization, Matching
 Local Histogram Processing
 Statistics for histogram
 Fundamentals of Spatial Filtering : Smoothing Spatial filters - linear Filters
 Order statistics nonlinear filters -Sharpening spatial filters
 Combined spatial enhancement methods
 Frequency Domain methods: Basics of filtering in frequency domain
 image smoothing, image sharpening, selective filtering,
 Homomorphic filtering, A model of image degradation/ restoration
Process, Noise models, Adaptive filters, Band reject Filters, Band pass Filters, Inverse Filtering – Wiener, Singular
value decomposition
 Applications of Histograms
1. In digital image processing, histograms are used for simple calculations in software.
2. It is used to analyze an image. Properties of an image can be predicted by the detailed study of the histogram.
3. The brightness of the image can be adjusted by having the details of its histogram.
4. The contrast of the image can be adjusted according to the need by having details of the x-axis of a histogram.
5. It is used for image equalization. Gray level intensities are expanded along the x-axis to produce a high contrast
image.
PROCESSIN
G
TECHNIQUE
S
 Histogram
Stretching
HISTOGRAM EQUALIZATION
 Histograms are the basis for numerous spatial domain processing
techniques. Histogram manipulation can be used for image
enhancement, as shown in this section.
 As an introduction to histogram processing for intensity
transformations, consider the below Diagram
 four basic intensity characteristics: dark, light, low contrast, and
high contrast. The right side of the figure shows the histograms
corresponding to these images. The horizontal axis of each
histogram plot corresponds to intensity values, The vertical axis
corresponds to values of or if the values are normalized. Thus,
histograms may be viewed graphically simply as plots of
h(rk) = nk.rk
p(rk) = nk>MN
H= horizontal, rk- intensity values , nk- number of pixels
h(rk) = nk is the discrete function
P(rk) = probability of the occurrence based on the intensity rk
M and N are the row and column dimension of the image.

Result :
The sum of all components of a normalized histogram is
equal to 1.

42
 Statistics obtained directly from an image histogram can be used for image enhancement. Let r
denote a discrete random variable representing intensity values in the range(0, L-1) and let p(ri)
denote the normalized histogram
 mn(r) = a L-1 i=0 (ri - m) np(ri)
 As image shows the level of statistics based on the grey scale.

43
 There are several basic concepts underlying the use of spatial filters for image processing. Spatial
filtering is one of the principal tools used in this field for a broad spectrum of applications, so it is
highly advisable that you develop a solid understanding of these concepts,
 The name filter is borrowed from frequency domain processing where “filtering” refers to
accepting (passing) or rejecting certain frequency components. For example, a filter that passes
low frequencies is called a lowpass filter which means blur or otherwise called as smooth of an
image.
 We can accomplish a similar smoothing directly on the image itself by using spatial filters (also
called spatial masks, kernels, templates, and windows).

44
 Spatial filter consists of (1) a neighborhood,
(typically a small rectangle), and (2) a predefined
operation that is performed on the image pixels
encompassed by the neighborhood.
A processed (filtered) image is generated as the
center of the filter visits each pixel in the input
image. If the operation performed on the image
pixels is linear, then the filter is called a linear
spatial filter Otherwise, the filter is nonlinear

45
 Smoothing filters are used for blurring and for noise reduction.
 Blurring is used in preprocessing tasks, such as removal of small details from an image prior to
(large) object extraction, and bridging of small gaps in lines or curves.
 Noise reduction can be accomplished by blurring with a linear filter and also by nonlinear
filtering.

❖ Smoothing Linear Filters


❖ Order Statistics Non- Linear Filters

46
 The output (response) of a smoothing, linear spatial filter is simply the average of the pixels
contained in the neighborhood of the filter mask. These filters sometimes are called averaging
filters.
 The idea behind smoothing filters is straightforward.
 By replacing the value of every pixel in an image , the average of the intensity levels in the
neighborhood is defined by the filter mask, this process results in an image with reduced “sharp”
transitions in intensities.
 Because random noise typically consists of sharp transitions in intensity levels, the most obvious
application of smoothing is noise reduction.
 However, edges (which almost always are desirable features of an image) also are characterized
by sharp intensity transitions, so averaging filters have the undesirable side effect that they blur
edges.

47
 Order-statistic filters are nonlinear spatial filters whose
response is based on ordering (ranking) the pixels
contained in the image area encompassed by the filter, and
then replacing the value of the center pixel with the value
determined by the ranking result.
 The best-known filter in this category is the median filter,
which, as its name implies, replaces the value of a pixel by
the median of the intensity values in the neighborhood of
that pixel.
 Median filters are particularly effective in the presence of
impulse noise, also called salt-and-pepper noise because
of its appearance as white and black dots superimposed on
an image.

48
 The principal objective of sharpening is to highlight transitions in intensity.
 Uses:
1.Electronic printing
2.medical imaging
3.Industrial inspection
4.Autonomous guidance in military systems
 Fundamentally, the strength of the response of a derivative operator is proportional to the degree
of intensity in sharpening.
 Thus, image differentiation enhances edges and other discontinuities (such as noise) and
deemphasizes areas with slowly varying intensities.

49
 In this section we illustrate by means of an example how to
combine several of the approaches developed thus far in this
chapter to address a difficult image enhancement task.
 With a few exceptions, like combining blurring with
thresholding.
 The image given below is a nuclear whole body bone scan,
used to detect diseases such as bone infection and tumors.
 Our objective is to enhance this image by sharpening it and by
bringing out more of the skeletal detail. The narrow dynamic
range of the intensity levels and high noise content make this
image difficult to enhance.

50
51
 We begin with lowpass filters. Edges and other sharp intensity transitions (such as noise) in an
image contribute significantly to the high frequency content of its Fourier transform.
 Hence, smoothing (blurring) is achieved in the frequency domain by high-frequency attenuation;
that is, by lowpass filtering.
 we consider three types of lowpass filters: ideal, Butterworth, and Gaussian.
 These three categories cover the range from very sharp (ideal) to very smooth (Gaussian) filtering.
The Butterworth filter has a parameter called the filter order.
 so all filter functions, (u, v), are understood to be discrete functions of size that is, the discrete
frequency variables are in the range
 u = 0, 1, 2, Á , P - 1 v = 0, 1, 2, Á , Q - 1.

52
IMAGE ENHANCEMENT IN THE
FREQUENCY DOMAIN

Enhance: To make greater (as in value, desirability,


or attractiveness.
Frequency: The number of times that a periodic
function repeats the same sequence of values during
a unit variation of the independent variable.
– Webster’s New Collegiate Dictionary
Frequency Domain Filters

Types
 Smoothing Frequency-Domain Filters
 Sharpening Frequency-Domain Filters
 Homomorphic Filtering
What is frequency domain
• The frequency domain
refers to the plane of the
two dimensional discrete
Fourier transform of an
image.
• The purpose of the Fourier
transform is to represent a
signal as a linear
combination of sinusoidal
signals of various
frequencies.
INTRODUCTION TO THE FOURIER TRANSFORM
AND THE FREQUENCY DOMAIN
• The one-dimensional Fourier transform and its inverse
– Fourier transform (continuous case)

F (u)   f ( x)e  j 2uxdx where j   1


– Inverse Fourier transform: e j  cos   j sin 



f ( x)   F (u )e j 2uxdu


• The two-dimensional Fourier transform and its inverse


– Fourier transform (continuous case)
 
F (u, v)    f ( x, y)e  j 2 (uxvy ) dxdy
 

– Inverse Fourier transform:


 
f ( x, y)    F (u, v)e j 2 (uxvy ) dudv
 
FILTERING IN THE FREQUENCY DOMAIN
Frequency is directly related to rate of change. The frequency of fast
varying components in an image is higher than slowly varying components.
Basics of Filtering in the Frequency Domain
Including multiplication the input/output image by (-1)x+y.
What is zero-phase-shift filter?
Some Basic Filters and Their Functions

 Multiply all values of F(u,v) by the filter function (notch filter):


 0 if (u, v)  ( M / 2, N / 2)
H (u, v)  
1 otherwise.
 All this filter would do is set F(0,0) to zero (force the average value
of an image to zero) and leave all other frequency components of
the Fourier transform untouched and make prominent edges stand
out
Some Basic Filters and Their Functions

Lowpass filter

Circular symmetry

Highpass filter
Some Basic Filters and Their Functions

Low frequency filters: eliminate the gray-level detail and keep the general
gray-level appearance. (blurring the image)
High frequency filters: have less gray-level variations in smooth areas and
emphasized transitional (e.g., edge and noise) gray-level detail.
(sharpening images)
CORRESPONDENCE BETWEEN FILTERING IN THE SPATIAL AND FREQUENCY
DOMAIN

 Convolution theorem:
 The discrete convolution of two functions f(x,y) and h(x,y) of
size M  N is defined as
1 M 1 N 1
f ( x, y )  h ( x, y )   
MN m0 n 0
f (m, n)h( x  m, y  n)
M 1 N 1
1

MN
  h(m, n) f ( x  m, y  n)
m0 n 0

The process of implementation:


1) Flipping one function about the origin;
2) Shifting that function with respect to the other by changing
the values of (x, y);
3) Computing a sum of products over all values of m and n, for
each displacement.
–Let F(u,v) and H(u,v) denote the Fourier transforms of f(x,y) and
h(x,y), then
f ( x, y)  h( x, y)  F (u, v) H (u, v)
f ( x, y)h( x, y)  F (u, v)  H (u, v)

• an impulse function of strength A, located at coordinates


(x0,y0): A ( x  x0 , y  y0 ) and is defined by
M 1 N 1
:
 s( x, y) A ( x  x0 , y  y0 )  As ( x0 , y0 )
x 0 y 0
M 1 N 1

 s( x, y) ( x, y)  s(0,0)
x 0 y 0
The shifting property of impulse
function
where  ( x, y) : a unit impulse located at the origin
• The Fourier transform of a unit impulse at the origin
M 1 N 1
1 1
F (u, v) 
MN
  ( x,
x 0 y 0
y ) e  j 2 ( ux / M  vy / N )

MN
f ( x, y)   ( x, y)
 Let , then the convolution
1 M 1 N 1
f ( x, y )  h ( x, y )  
MN m0 n 0
 (m, n)h( x  m, y  n)

1
 h ( x, y )
MN
 Combine,we obtain:
f ( x, y )  h( x, y )  F (u , v) H (u , v)
 ( x, y )  h( x, y )   ( x, y )H (u , v)
1 1
h ( x, y ) H (u , v)
MN MN
h( x, y )  H (u , v)
That is to say, the response of
impulse input is the transfer
function of filter.
The distinction and links between spatial and frequency
filtering
If the size of spatial and frequency filters is same, then the
computation burden in spatial domain is larger than in
frequency domain;
However, whenever possible, it makes more sense to filter in the
spatial domain using small filter masks.
Filtering in frequency is more intuitive. We can specify filters in
the frequency, take their inverse transform, and the use the
resulting filter in spatial domain as a guide for constructing
smaller spatial filter masks.
Fourier transform and its inverse are linear process, so the
following discussion is limited to linear processes.
There is two reasons that filters based on Gaussian functions are of
particular importance: 1) their shapes are easily specified; 2) both
the forward and inverse Fourier transforms of a Gaussian are real
Gaussian function.
 Let H(u) denote a frequency domain, Gaussian filter
function given the equation
 u 2 / 2 2
H (u)  Ae
where  : the standard deviation of the Gaussian curve.
 The corresponding filter in the spatial domain is

2 2 2 x 2
h( x)  2 Ae
 u 2 / 212  u 2 / 2 22
H (u)  Ae  Be ,( A  B,1   2 )
The corresponding filter in the spatial domain is

2 212 x2 2 2 22 x2


h( x)  21 Ae  2 2 Be
We can note that the value of this types of filter has both negative and
positive values. Once the values turn negative, they never turn positive again.

Filtering in frequency domain is usually used for the guides to design the
filter masks in the spatial domain.
Some important properties of Gaussian filters functions

 One very useful property of the Gaussian function is that both it and its
Fourier transform are real valued; there are no complex values
associated with them.
 In addition, the values are always positive. So, if we convolve an image
with a Gaussian function, there will never be any negative output
values to deal with.
 There is also an important relationship between the widths of a
Gaussian function and its Fourier transform. If we make the width of
the function smaller, the width of the Fourier transform gets larger.
This is controlled by the variance parameter 2 in the equations.
 These properties make the Gaussian filter very useful for lowpass
filtering an image. The amount of blur is controlled by 2. It can be
implemented in either the spatial or frequency domain.
 Other filters besides lowpass can also be implemented by using two
different sized Gaussian functions.
TYPE 1: SMOOTHING FREQUENCY-DOMAIN FILTERS

 The basic model for filtering in the frequency domain


G(u, v)  H (u, v) F (u, v)
where F(u,v): the Fourier transform of the image to be
smoothed
H(u,v): a filter transfer function

 Smoothing is fundamentally a lowpass operation in the


frequency domain.
 There are several standard forms of lowpass filters (LPF).
 Ideal lowpass filter
 Butterworth lowpass filter
 Gaussian lowpass filter
Type 1.1 Ideal Low pass Filters (ILPFs)

 The simplest lowpass filter is a filter that “cuts off” all


high-frequency components of the Fourier transform
that are at a distance greater than a specified distance D0
from the origin of the transform.
 The transfer function of an ideal lowpass filter
1 if D(u, v)  D0
H (u, v)  
0 if D(u, v)  D0
where D(u,v) : the distance from point (u,v) to the center
of ther frequency rectangle (M/2, N/2)

 
1
D(u, v)  (u  M / 2) 2  (v  N / 2) 2 2
cutoff frequency

ILPF is a type of “nonphysical” filters and can’t be realized with electronic


components and is not very practical.
The blurring and ringing
phenomena can be seen, in
which ringing behavior is
characteristic of ideal filters.
Another example of ILPF

Figure 4.13 (a) A frequency-domain


ILPF of radius 5. (b) Corresponding
spatial filter. (c) Five impulses in the
spatial domain, simulating the values
of five pixels. (d) Convolution of (b)
and (c) in the spatial domain.
frequency

f ( x, y)  h( x, y)  F (u, v) H (u, v)
Notation: the radius of center
component and the number of spatial
circles per unit distance from
the origin are inversely
proportional to the value of the spatial
cutoff frequency.

diagonal scan line of (d)


spatial
Type 1.2 Butterworth Lowpass Filters (BLPFs) with order n
1
H (u, v) 
1  D(u, v) / D0 
2n

Note the relationship


between order n and
smoothing

The BLPF may be viewed as a transition between ILPF AND GLPF, BLPF of
order 2 is a good compromise between effective lowpass filtering and
acceptable ringing characteristics.
Butterworth Lowpass
Filters (BLPFs)

n=2
D0=5,15,30,80,and 230
Butterworth Lowpass Filters (BLPFs)
Spatial Representation

n=1 n=2 n=5 n=20


Type 1.3 Gaussian Lowpass Filters (FLPFs)

 D 2 ( u ,v ) / 2 D02
H (u, v)  e
Gaussian Lowpass
Filters (FLPFs)

D0=5,15,30,80,and 230
Additional Examples of Lowpass Filtering
Character recognition in machine perception: join the broken character
segments with a Gaussian lowpass filter with D0=80.
Application in “cosmetic processing” and produce a smoother,
softer-looking result from a sharp original.
Gaussian lowpass filter for reducing the horizontal sensor scan lines and
simplifying the detection of features like the interface boundaries.
86

SRM Institute of Science and Technology 06-02-2024


 A digital image is a grid of pixels.
 A pixel is the smallest element in an image.
 Each pixel corresponds to any one value called pixel intensity.
 The intensity of an image varies with the location of a pixel.
 The term spatial refers to space (or) Image Plane.
 Surface of the images is known as image plane
 Direct manipulation (or) process in pixels of an image
 Process of manipulating an image
 change the color, size, brightness, contrast etc...

 Result is more suitable than the original for a specific application.


 Used in many applications
 Adobe Photoshop
 Digital Cameras
 Printers
 Medical images
 Remote sensing images(Image Captured from satellites and aircrafts)
 The spatial domain process we discuss in this chapter can be
denoted by g(x,y) = T[f(x,y)]
 Where f(x,y) is the input image
 Where g(x,y) is the output image
 T is an operator and transformation function.
 Image enhancement provides more detailed image as compare to
non enhanced image (or) original image.
 The transformation function has been given below
s=T(r)
 'r' is the pixels of the input image.
 's' is the pixels of the output image.
 T is a transformation function that maps each value of r to each
value of s.
 Each image is represented in a 2D matrix of 'L' intensity levels.
 Each pixel takes a value between 0 – L-1.
 Color transformation (or) intensity transformation of grayscale
images.
 Black and white images.
 But most of the black and white images are have gray shades.
 Linear
 Negative and Identity Transformations
 Logarithmic
 Log and inverse log Transformations
 Power – law
 nth power and nth root Transformations
 Piecewise linear
 The word linear refers "straight line".
 A linear transformation is a function from one vector space to
another vector space
 Vector is collection of objects
 A linear transformation is also known as a linear operator or map.
 Linear transformation includes
 Identity Transformation
 Negative Transformation (or) Image Negatives
 Each value of the input image is directly mapped to each other value
of output image.
 That results in the same input image and output image. And hence
is called identity transformation.
 Inverse of identity transformation.
 Each value of the input image is subtracted from the L-1 and
mapped onto the output image.
 s = (L – 1) – r
 'r' is the pixel values of an image.
 Black = 0; white = 255
 The input image of Einstein is an 8 bpp image.
 so the number of intensity levels in this image are 256.
 Apply 256 in the equation, we get this
s = 255 – r
 So each value is subtracted by 255 and what happens is that, the
lighter pixels become dark and the darker picture becomes light.
And it results in image negative.
 Input Image Output Image
 The log transformations can be defined by
s = c log(r + 1)
 's' is pixel values of the output image
 'r' is pixel values of input image
 'c' is a constant and r ≥ 0
 The value 1 is added to each pixel value of the input image because
if pixel intensity is 0 in the image, then log (0) is equal to infinity. So
1 is added, to make the minimum value at least 1.
 Image enhancement technique
 Power-Law transformation have the basic form

(or)

 Where c and γ are positive constants


 This symbol γ is called gamma, also known as gamma
transformation.
 Variation in the value of γ varies the enhancement of the images.
 For example, the 3rd root of 27 is 3 as 3 x 3 x 3 is 27.
 The 5th root of 1,024 is 4, as 4 x 4 x 4 x 4 x 4 is 1,204.
 Different display devices / monitors have their own gamma
correction, that’s why they display their image at different intensity.
 Nth root - The number multiplied by itself n times to get the original
number.
 Two power law transformations, that include
 nth power transformation.
 nth root transformation.
 Plots of s versus r for various values of γ are shown in
 As in the case of log transformation, power-law curves with
fractional values of γ map a narrow range of dark input values into a
wider range of output values, with the opposite being true for higher
of input levels.
Correcting Gamma
s=cr^γ
s=cr^(1/2.5)
Gamma=10 Gamma=8 Gamma=6
 The form of piecewise linear functions can be arbitrary constant.
 Arbitrary Constant – Values of variables can be changed but the
output won't be changed
 Example ax+by=c
 Here a,b,c can be anything. There is no restrictions on their values
 It has more flexibility in the design of transformation.
 Contrast Stretching
 Intensity Level Slicing
 Bit Plane Slicing
 It is a process that used to improve the contrast in an image by
expands the intensity levels in an image
 Causes
 Low cost images can result can from poor illumination
 Lack of dynamic range from image sensor
 Wrong setting of a lens during an image acquisition is cause of
poor illumination image.
 Highlighting the specific range of intensities in an image.
 These transformations permit segmentation of certain gray level
regions from the rest of the image.
 This technique is useful when different features of an image are
contained in different gray levels.
 Instead of highlighting the intensity level ranges, we could highlight
the contribution made to total image appearance by specific bits
 The intensity of each pixels in a 256-level grayscale image is
composed of 8 bits
 Assuming that each pixel is represented by 8 bits, the image is
composed of 8 1-bit planes.
 Plane 1 contains the least significant bit and plane 8 contains the
most significant bit
 Useful for analyzing the relative importance played by each bit of
the image.
 Only the higher order bits (top four) contain visually significant
data.
 Plane 8 corresponds exactly with an image threshold at gray level
128
A histogram is an accurate graphical representation of
the distribution of numerical data.
 Contrast can be increased using histogram stretching.
 Histogram equalization is used to enhance contrast.
 Frequency of occurrence of each gray level in an image
 Generating the image histogram
 Systematic counting of the number of pixel
 Storing the results in a table and displaying results in chart
 Adjusting image intensities to enhance Contrast
 It is a bar graph
 Intensity level of digital image is 0-255[0-L-1]
 Discrete function
 P(rk)=nk/MN - K=0,1,2,….....,L-1
 rk is gray level, p(rk) is probability of occurrence of intensity level
 nk is no of pixels in an image with the intensity levels.
 MN – multiplication of rows and columns
The above image have two gray levels, 0 and 1.
Black = 0, white = 255
How the histogram demonstrated
Frequency is no of gray levels in an image(How many black colors and
Gray Level Frequency
white colors in an image)
In chart x axis = gray level 0
1
Y axis = frequency
 S=T(r) 0≤r≤L-1 - Condition(a)
 0≤r≤L-1 and 0≤T(r)≤L-1 - Condition (b)
 Condition(a)
 R denotes intensities of an image
 The range of 'r' is [0,L-1]
 That produce an output of intensity level 's' for every pixel in an
image
 T(r) is monotonically increasing function that output intensity
values will never be less than corresponding input values.
 Condition (b)
 Guarantees that the range of output intensities is the same as the
input.
 The fundamental descriptor of a random variable is its probability
density function
 Consider 3 bit image – 8 colors are there
 2power3 = 8 ; Intensity level [0 – 7]
 P(rk)=nk/MN
 Transformation Function (or) CDF

 T(r) - Transformation of intensity level


 Cumulative Distribution Function(CDF)
 S0 = 7 * 0.19 = 1.33 -----------------------------------------------------> 1
 S1 = 7 * (0.19 + 0.25) = 3.08 ------------------------------------------> 3
 S2 = 7 * (0.19+0.25+0.21) = 4.55 ------------------------------------> 5
 S3 = 7 * (0.19+0.25+0.21 + 0.16) = 5.67 ---------------------------> 6
 S4 = 7 * (0.19+0.25+0.21+0.16+0.08) = 6.23 ---------------------> 6
 S5 = 7 * (0.19+0.25+0.21+0.16+0.08+0.06) = 6.65 -------------> 7
 S6 = 7 * (0.19+0.25+0.21+0.16+0.08+0.06+0.03) = 6.86 -----> 7
 S7 = 7 * (0.19+0.25+0.21+0.16+0.08+0.06+0.03+0.02) = 7.00-> 7
 Original Histogram Equalized Histogram
 Example
 These elements are represents intensities of pixels
 Intensity value of these pixels between 1 – 8
 So, to increase the contrast between 1 – 20
 Probability Distribution Function(PDF) = no of pixels / 16
 Cumulative probability(CDF) = PDF + PDF * 10
 Final histogram Value = CDF * 20
 Pixel Value b4 Equalization Pixel Value after
Equalization
 Image Before Equalization Image
after Equalization
 Histogram specification is the transformation of an image.
 Used to generate the processed image that has a specified histogram
called histogram matching (or) histogram specification.
 Let 's' be a random variable in the property

 Let 'z' be a random variable in the property


 Filtering is a technique for modifying or enhancing an image
 Filters can highlight the features (or) remove the features of an
image.
 Eg: iris of an animal image
 Filters can accepting or rejecting certain frequency components
based on their types.
 Some filters accept the low quality images and display them. Some
don’t..
 Linear filters or smoothing filters
 Frequency domain filters.
 Highpass filters(passes signals with a higher frequency)
 Lowpass filters(passes signals with a lower frequency)
 Filters are used for
 Blurring and noise reduction(remove the
particular element)
 Edge detection(Increase the brightness sharply,
to show only edge of the image) and sharpness
 Moving the filter mask from point to point in an image.
 All the filters values are predefined.
 The value of a filter is calculated by a
predefined functions.
 This is Called the linear pixel.
 Filters values always depends on the
neighbor pixels.
 It visits each pixel in the input image.
 Spatial filter consist of
 Neighborhood
 Predefined operations - that is performed on image pixels.
 It creates the new pixel with coordinates equal to center of the
neighborhood.
 Original Pixels Filtered Pixels​
 Two Important Concepts in Spatial filtering
 Correlation
 Convolution
 Correlation is the process of moving filter mask over the image and
computing the sum of products at each element.
 The mechanism of convolution is same, except that the filter is
rotated by 180°
 local averaging.
 Let’s consider a simple averaging operation, we replace every pixel
5 4 2 3 7 4 6 5 3 6
in a 1D image by the average of that pixel and its two neighbors.
Suppose we have an image "I" equal to:

 Averaging is an operation that takes an image as input, and


produces a new image "J" as output.
 When we average the fourth pixel, for example, we replace the value
3 with the average of 2, 3, and 7.

 J(4) = (I(3)+I(4)+I(5))/3 = (2+3+7)/3


5 4 =2 4.3 7 4 6 5 3 6

 Pixel value 3 will be replaced by value 4

 J(3) = (I(2)+I(3)+I(4))/3 = (4+2+3)/3 = 3.


 Pixel value 2 will be replaced by value 3
 J(4) should only depend on I(3), I(4) and I(5).
 J(3) should only depend on I(2), I(3) and I(4).
 Averaging is linear because every new pixel is a linear combination
of the old pixels.
 Function(f) 1/9(coefficients) Output
2 1 0 6 7 1 1 1 2​ 1​ 0​
1 1 1
2 0 1 6 5 2​ 2 1
1 1 1
1 1 8 5 6 1​
1 0 6 6 5 2​ 1​ 0​
3 5 6 7 7
2​ 0​ 1​
1​ 1​ 8​

 1/9 *(1(2)+1(1)+1(0) + 1(2)+1(0)+1(1) +


1(1)+1(1)+1(8)) = 1/9*16 = 1.77 = 2
 Here "0, 1, 1, 8" is the local averaging pixel
 Function(f) 1/9(coefficients) Output
2 1 0 6 7 1​ 1​ 1​ 2​​ 1​​ 0​
2 0 1 6 5 1​ 1​ 1​
1​ 1​ 1​ 2​​ 2​ ​3
1 1 8 5 6
1 0 6 6 5 1​​ ​ ​
1​ 0​ 6​
3 5 6 7 7
0​ 1​ 6​
1​ 8​ 5​

 1/9 *(1(1)+1(0)+1(6) + 1(0)+1(1)+1(6) +


1(1)+1(8)+1(5)) = 1/9*28 = 3.11 = 3
 Final Output 2​​ 1​​ 0​

2​​ 2​​ ​3​


1​​ ​2 ​4
 The mechanism of convolution is same, Rotate the
correlation kernel 180° about its center element to
create a convolution kernel.
 Image (or) Function correlation convolution
17 24 1 8 15 1​ 8​ 15​ 2 9 4
23 5 7 14 16 7​ 14​ 16​ 7 5 3
4 6 13 20 22 6 1 8
10 12 19 21 3 13​ 20​ 22​
8 1 6
11 18 25 2 9
3 5 7
4 9 2
 1*2 + 8*9 + 15*4 + 7*7 + 14*5 + 16*3 + 13*6 + 20*1
+ 22*6 = 575
 575/9 =64
 Where "ws" are the coefficient of the m * n filter and the "zs" are
corresponding image intensities
 Generating m * n linear spatial mask it requires that we have to
specify the mn coefficients
 We want to replace the pixels in an image by 3 * 3 the minimum
value of original pixels should be 3 * 3
 Size should be same
 Used for blurring and noise reduction.
 Blurring is used as remove small details in an image.
 And bridging small gaps in lines (or) curves
 Average of the pixels in neighborhood around the central value.
 Highlighting the gross detail
 These filters are called averaging filters (or) lowpass filters.
 Sample Diagram
 Order-statistic filters are nonlinear spatial filters.
 It is based on ordering the pixels contained in the image area
encompassed by the Filter.
 Replacing the value of the center pixel with the value determined by
the ranking result.
 Replaces the value of a pixel by the median of the intensity values in
the neighborhood of that pixel is called median filter.
 Sharpening are highlighting the detail of an image
 Remove blurring from images
 Highlighting edges
 Edges of the images can be sharpened
 The derivative of digital functions are defined in terms of differences
 There are various ways to define these differences
 First Derivative
 Must be zero in areas of constant intensity
 Must be non-zero at the onset of intensity step (or) ramp
 Must be non-zero along ramps
 Second Derivative
 Must be zero in constant ares
 Must be non-zero at the onset and end of the intensity step (or)
ramp
 Must be zero along ramps of constant slope
 The basic definition of the first order derivative of a one dimensional
functional function f(x)

 Define the second order derivative of f(x)


 Sharpen images consist of subtracting the unsharp version of an
image from the original image called unsharp masking
 Consist of following steps
 Blur the original image
 Subtract the blurred image from original
 Add the mask to the original
The concept of frequency
 The period of cos( t ) is 2π seconds.
 i.e. The signal repeats itself after 2 π seconds.
 The period of cos(2 π · t ) is one second.
 The period is usually denoted T.
 Frequency is measured in Hz (Hertz) and is the number of periods
(or) cycles per second, denoted f. i.e f = 1/T
 The function cos(2 π · f t ) has a frequency of f and a period of 1/f
 Angular frequency is measured in rad/s, denoted ω, so ω = 2 π T
 Frequency is measured in hertz, cycles or periods per second.
 Higher frequency means more periods per second.
 Higher frequency means shorter period.
 Zero frequency implies infinite period, which means a constant
signal.
 Fourier transform of a function of time has units, cycles per second
Fourier transform of a function of pixels (like an image) will have
units, cycles per pixel.
Rapid changes in a signal correspond to high frequencies, slow
changes are represented by low frequencies
Rapid changes in intensity in an image are high frequencies.
 It is based on modify the Fourier transform to achieve a specific
objective
 Computing the inverse transform to obtain the processed result.
 The basic filtering equation

 is the IDFT
 F(u,v) is the DFT of the input image
F(x,y), H(u,v) is the filter function
G(x,y) is the filtered image
Functions F,H are arrays of size M * N
H(u,v) and F(u,v) is formed using array multiplication.
Low frequencies in the transform are related to slowly varying
intensity components in an image
High frequencies are caused by sharp transitions such as edges and
noise
 DFT is a complex array

 F(u,v) = R(u,v) + jI(u,v)

 Apply basic filtering equation, then becomes

High Frequency Components


 High frequency components correspond to edges in an image.

Low Frequency Components


 Low frequency components in an image correspond to smooth regions.
 Given an input image f(x, y) of size M x N, obtain the padding
parameters P and Q. We select P = 2M and Q = 2N.
 Form a padded image, f p(x, y), of size P x Q by appending the
necessary number of zeros to f (x, y).
 Multiply f p(x, y) by (-1)X" to center its transform.
 Compute the DFT, F(u, v), of the image from step 3.
 Generate a real, symmetric filter function, H(u, v), of size P x Q with
center at coordinates (P/2, Q/2). Form the product G(u, v) = H(u,
v)F(u, v) using array multiplication; that is, G(i, k) = H(i, k)F(i, k).
 Obtain the processed image

 Obtain the final processed result, g(x, y), by extracting the M x N


region from the top, left quadrant of gp(x, y).
Spatial Domain
we deal with images as it is. The value of the pixels of the image
change with respect to scene.
we directly deal with the image matrix.
Frequency Domain
we deal with the rate at which the pixel values are changing in
spatial domain.
Ideal Lowpass Filters
 A 2-D lowpass filter that passes without attenuation all frequencies
within a circle of radius 'Do' from the origin and "cuts off" all
frequencies outside this circle is called an ideal lowpass filter (ILPF)
 It is specified by the function

 where 'Do' is a positive constant and D(u, v) is the distance between


a point (u, v) in the frequency domain
 P and Q are the padded sizes

 ILPF cannot be realized with real electronic components


 For ILPF cross selection, the point of transition between H(u,v) = 1
and H(u,v) = 0 is called cutoff frequency
 Transfer function of a Butterworth lowpass filter (BLPF) of order n
and with cutoff frequency at a distance D0 from the origin:
 Gaussian Lowpass Filters (GLPFs) in two-dimensions.

 (σ = measure of spread about the center)


 (D0 = cutoff frequency)
Highpass Filtering
 Attenuation of the high-frequency components of the Fourier
transform of the image
 Radially symmetric filters
 All filter functions are assumed to be discrete functions of size PxQ.
 A highpass HHP filter can be obtained from a given lowpass HLP
filter by:
 A 2-D Ideal Highpass Filter (IHPF) is defined as
 A 2-D Butterworth Highpass Filter (BHPF) of order n and cutoff
frequency D0 is defined as
 The transfer function of the Gaussian Highpass Filter (GHPF) with
cutoff frequency locus at a distance D0 from the center of the
frequency rectangle is defined as
 The Laplacian in the Frequency Domain

 Or, with respect to the center of the frequency rectangle:

 The Laplacian image is obtained by:


 Enhancement of the image is achieved using (H(u,v) negative)
 Used to improving the appearance of an image by simultaneous intensity
range compression and contrast enhancement
 An image f(x,y) can be expressed as the product of its illumination I(x,y)
and reflectance r(x,y)

 This equation cannot be used directly to operate on the frequency


components of illumination and reflectance because of Fourier transform
of a product

You might also like