Professional Documents
Culture Documents
DIP Slides - Merged
DIP Slides - Merged
DIGITAL IMAGE
PROCESSING
SEM I – 2023-24
LECTURE 01
August 14, 2023 Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus
WORD OF CAUTION
➢ The course textbook and reference books are the primary study materials. These slides 2
➢ Hence, in case of any ambiguity regarding the completeness and correctness of these
➢ These slides are provided for your reference. Do not share or reproduce the content
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
COURSE HANDOUT (1)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
COURSE HANDOUT (2)
➢ E-mail: ravik@goa.bits-pilani.ac.in
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
MAKE-UP POLICY
Application for Make-up will be considered only for Mid-Sem and Comprehensive
Campus Medical center) needs to be submitted to the IC of the course at least a day before
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
ATTENDANCE POLICY
6
Since BITS-Pilani is a residential campus, all students are expected to engage in all
regular and special lectures/tutorials announced by the instructors. Attendance and class
participation of the student will be considered during final grading and will be based on
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
GRADING NOTICE
All students registered in the course are expected to appear for all evaluation 7
components. Per section 4.19 of the BITS, Pilani Academic regulations, NC may be
given to students if they fail to provide a chance for the instructor to evaluate their
progress in the class. Absence in any evaluation components without prior consent of
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus 14 August 2023
HONOR CODE AND DISCIPLINARY ACTION
8
All submissions by students in this class towards any evaluation component will be
considered their own original and individual work. It will be assumed that the
students have not resorted to any unfair means during the evaluation. If malpractice
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
WHY DIGITAL IMAGE PROCESSING?
➢ Vision is the most advanced of our senses, so images play the single most important role in human
perception (limited to the visual band of the electromagnetic (EM) spectrum). 9
➢ Imaging machines cover almost the entire EM spectrum, ranging from gamma to radio waves. These
include ultrasound, electron microscopy, and computer-generated images.
➢ The course provides an introduction to basic concepts and methodologies applicable to digital image
processing.
➢ The course develops a foundation for further study and research in this field.
➢ The course material is fundamental whose scope of application is not limited to the solution of
specialized problems.
➢ The mathematical complexity of the course requires introductory preparation in linear algebra,
probability and statistics, linear systems, and MATLAB.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
WHAT IS DIGITAL IMAGE PROCESSING? (1)
➢ Digital image is composed of a finite number of elements, each of which has a particular
10
location and value. These elements are called pixels.
➢ 𝒇(𝒙, 𝒚) where 𝒙, 𝒚 represent spatial (plane) co-ordinates and the amplitude of 𝒇 represents
the intensity or gray level of the image at that point.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus 14 August 2023
WHAT IS DIGITAL IMAGE PROCESSING? (2)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
WHAT IS DIGITAL IMAGE PROCESSING? (3)
12
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
WHAT IS DIGITAL IMAGE PROCESSING? (4)
➢ Consider the area of automated analysis of text.
➢ Digital image processing: 13
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
APPLICATIONS
➢ Image processing applications can be categorized based on their source.
➢ acoustic
➢ ultrasonic
➢ electronic (in the form of electron beams used in electron microscopy), and
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
FUNDAMENTAL STEPS IN DIGITAL IMAGE PROCESSING
15
Objective
Subjective
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
DIGITAL IMAGE ACQUISITION PROCESS (1)
16
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
DIGITAL IMAGE ACQUISITION PROCESS (2)
➢ Intensity (gray level) of a monochrome image at any coordinates (𝑥, 𝑦) is denoted by 𝑓 𝑥, 𝑦
➢ 0 ≤ 𝑓 𝑥, 𝑦 < ∞ 17
➢ 𝑓 𝑥, 𝑦 = 𝑖 𝑥, 𝑦 𝑟 𝑥, 𝑦
➢ The range [𝐿min , 𝐿max ] is called the intensity or gray scale. Usually [0, 1] or [0, 𝐶] with 0
18
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
SAMPLING AND QUANTIZATION (2)
ordinates respectively
digital image is 𝑏 = 𝑀 × 𝑁 × 𝑘
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
SAMPLING AND QUANTIZATION (3)
20
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
LINEAR VS COORDINATE INDEXING
➢ 𝛼 = 𝑀𝑦 + 𝑥
➢ Coordinate indexing:
➢ 𝑥 = 𝛼 mod 𝑀
➢ 𝑦 = (𝛼 − 𝑥)/𝑀
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
SPATIAL AND INTENSITY RESOLUTION
Usually expressed as pixels per unit distance. (sometimes dots per inch (dpi)).
spatial units.
level.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
F435 1
DIGITAL IMAGE
PROCESSING
SEM I – 2023-24
LECTURE 02
August 16, 2023 Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus
WORD OF CAUTION
➢ The course textbook and reference books are the primary study materials. These slides 2
➢ Hence, in case of any ambiguity regarding the completeness and correctness of these
➢ These slides are provided for your reference. Do not share or reproduce the content
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS - NEIGHBORS
Let 𝑝 = (𝑥, 𝑦). Green pixels are the 4-neighbors: 𝑵𝟒 (𝒑), Yellow are the diagonal
neighbors: 𝑵𝑫 (𝒑), and the two together form the 8-neighbors: 𝑵𝟖 (𝒑) = 𝑵𝟒 (𝒑) ∪ 𝑵𝑫 (𝒑)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS - ADJACENCY
➢ Let 𝑽 be the set of intensity values used to define adjacency. In a binary image, 𝑽 = {𝟏} if
we are referring to adjacency of pixels with value 𝟏. 4
➢ 4-adjacency. Two pixels 𝑝 and 𝑞 with values from 𝑉 are 4-adjacent if 𝑞 is in the set 𝑁4 (𝑝).
➢ 8-adjacency. Two pixels 𝑝 and 𝑞 with values from 𝑉 are 8-adjacent if 𝑞 is in the set 𝑁8 (𝑝).
➢ m-adjacency (also called mixed adjacency). Two pixels 𝑝 and 𝑞 with values from 𝑉 are m-
adjacent if
➢ 𝒒 is in 𝑵𝟒 (𝒑), or
➢ 𝒒 is in 𝑵𝑫 (𝒑) and the set 𝑵𝟒 𝒑 ∩ 𝑵𝟒 (𝒒) has no pixels whose values are from 𝑽.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS - ADJACENCY
Coordinates
(0,0) (1,0) (2,0)
5
(0,1) (1,1) (2,1)
(0,2) (1,2) (2,2)
0 1 1 0 1 1 0 1 1
0 1 0 0 1 0 0 1 0
0 0 1 0 0 1 0 0 1
(a) (b) (c)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – PATHS (1)
➢ A digital path (or curve) from pixel 𝒑 with coordinates (𝒙,𝟎 𝒚𝟎 ) to pixel 𝒒 with coordinates
6
(𝒙𝒏 , 𝒚𝒏 ) is a sequence of distinct pixels with coordinates (𝒙𝟎 , 𝒚𝟎 ), (𝒙𝟏 , 𝒚𝟏 ), … , (𝒙𝒏 , 𝒚𝒏 ) where
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – PATHS (2)
3 4 1 2 0 7
0 1 0 4 2 (𝑞)
(𝑝) 2 2 3 1 4
3 0 4 2 1
1 2 0 3 4
Let 𝑉 = {0,1,2}. Compute the shortest 4 −, 8 − and 𝑚 − path between the pixels 𝑝 and 𝑞.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – REGIONS (1)
➢ Let 𝑆 represent a subset of pixels in an image. Two pixels 𝑝 and 𝑞 are said to be connected in
𝑆 if there exists a path between them consisting entirely of pixels in 𝑆. 8
➢ For any pixel 𝑝 in 𝑆, the set of pixels that are connected to it in 𝑆 is called a connected
component of 𝑆. If it only has one component, and that component is connected, then 𝑆 is
called a connected set.
➢ Let 𝑅 represent a subset of pixels in an image. We call 𝑅 a region of the image if 𝑅 is a
connected set.
➢ Two regions, 𝑅𝑖 and 𝑅𝑗 are said to be adjacent if their union forms a connected set.
➢ Regions that are not adjacent are said to be disjoint. We consider 𝟒 − and 𝟖 −adjacency
when referring to regions.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – REGIONS (2)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – REGIONS (3)
10
(a) (b)
(a) Two regions (of 1’s) that are 8 − adjacent, (b) The circled point is on
the boundary of the 1 − valued pixels only if 8 − adjacency between the
region and background is used.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – REGIONS (4)
𝑆1 𝑆2
11
0 0 0 0 0 0 0 1 1 0
1 0 0 1 0 0 1 0 0 1
1 0 0 1 0 1 1 0 0 0
0 0 1 1 1 0 0 0 0 0
0 0 1 1 1 0 0 1 1 1
Let 𝑉 = {1} and 𝑆1 and 𝑆2 represent two image subsets. Determine whether the two
subsets are (a) 4 −adjacent, (b) 8 −adjacent, or (c) 𝑚 −adjacent.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – DISTANCE (1)
➢ For pixels 𝑝, 𝑞, and 𝑠, with coordinates (𝑥, 𝑦), (𝑢, 𝑣), and (𝑤, 𝑧), respectively, 𝐷 is a
12
distance function or metric if
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – DISTANCE (2)
➢ The 𝑫𝟒 distance, (called the city-block distance) between 𝑝 and 𝑞 is defined as
𝐷4 𝑝, 𝑞 = 𝑥 − 𝑢 + |𝑦 − 𝑣|
13
➢ Pixels having a 𝐷4 distance from (𝑥, 𝑦) that is less than or equal to some value 𝑑
form a diamond centered at (𝑥, 𝑦).
➢ The pixels with 𝐷4 distance ≤ 2 from (𝑥, 𝑦) (the center point) form the following
contours of constant distance:
(𝑥, 𝑦)
(𝑥, 𝑦)
(𝑥, 𝑦)
15
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
ARITHMETIC OPERATIONS BETWEEN TWO
IMAGES - ADDITION
16
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
ARITHMETIC OPERATIONS BETWEEN TWO
IMAGES - SUBTRACTION
17
Digital subtraction
angiography. (a)
Mask image. (b) A
live image. (c)
Difference between
(a) and (b). (d)
Enhanced difference
image. (Figures (a)
and (b)
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
ARITHMETIC OPERATIONS BETWEEN TWO
IMAGES – MULTIPLICATION
18
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
LOGICAL OPERATIONS BETWEEN TWO IMAGES
19
Illustration of logical
operations involving
foreground (white)
pixels. Black represents
binary 0’s and white
binary 1’s.
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
GEOMETRIC TRANSFORMATIONS
➢ Intensity interpolation that assigns intensity values to the spatially transformed pixels
➢ The transformation of coordinates may be expressed as
For example, the transformation (𝑥′, 𝑦′) = (𝑥/2, 𝑦/2) shrinks the original image to half
its size in both spatial directions.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
F435 1
DIGITAL IMAGE
PROCESSING
SEM I – 2023-24
LECTURE 03
August 17, 2023 Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus
WORD OF CAUTION
➢ The course textbook and reference books are the primary study materials. These slides 2
➢ Hence, in case of any ambiguity regarding the completeness and correctness of these
➢ These slides are provided for your reference. Do not share or reproduce the content
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
GEOMETRIC TRANSFORMATIONS
➢ Intensity interpolation that assigns intensity values to the spatially transformed pixels
➢ The transformation of coordinates may be expressed as
For example, the transformation (𝑥′, 𝑦′) = (𝑥/2, 𝑦/2) shrinks the original image to half
its size in both spatial directions.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
GEOMETRIC TRANSFORMATIONS - AFFINE TRANSFORMATIONS (1)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
GEOMETRIC TRANSFORMATIONS - AFFINE TRANSFORMATIONS (2)
Images from “R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009”
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
GEOMETRIC TRANSFORMATIONS - AFFINE TRANSFORMATIONS (3)
Images from “R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009”
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
GEOMETRIC TRANSFORMATIONS - AFFINE TRANSFORMATIONS (4)
➢ A significant advantage of being able to perform all transformations using the unified
representation is that it provides the framework for concatenating a sequence of 7
operations.
➢ For example, if we want to resize an image, rotate it, and move the result to some
location, we simply form a 3 × 3 matrix equal to the product of the scaling, rotation, and
translation matrices shown in the previous slides.
➢ The preceding transformation moves the coordinates of pixels in an image to new locations.
➢ To complete the process, we have to assign intensity values to those locations. This task is
accomplished using intensity interpolation: nearest neighbor, bilinear, and bicubic
interpolation techniques.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
GEOMETRIC TRANSFORMATIONS - AFFINE TRANSFORMATIONS (5)
and, at each location (𝑥, 𝑦), computing the spatial location (𝑥′, 𝑦′) of the corresponding
pixel in the output image using the matrix relation directly.
➢ Problems with the forward mapping approach:
➢ Two or more pixels in the input image can be transformed to the same location in the
output image, raising the question of how to combine multiple output values into a
single output pixel value.
➢ In addition, it is possible that some output locations may not be assigned a pixel at all.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
GEOMETRIC TRANSFORMATIONS - AFFINE TRANSFORMATIONS (6)
➢ The second approach, called inverse mapping, scans the output pixel locations and, at
9
each location (𝑥′, 𝑦′), computes the corresponding location in the input image using
➢ It then interpolates (using one of the techniques mentioned earlier) among the nearest
➢ Inverse mappings are more efficient to implement than forward mappings, and are used
10
Images from “R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009”
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
REPRESENTATION OF COLOR IMAGES (1)
➢ In multispectral image processing, each pixel of an RGB image has three components, which
can be organized in the form of a column vector. 11
𝑧1
𝑧 = 𝑧2
𝑧3
where 𝑧1 is the intensity of the pixel in the red image, and 𝑧2 and 𝑧3 are the corresponding pixel
intensities in the green and blue images, respectively.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
REPRESENTATION OF COLOR IMAGES (1)
12
➢ Conversion from RGB to gray scale.
𝑧1 +𝑧2 +𝑧3
➢ Averaging:
3
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
INTENSITY TRANSFORMATIONS (1)
➢ Based on the expression
𝑔 𝑥, 𝑦 = 𝑇[𝑓 𝑥, 𝑦 ] 13
where 𝑓(𝑥, 𝑦) is an input image, 𝑔(𝑥, 𝑦) is the output image, and 𝑇 is an operator on 𝑓
defined over a neighborhood of point (𝑥, 𝑦).
➢ The smallest possible neighborhood is of size 1 × 1. In this case, 𝑔 depends only on the
value of 𝑓 at a single point (𝑥, 𝑦) and the operator 𝑇 becomes an intensity (also called a
gray-level, or mapping) transformation function of the form
𝑠 = 𝑇(𝑟)
where, for simplicity in notation, we use 𝑠 and 𝑟 to denote, respectively, the intensity of 𝑔
and 𝑓 at any point 𝑥, 𝑦 .
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS (2)
14
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – IMAGE NEGATIVE (1)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – IMAGE NEGATIVE (2)
16
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – LOG TRANSFORM
(a) Fourier spectrum (with values in the range 0 to 1.5 × 106 ) displayed as a grayscale image. (b) Result of applying
the log transformation with 𝑐 = 1 (range reduces to 0 to 6.2). Both the images are scaled to the range [0, 255].
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – POWER-LAW (GAMMA)
TRANSFORM (1)
➢ Power-law transformation function:
18
𝛾
𝑠 = 𝑐𝑟
➢ The response of many devices used for image capture, printing, and display obey a power law.
➢ By convention, the exponent in a power-law equation is referred to as gamma [hence our use
of this symbol in the equation above].
➢ The process used to correct these power-law response phenomena is called gamma
correction or gamma encoding.
➢ For example, cathode ray tube (CRT) devices have an intensity-to-voltage response that is a
power function, with exponents varying from approximately 1.8 to 2.5.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – POWER-LAW (GAMMA)
TRANSFORM (2)
19
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – CONTRAST
STRETCHING (1)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – CONTRAST
STRETCHING (2)
21
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – INTENSITY
LEVEL SLICING (1)
➢ There are applications in which it is of interest to highlight a specific range of intensities
22
in an image.
➢ Some of these applications include enhancing features in satellite imagery, such as
masses of water, and enhancing flaws in X-ray images.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – INTENSITY
LEVEL SLICING (2)
23
(a) Aortic angiogram. (b) Result of using a slicing transformation of the type illustrated in the previous
slide in Fig. (a), with the range of intensities of interest selected in the upper end of the gray scale. (c)
Result of using the transformation in the previous slide in Fig. (b), with the selected range set near
black, so that the grays in the area of the blood vessels and kidneys were preserved.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS - BIT-PLANE
SLICING (1)
➢ Separating a digital image into its bit planes is useful for analyzing the relative
24
importance played by each bit of the image.
➢ We can determine the adequacy of number of bits used to quantize each pixel,
useful for image compression.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
INTENSITY TRANSFORMATIONS - BIT-PLANE
SLICING (2)
25
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS - BIT-PLANE
SLICING (3)
26
(a) An 8-bit gray-scale image of size 550 × 1192 pixels. (b) through (i) Bit planes 8 through
1, with bit plane 1 corresponding to the least significant bit. Each bit plane is a binary image.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS - BIT-PLANE
SLICING (4)
➢ The reconstruction is done by multiplying the pixels of the 𝑛𝑡ℎ plane by the constant 2𝑛−1 .
➢ This converts the nth significant binary bit to decimal. 27
➢ Each bit plane is multiplied by the corresponding constant, and all resulting planes are
added to obtain the grayscale image. Thus, to obtain image (a) in the figure below, we
multiplied bit plane 8 by 128, bit plane 7 by 64, and added the two planes.
Image reconstructed from bit planes: (a) 8 and 7; (b) 8, 7, and 6; (c) 8, 7, 6, and 5.
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
IMAGE TRANSFORMS (1)
➢ In some cases, image processing tasks are best formulated by transforming the
28
input images, carrying the specified task in a transform domain, and applying the
inverse transform to return to the spatial domain.
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
IMAGE TRANSFORMS (2)
𝑀−1 𝑁−1
𝑓 𝑥, 𝑦 = 𝑇 𝑢, 𝑣 𝑠(𝑥, 𝑦, 𝑢, 𝑣)
𝑢=0 𝑣=0
where 𝑠(𝑥, 𝑦, 𝑢, 𝑣) is called an inverse transformation kernel
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
IMAGE TRANSFORMS (3)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
IMAGE TRANSFORMS (4)
31
(a) Image corrupted by sinusoidal
interference. (b) Magnitude of the Fourier
transform showing the bursts of energy
caused by the interference (the bursts were
enlarged for display purposes). (c) Mask used
to eliminate the energy bursts. (d) Result of
computing the inverse of the modified
Fourier transform.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
F435 1
DIGITAL IMAGE
PROCESSING
SEM I – 2023-24
LECTURE 04
August 23, 2023 Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus
WORD OF CAUTION
➢ The course textbook and reference books are the primary study materials. These slides 2
➢ Hence, in case of any ambiguity regarding the completeness and correctness of these
➢ These slides are provided for your reference. Do not share or reproduce the content
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM PROCESSING
➢ A histogram of an image is the graphical interpretation of the image’s pixel intensity values
➢ A histogram is a graph that shows the frequency of occurring of data in the whole data set 3
ℎ 𝑟𝑘 𝑛𝑘
𝑝 𝑟𝑘 = =
𝑀𝑁 𝑀𝑁
➢ Sum of all values of 𝑝(𝑟𝑘 ) is equal to 1.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM PROCESSING – CONTRAST (1)
➢ For a grayscale image, the intensity levels are between 0 (corresponding to black) and 𝐿 − 1
4
(corresponding to white).
➢ If the light intensity levels of the pixels are more towards 𝐿 − 1, it can be said that the image
is brighter compared to an image with lesser light intensity values.
➢ Contrast can be simply explained as the difference between maximum and minimum pixel
intensity in an image.
➢ If an image lacks contrast, it may appear washed out and images that look washed out and
dark and highlights of images might be lost.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM PROCESSING – CONTRAST (2)
Four image types and their corresponding histograms. (a) dark; (b) light; (c) low contrast; (d) high
contrast. The horizontal axis of the histograms are values of 𝑟𝑘 and the vertical axis are values of 𝑝(𝑟𝑘 ).
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM MANIPULATION
𝑓 𝑥, 𝑦 − 𝑓𝑚𝑖𝑛
𝑔 𝑥, 𝑦 = 𝑓𝑛𝑒𝑤_𝑚𝑎𝑥 − 𝑓𝑛𝑒𝑤_𝑚𝑖𝑛 + 𝑓𝑛𝑒𝑤_𝑚𝑖𝑛
𝑓𝑚𝑎𝑥 − 𝑓𝑚𝑖𝑛
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – CDF BASICS (1)
➢ Consider a random variable obtained by selecting a pixel randomly from the image,
8
with intensity denoted by 𝑟.
➢ Then the probability of getting a particular intensity 𝑟𝑘 is given by,
𝑛𝑘
𝑝𝑟 𝑟𝑘 = P 𝑟 = 𝑟𝑘 =
𝑀𝑁
where 𝑛𝑘 is the number of pixels with intensity 𝑟𝑘 .
➢ CDF is given by
𝑘
𝑛𝑖
P 𝑟 ≤ 𝑟𝑘 =
𝑀𝑁
𝑖=1
➢ CDF is monotonically increasing.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – CDF BASICS (2)
(a) Monotonic increasing function, showing how multiple values can map to a single value.
(b) Strictly monotonic increasing function. This is a one-to-one mapping, both ways.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – CDF BASICS (3)
➢ The intensity of an image may be viewed as a random variable in the interval [0, 𝐿 − 1].
➢ Let 𝑝𝑟 (𝑟) and 𝑝𝑠 (𝑠) denote the PDFs of intensity values 𝑟 and 𝑠 in two different images.
10
𝑠 = 𝑇 𝑟 = (𝐿 − 1) න 𝑝𝑟 𝑤 𝑑𝑤
𝑟 0
𝑑𝑠 𝑑𝑇(𝑟) 𝑑
= = 𝐿−1 න 𝑝𝑟 𝑤 𝑑𝑤 = 𝐿 − 1 𝑝𝑟 (𝑟)
𝑑𝑟 𝑑𝑟 𝑑𝑟
0
1 𝟏
𝒑𝒔 𝒔 = 𝑝𝑟 𝑟 = ,0 ≤ 𝑠 ≤ 𝐿 − 1
𝐿 − 1 𝑝𝑟 𝑟 𝑳−𝟏
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – CDF BASICS (3)
𝑠=𝑇 𝑟 11
(a) An arbitrary PDF. (b) Result of applying the 𝑇(𝑟) described in the previous slide to the
input PDF. The resulting PDF is always uniform, independently of the shape of the input.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – STEPS
➢ Histogram equalization
𝑘
𝑠𝑘 = 𝑇 𝑟𝑘 = 𝐿 − 1 𝑝𝑟 𝑟𝑖 , 0≤𝑘 ≤𝐿−1
𝑖=1
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – APPLICATION (1)
13
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – APPLICATION (2)
14
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – EXAMPLE (1)
15
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – EXAMPLE (2)
16
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – EXAMPLE (3)
17
Equalized image
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – CONTRAST ENHANCEMENT
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
F435 1
DIGITAL IMAGE
PROCESSING
SEM I – 2023-24
LECTURE 05
August 25, 2023 Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus
WORD OF CAUTION
➢ The course textbook and reference books are the primary study materials. These slides 2
➢ Hence, in case of any ambiguity regarding the completeness and correctness of these
➢ These slides are provided for your reference. Do not share or reproduce the content
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM EQUALIZATION
➢ Histogram equalization
𝑘
𝑠𝑘 = 𝑇 𝑟𝑘 = 𝐿 − 1 𝑝𝑟 𝑟𝑖 , 0≤𝑘 ≤𝐿−1
𝑖=1
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM EQUALIZATION – EXAMPLE (1)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM EQUALIZATION – EXAMPLE (2)
Histogram equalization. (a) Original histogram. (b) Transformation function. (c) Equalized
histogram.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM EQUALIZATION – CONTRAST
ENHANCEMENT
➢ Because a histogram is an approximation to a PDF, and no new allowed intensity
6
levels are created in the process, perfectly flat histograms are rare in practical
applications of histogram equalization using the method just discussed.
➢ Thus, unlike its continuous counterpart, it cannot be proved in general that discrete
histogram equalization results in a uniform histogram.
➢ However, discrete histogram equalization has the general tendency to spread the
histogram of the input image so that the intensity levels of the equalized image span a
wider range of the intensity scale. The net result is contrast enhancement.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING
Histogram equalization
7
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING
➢ The method used to generate images that have a specified histogram is called histogram
matching or histogram specification.
8
➢ Given an image in which the pixel pdf is 𝑝𝑟 (𝑟𝑘 ), perform histogram equalization
𝑘
➢ Given an output image with pixel pdf 𝑝𝑧 (𝑧𝑞 ) as a specification, perform histogram equalization
𝑞
𝐺 𝑧𝑞 = 𝐿 − 1 𝑝𝑧 𝑧𝑖 −−− −(2)
𝑖=0
𝐺 𝑧𝑞 = 𝑠𝑘
𝑧𝑞 = 𝐺 −1 𝑠𝑘 = 𝐺 −1 (𝑇(𝑟𝑘 ))
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – STEPS
➢ Compute the histogram, 𝑝𝑟 (𝑟𝑘 ), of the input image, and use 𝑠𝑘 = 𝑇(𝑟𝑘 ) to map the intensities in the
input image to the intensities in the histogram-equalized image. Round the resulting values, 𝑠𝑘 , to the
integer range [0, 𝐿 − 1]. 9
➢ Compute all values of function 𝐺𝑧 (𝑧𝑞 ) using the Eq. (2) in the previous slide for 𝑞 = 0,1, 2, … , 𝐿 − 1,
where 𝑝𝑧 (𝑧𝑖 ) are the values of the specified histogram. Round the values of 𝐺 to integers in the range
[0, 𝐿 − 1]. Store the rounded values of 𝐺 in a lookup table.
➢ For every value of 𝑠𝑘 , 𝑘, = 0,1, 2, … , 𝐿 − 1, use the stored values of 𝐺 from Step 2 to find the
corresponding value of 𝑧𝑞 so that 𝐺𝑧 (𝑧𝑞 ) is closest to 𝑠𝑘 . Store these mappings from 𝑠 to 𝑧. When more
than one value of 𝑧𝑞 gives the same match (i.e., the mapping is not unique), choose the smallest value by
convention.
➢ Form the histogram-specified image by mapping every equalized pixel with value 𝑠𝑘 to the
corresponding pixel with value 𝑧𝑞 in the histogram-specified image, using the mappings found in Step 3.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – EXAMPLE (1)
10
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – EXAMPLE (2)
Histogram equalization of the input image
11
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – EXAMPLE (3)
Histogram equalization of the output image
12
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – EXAMPLE (4)
𝒓𝒌 𝒔𝒌 𝑮(𝒛𝒒 ) 𝒛𝒒 𝒓𝒌 𝒑𝒓 (𝒓𝒌 ) 𝒛𝒒 Matched 𝒛𝒒 Specified
𝒑𝒛 (𝒛𝒒 ) 𝒑𝒛 (𝒛𝒒 )
0 1 0 0 13
0 0.19 3 0.19 0 0
1 3 0 1
1 0.25 4 0.25 1 0
2 5 0 2
2 0.21 5 0.21 2 0
3 6 1 3
3 0.16 6 3 0.15
4 6 2 4 0.24
4 0.08 6 4 0.20
5 7 5 5
5 0.06 7 5 0.30
6 7 6 6
6 0.03 7 0.11 6 0.20
7 7 7 7
7 0.02 7 7 0.15
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – EXAMPLE (5)
14
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – APPLICATION (1)
15
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – APPLICATION (2)
16
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM STATISTICS - GOLBAL
➢ For an image with intensity levels in the range [0, 𝐿 − 1], the 𝑛𝑡ℎ moment of 𝑟 about its mean,
𝑚, is defined as 𝐿−1 17
𝜇𝑛 = 𝑟𝑖 − 𝑚 𝑛 𝑝𝑟 (𝑟𝑖 )
𝑖=0
where 𝑚 is given by 𝐿−1
𝑚 = 𝑟𝑖 𝑝𝑟 (𝑟𝑖 )
𝑖=0
➢ The mean is a measure of average intensity and the variance 𝜎 2 (or standard deviation, 𝜎),
given by 𝐿−1
𝜎 2 = 𝜇2 = 𝑟𝑖 − 𝑚 2 𝑝𝑟 (𝑟𝑖 )
𝑖=0
is a measure of image contrast.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM STATISTICS - LOCAL
➢ Let (𝑥, 𝑦) denote the coordinates of any pixel in a given image, and let 𝑆𝑥𝑦 denote a
neighborhood of specified size, centered on (𝑥, 𝑦).
18
➢ Mean value of the pixels in the neighborhood 𝑆𝑥𝑦 is
𝐿−1
𝑚 = 𝑟𝑖 𝑝𝑆𝑥𝑦 (𝑟𝑖 )
𝑖=0
𝐿−1
2
𝜎𝑆2𝑥𝑦 = 𝑟𝑖 − 𝑚𝑆𝑥𝑦 𝑝𝑆𝑥𝑦 (𝑟𝑖 )
𝑖=0
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM STATISTICS – LOCAL ENHANCEMENT (1)
19
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM STATISTICS – LOCAL ENHANCEMENT (2)
20
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
F435 1
DIGITAL IMAGE
PROCESSING
SEM I – 2023-24
LECTURE 06
August 28, 2023 Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus
WORD OF CAUTION
Ø The course textbook and reference books are the primary study materials. These slides 2
Ø Hence, in case of any ambiguity regarding the completeness and correctness of these
Ø These slides are provided for your reference. Do not share or reproduce the content
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING
Ø Spatial filtering modifies an image by replacing the value of each pixel by a function of the
values of the pixel and its neighbors. 3
Ø If the operation performed on the image pixels is linear, then the filter is called a linear spatial
filter. Otherwise, the filter is a nonlinear spatial filter.
Ø The method used to generate images that have a specified histogram is called histogram
matching or histogram specification.
Ø A linear spatial filter performs a sum-of-products operation between an image ! and a filter
kernel, ".
Ø The kernel (mask or template or window) is an array whose size defines the neighborhood of
operation, and whose coefficients determine the nature of the filter.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (1)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (2)
Ø At any point (#, $) in the image, the response, %(#, $), of the filter is the sum of products of
the kernel coefficients and the image pixels encompassed by the kernel:
5
Ø As coordinates # and $ are varied, the center of the kernel moves from pixel to pixel,
generating the filtered image, %, in the process.
Ø Typically for a kernel of size & × ', we assume that & = 2* + 1 and ' = 2- + 1, where a
and b are nonnegative integers.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (3)
Ø Correlation: the correlation of a kernel " of size & × ' with an image !(#, $), denoted as
("!)(#, $), is given by: 6
Ø Convolution: the convolution of a kernel " of size & × ' with an image !(#, $), denoted as
("!)(#, $), is given by:
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (4)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (5)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (6)
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (7)
10
In this course, when we use the term linear spatial filtering, we mean
convolving a kernel with an image.
If all the individual kernels are of size & × ', it follows from these equations
that " will be of size ./ × .0 , where
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (8)
two 1-D functions, 45 (#, $) and 46 (#, $); that is, 4 #, $ = 45 #, $ 46 (#, $).
Ø A spatial filter kernel is a matrix, and a separable kernel is a matrix that can be
expressed as the outer product of two vectors.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (9)
Ø A separable kernel of size & × ' can be expressed as the outer product of two vectors, 7
and ": 12
" = 89 :
where 8 and 9 are vectors of size & × 1 and ' × 1 respectively.
Ø For a square kernel of size & × &, we write
" = 88 :
Ø It turns out that the product of a column vector and a row vector is the same as the 2-D
convolution of the vectors.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (10)
requires on the order of >?@A
multiplications and additions.
&×' ;×< 13
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SPATIAL FILTERING – LINEAR SPATIAL FILTERING (11)
Ø We know from matrix theory that a matrix resulting from the product of a column vector
and a row vector always has a rank of 1. 14
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING (LOWPASS) SPATIAL FILTER
Ø Smoothing (also called averaging) spatial filters are used to reduce sharp transitions in
intensity.
15
Ø Applications:
Ø Because random noise typically consists of sharp transitions in intensity, an obvious
application of smoothing is noise reduction.
Ø Smoothing prior to image resampling to reduce aliasing, is also a common application.
Ø Smoothing is used to reduce irrelevant detail in an image, where “irrelevant” refers to
pixel regions that are small with respect to the size of the filter kernel.
Ø Another application is for smoothing the false contours that result from using an
insufficient number of intensity levels in an image.
Ø Smoothing filters are used in combination with other techniques for image
enhancement, such as the histogram processing techniques, and unsharp masking, as
discussed later in this module.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER –BOX KERNEL (1)
Ø Box kernel: The simplest, separable lowpass filter kernel is the box kernel, whose
coefficients have the same value (typically 1). 16
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – BOX KERNEL (2)
17
(a) Test pattern of size 1F2G × 1F2G pixels. (b)-(d) Results of lowpass filtering with box kernels of sizes 3 × 3, 11 × 11,
and 21 × 21, respectively.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (1)
MN OPN
L
" H, I = 4 H, I = JK NQN where J is a non-
zero constant.
SN
L N
4 R = JK NQ where R = H6 + I6
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (2)
19
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (3)
20
(a) Sampling a Gaussian function to obtain a discrete Gaussian kernel. The values
shown are for J = 1 and T = 1. (b) Resulting 3 × 3 kernel.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (4)
Ø The values of a Gaussian function at a distance larger than UV from the mean are small 21
Ø Typical limit for the Gaussian kernel is WT × WT (usually select the smallest odd
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (5)
22
Mean and standard deviation of the product and convolution of two 1-D Gaussian
functions, ! and %.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (6)
23
(a) A test pattern of size 1F2G × 1F2G. (b) Result of lowpass filtering the pattern with a Gaussian kernel of size
21 × 21, with standard deviations T = 3YZ. (c) Result of using a kernel of size G3 × G3, with T = X. This result
is comparable to the box kernel image (d). We used J = 1 in all cases.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (7)
24
(a) Result of filtering image (a) in the previous slide using a Gaussian kernels of size G3 × G3, with T = X. (b) Result
of using a kernel of [Z × [Z, with the same value of T. (c) Difference image.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS (8)
25
(a) Image of a white rectangle on a black background, and a horizontal intensity profile along the scan line shown dotted.
(b) Result of smoothing this image with a box kernel of size X1 × X1, and corresponding intensity profile. (c) Result of
smoothing the image using a Gaussian kernel of size 1Z1 × 1Z1, with J = 1 and H = 2Z. Note the smoothness of the
profile in (c) compared to (b). The image and rectangle are of sizes 1F2G × 1F2G and XW[ × 12[ pixels, respectively.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – PADDING METHODS
26
(a) Zero padding (b) Replicate padding (c) Mirror (Symmetry) padding
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS
27
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – GAUSSIAN KERNELS
28
(a) Test pattern of size GF\W × GF\W pixels. (b) Result of filtering the test pattern with the same
Gaussian kernel used in the previous slide. (c) Result of filtering the pattern using a Gaussian kernel
of size XGZ × XGZ elements, with J = 1 and T = 12G. Mirror padding was used throughout.
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – APPLICATIONS (1)
Using lowpass filtering and thresholding for region extraction
29
(a) A 2ZWW × 2XZ[ Hubble Telescope image of the Hickson Compact Group. (b) Result of lowpass
filtering with a Gaussian kernel of size 1Z1 × 1Z1 and T = 2Z. (c) Result of thresholding
(thereshold value of ] = FYG) the filtered image (intensities were scaled to the range ^F, 1_).
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
SMOOTHING SPATIAL FILTER – APPLICATIONS (2)
Shading correction using lowpass filtering
30
(a) Shaded image (2FG[ × 2FG[ checkerboard whose inner squares are of size 12[ × 12[). (b) Estimate
of the shading patterns obtained using lowpass filtering using a Z12 × Z12 Gaussian kernel (four times the
size of the squares), J = 1, and T = 12[ (equal to the size of the squares). (c) Result of dividing (a) by (b).
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 28, 2023
F435 1
DIGITAL IMAGE
PROCESSING
SEM I – 2023-24
LECTURE 07
September 1, 2023 Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus
WORD OF CAUTION
➢ The course textbook and reference books are the primary study materials. These slides 2
➢ Hence, in case of any ambiguity regarding the completeness and correctness of these
➢ These slides are provided for your reference. Do not share or reproduce the content
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
ORDER STATISTICS FILTERING (1)
➢ Order Statistics (nonlinear) filtering involves ordering (ranking) the pixels contained in
3
➢ Smoothing is achieved by replacing the value of the center pixel with the value
➢ Median filter: replaces the value of the center pixel by the median of the intensity values
in the neighborhood of that pixel (the value of the center pixel is included in computing
the median).
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
ORDER STATISTICS FILTERING (2)
➢ Suppose that a 3 × 3 neighborhood has values (10, 20, 20, 20, 15, 20, 20, 25, 100). These
values are sorted as (10, 15, 20, 20, 20, 20, 20, 25, 100), which results in a median of 20. 4
Thus, the principal function of median filters is to force points to be more like their
neighbors.
➢ Median filters are particularly effective in the presence of impulse noise (also called as
➢ Noise reduction is achieved with considerably less blurring than linear smoothing filters
of similar size.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
ORDER STATISTICS FILTERING (3)
(a) X-ray image of a circuit board, corrupted by salt-and pepper noise. (b) Noise reduction using a
19 × 19 Gaussian lowpass filter kernel with 𝜎 = 3. (c) Noise reduction using a 7 × 7 median filter.
R. C. Gonzalez & R. E. Woods, Digital Image Processing, Pearson Education, 3rd ed., 2009
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (1)
➢ Sharpening highlights transitions in intensities.
➢ Image blurring could be accomplished in the spatial domain by pixel averaging (smoothing) 6
in a neighborhood.
➢ Because averaging is analogous to integration, it is logical to conclude that sharpening can be
accomplished by spatial differentiation.
➢ Use derivatives for sharpening.
➢ Image differentiation enhances edges and other discontinuities (such as noise) and de-
emphasizes areas with slowly varying intensities.
➢ High frequencies (which are responsible for fine details) are passed, while low frequencies
are attenuated or rejected.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (2)
𝜕𝑓
= 𝑓 𝑥 + 1 − 𝑓(𝑥)
𝜕𝑥
𝜕2 𝑓
= 𝑓 𝑥 + 1 + 𝑓(𝑥 − 1) − 2𝑓(𝑥)
𝜕𝑥 2
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (3)
A first order derivative:
1. Must be zero in areas of constant intensity.
8
2. Must be nonzero at the onset of an intensity
step or ramp.
3. Must be nonzero along intensity ramps.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (4)
➢ Edges in digital images often are ramp-like transitions in intensity, in which case the first
9
derivative of the image would result in thick edges because the derivative is nonzero
along a ramp.
➢ On the other hand, the second derivative would produce a double edge one pixel thick,
separated by zeros.
➢ From this, we conclude that the second derivative enhances fine detail much better than
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (5)
➢ Isotropic kernel for second order derivative - Laplacian:
𝜕 2𝑓 𝜕 2𝑓 10
∇2 𝑓(𝑥, 𝑦) = 2 + 2 = 𝑓 𝑥 + 1, 𝑦 + 𝑓 𝑥 − 1, 𝑦 + 𝑓 𝑥, 𝑦 + 1 + 𝑓 𝑥, 𝑦 − 1 − 4𝑓(𝑥, 𝑦)
𝜕𝑥 𝜕𝑦
(a) Laplacian kernel used to implement the above equation using convolution. (b) Kernel used to implement
an extension of this equation that includes the diagonal terms. (c) and (d) Two other Laplacian kernels.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (6)
➢ Laplacian being a derivative operator, highlights sharp intensity transitions in an image and
➢ This will tend to produce images that have grayish edge lines and other discontinuities, all
➢ Background features can be “recovered” while still preserving the sharpening effect of the
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑐∇2 𝑓(𝑥, 𝑦)
where 𝑓(𝑥, 𝑦) and 𝑔(𝑥, 𝑦) are the input and sharpened images, respectively.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (7)
𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑐∇2 𝑓(𝑥, 𝑦)
12
where 𝑓(𝑥, 𝑦) and 𝑔(𝑥, 𝑦) are the input and sharpened images, respectively.
𝑐 = −1 𝑐=1
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (8)
13
(a) Blurred image of the North Pole of the
moon. (b) Laplacian image obtained using
the kernel-a in the previous slide (all the
negative values are clipped at 0). (c) Image
sharpened the equation in the previous
slide with 𝑐 = −1. (d) Image sharpened
using the same procedure, but with the
kernel-b in the previous slide.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
SHARPENING (HIGHPASS) SPATIAL FILTERING (9)
14
The Laplacian image from image-(b) in the
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
UNSHARP MASKING AND HIGHBOOST FILTERING (1)
➢ Unsharp masking, consists of the following steps:
ҧ 𝑦)
𝑓(𝑥, 𝑦) → 𝑓(𝑥,
➢ Subtract the blurred image from the original (the resulting difference is called the mask.)
ҧ 𝑦)
𝑔𝑚𝑎𝑠𝑘 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 − 𝑓(𝑥,
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
UNSHARP MASKING AND HIGHBOOST FILTERING (2)
16
unsharp masking.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
UNSHARP MASKING AND HIGHBOOST FILTERING (3)
17
(a) Original image of size 600 × 259 pixels. (b) Image blurred using a 31 × 31 Gaussian lowpass
filter with 𝜎 = 5. (c) Mask. (d) Result of unsharp masking with 𝑘 = 1. (e) Result of highboost
filtering with 𝑘 = 4.5.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
FIRST-ORDER DERIVATIVES FOR IMAGE SHARPENING -
THE GRADIENT (1)
➢ First derivatives in image processing are implemented using the magnitude of the gradient. 18
➢ The gradient of an image 𝑓 at coordinates (𝑥, 𝑦) is defined as the two dimensional column
vector,
➢ This vector has the important geometrical property that it points in the direction of the
greatest rate of change of 𝑓 at location (𝑥, 𝑦).
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
FIRST-ORDER DERIVATIVES FOR IMAGE SHARPENING -
THE GRADIENT (2)
➢ The magnitude (length) of vector ∇𝑓, denoted as 𝑀(𝑥, 𝑦) (the vector norm notation 𝑓 is
19
also used frequently), where
is the value at (𝑥, 𝑦) of the rate of change in the direction of the gradient vector.
➢ It is common practice to refer to this image as the gradient image (or simply as the gradient).
➢ Because the components of the gradient vector are derivatives, they are linear operators.
➢ However, the magnitude of this vector is not, because of the squaring and square root
operations.
➢ On the other hand, the partial derivatives are not rotation invariant, but the magnitude of the
gradient vector is.
Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
1) Negative of Image
2) Threshold
3) Slicing