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

F435 1

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

would only serve as a supplementary aid for your preparations.

➢ Hence, in case of any ambiguity regarding the completeness and correctness of these

slides, textbook has to be taken in to confidence.

➢ These slides are provided for your reference. Do not share or reproduce the content

without obtaining permission from the course instructor.

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)

➢ Office hour: Mondays 5:00 – 6:00 pm (Please send email in advance).

➢ 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

Examination. An application in writing with relevant certificates attached (medical from

Campus Medical center) needs to be submitted to the IC of the course at least a day before

the scheduled exam.

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

sole discretion of the instructors.

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

the instructor or submitting blank or incomplete/incoherent answer books may present

grounds for awarding NC in the course.

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

is discovered, strictest action will be initiated against the student.

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.

Scene element Digital image

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus 14 August 2023
WHAT IS DIGITAL IMAGE PROCESSING? (2)

➢ Digital image processing:


11
➢ processes whose inputs and outputs are images and,

➢ includes processes that extract attributes from images, and

➢ the recognition of individual objects


➢ Computer vision - use computers to emulate human vision, including learning and
being able to make inferences and take actions based on visual inputs. Artificial
Intelligence?
➢ Image analysis (also image understanding) falls in between image processing and
computer vision.

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

➢ acquiring an image of the area containing the text,

➢ preprocessing that image,

➢ extracting (segmenting) the individual characters,

➢ describing the characters in a form suitable for computer processing, and

➢ recognizing those individual characters


➢ Making sense of the content falls in the domain of image analysis and even computer vision,
depending on the level of complexity implied by the statement “making sense of”.

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.

➢ electromagnetic energy spectrum (from gamma rays to radio waves)


14

➢ acoustic

➢ ultrasonic

➢ electronic (in the form of electron beams used in electron microscopy), and

➢ synthetic (computer generated) images, used for modeling and visualization

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

➢ 𝑓 𝑥, 𝑦 = 𝑖 𝑥, 𝑦 𝑟 𝑥, 𝑦

➢ 0 ≤ 𝑖(𝑥, 𝑦) < ∞ is the illumination component

➢ 0 ≤ 𝑟 𝑥, 𝑦 ≤ 1 is the reflection component

➢ If 𝑙 = 𝑓(𝑥, 𝑦), then typically 𝐿min ≤ 𝑙 ≤ 𝐿max

➢ The range [𝐿min , 𝐿max ] is called the intensity or gray scale. Usually [0, 1] or [0, 𝐶] with 0

representing black and 1 (or 𝐶) representing white.


Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
SAMPLING AND QUANTIZATION (1)

18

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
SAMPLING AND QUANTIZATION (2)

➢ (𝑥, 𝑦) are sampled into 𝑀 and 𝑁 co-


19

ordinates respectively

➢ 𝑓 is quantized into 𝐿 intensity levels

[0, 𝐿 − 1] , where 𝐿 = 2𝑘 and 𝑘

represents the number of bits per level.

➢ Number of bits required to store a

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

➢ Linear Indexing (column wise): 21

➢ 𝛼 = 𝑀𝑦 + 𝑥

➢ Coordinate indexing:

➢ 𝑥 = 𝛼 mod 𝑀

➢ 𝑦 = (𝛼 − 𝑥)/𝑀

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 14, 2023
SPATIAL AND INTENSITY RESOLUTION

➢ Spatial resolution is a measure of the smallest discernible detail in an image.


22

Usually expressed as pixels per unit distance. (sometimes dots per inch (dpi)).

➢ To be meaningful, measures of spatial resolution must be stated with respect to

spatial units.

➢ Intensity resolution similarly refers to the smallest discernible change in intensity

level.

➢ Number of bits used to quantize intensity is referred to as the intensity resolution.

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

would only serve as a supplementary aid for your preparations.

➢ Hence, in case of any ambiguity regarding the completeness and correctness of these

slides, textbook has to be taken in to confidence.

➢ These slides are provided for your reference. Do not share or reproduce the content

without obtaining permission from the course instructor.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS - NEIGHBORS

𝑓(𝑥 − 1, 𝑦 + 1) 𝑓(𝑥, 𝑦 + 1) 𝑓(𝑥 + 1, 𝑦 + 1)

𝑓(𝑥 − 1, 𝑦) 𝑓(𝑥, 𝑦) 𝑓(𝑥 + 1, 𝑦)

𝑓(𝑥 − 1, 𝑦 − 1) 𝑓(𝑥, 𝑦 − 1) 𝑓(𝑥 + 1, 𝑦 − 1)

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

➢ Three types of adjacency:

➢ 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)

(a) An arrangement of pixels, (b) Pixels that are 8-adjacent (adjacency is


shown by dashed lines), and (c) m-adjacency.

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

points (𝒙𝒊 , 𝒚𝒊 ) and (𝒙𝒊−𝟏 , 𝒚𝒊−𝟏 ) are adjacent for 1 ≤ 𝑖 ≤ 𝑛.

➢ In this case, 𝒏 is the length of the path.

➢ If (𝒙𝟎 , 𝒚𝟎 ) = (𝒙𝒏 , 𝒚𝒏 ) the path is a closed path.

➢ We can define 𝟒 −, 𝟖 −,or 𝒎 −paths, depending on the type of adjacency specified.

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)

➢ Suppose an image contains 𝐾 disjoint regions, 𝑅𝑘 , 𝑘 = 1, 2, … , 𝐾, none of which touches the


9
image border. Let 𝑹𝒖 denote the union of all the 𝐾 regions, and let 𝑹𝒖 𝒄 denote its
complement.
➢ We call all the points in 𝑹𝒖 the foreground, and all the points in 𝑹𝒖 𝒄 the background of the
image.
➢ The boundary (also called the border or contour) of a region 𝑅 is the set of pixels in 𝑅 that
are adjacent to pixels in the complement of 𝑅.
➢ Here again, we must specify the connectivity being used to define adjacency.

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

➢ 𝐷(𝑝, 𝑞) ≥ 0, (𝐷(𝑝, 𝑞) = 0 iff 𝑝 = 𝑞) ,

➢ 𝐷(𝑝, 𝑞) = 𝐷(𝑞, 𝑝), and

➢ 𝐷(𝑝, 𝑠) ≤ 𝐷(𝑝, 𝑞) + 𝐷(𝑞, 𝑠).


➢ The Euclidean distance between 𝑝 and 𝑞 is defined as
1
𝐷𝑒 𝑝, 𝑞 = 𝑥−𝑢 2 + 𝑦−𝑢 2 2

➢ 𝐷𝑒 represents the points contained in a disk of radius 𝑟 centered at (𝑥, 𝑦).

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:

(𝑥, 𝑦)

(𝑥, 𝑦)

➢ The pixels with 𝐷4 = 1 are the 4-neighbors of (𝑥, 𝑦).


Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
RELATIONSHIPS BETWEEN PIXELS – DISTANCE (3)
➢ The 𝑫𝟖 distance, (called the chessboard distance) between 𝑝 and 𝑞 is defined as
𝐷8 𝑝, 𝑞 = max( 𝑥 − 𝑢 , 𝑦 − 𝑣 )
14
➢ Pixels having a 𝐷8 distance from (𝑥, 𝑦) that is less than or equal to some value 𝑑
form a square centered at (𝑥, 𝑦).
➢ The pixels with 𝐷8 distance ≤ 2 from (𝑥, 𝑦) (the center point) form the following
contours of constant distance:

(𝑥, 𝑦)

➢ The pixels with 𝐷8 = 1 are the 8-neighbors of (𝑥, 𝑦).


Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
ARITHMETIC OPERATIONS BETWEEN TWO IMAGES

15

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 16, 2023
ARITHMETIC OPERATIONS BETWEEN TWO
IMAGES - ADDITION

16

(a) Image of Galaxy Pair


NGC 3314 corrupted by
additive Gaussian noise. (b)-
(f) Result of averaging 5, 10,
20, 50, and 100 noisy
images, respectively. All
images are of size 566 × 598
pixels, and all were scaled
so that their intensities
would span the full [0, 255]
intensity scale.
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 - 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

Shading correction. (a) Shaded test pattern. (b) Estimated shading


pattern. (c) Product of (a) by the reciprocal of (b)

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

➢ Geometric transformations of digital images consist of two basic operations:


20
➢ Spatial transformation of coordinates

➢ 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

would only serve as a supplementary aid for your preparations.

➢ Hence, in case of any ambiguity regarding the completeness and correctness of these

slides, textbook has to be taken in to confidence.

➢ These slides are provided for your reference. Do not share or reproduce the content

without obtaining permission from the course instructor.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 17, 2023
GEOMETRIC TRANSFORMATIONS

➢ Geometric transformations of digital images consist of two basic operations:


3
➢ Spatial transformation of coordinates

➢ 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)

➢ Affine transformations, which include scaling, translation, rotation, and shearing.


➢ The key characteristic of an affine transformation in 2-D is that it preserves points, 4

straight lines, and planes.


➢ The equation in the previous slide can be used to express the transformations just
mentioned, except translation, which would require that a constant 2-D vector be
added to the right side of the equation.

All four affine transformations can


be expressed using a single 3 × 3
matrix in the following general form:

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)

➢ Two basic ways of implementing the affine transformations.


➢ The first, is a forward mapping, which consists of scanning the pixels of the input image 8

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

(𝑥, 𝑦) = 𝐴−1 (𝑥′, 𝑦′).

➢ It then interpolates (using one of the techniques mentioned earlier) among the nearest

input pixels to determine the intensity of the output pixel value.

➢ Inverse mappings are more efficient to implement than forward mappings, and are used

in numerous commercial implementations of spatial transformations (for example,

MATLAB uses this approach).


Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
GEOMETRIC TRANSFORMATIONS - AFFINE TRANSFORMATIONS (7)

10

(a) A 541 × 421 image of the


letter T. (b) Image rotated −21°
using nearest-neighbor
interpolation for intensity
assignments. (c) Image rotated
− 21° using bilinear interpolation.
(d) Image rotated −21° using
bicubic interpolation. (e)-(h)
Zoomed sections (each square is
one pixel, and the numbers shown
are intensity values).

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.

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)

12
➢ Conversion from RGB to gray scale.

𝑧1 +𝑧2 +𝑧3
➢ Averaging:
3

0.34𝑧1 +0.55𝑧2 +0.11𝑧3


➢ Luminosity method: (since, our vision is more sensitive
3

to the green color)

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

A 3 × 3 neighborhood about a point Intensity transformation functions. (a) Contrast stretching


function. (b) Thresholding function.
(𝑥0 , 𝑦0 ) in an image. The neighborhood
is moved from pixel to pixel in the
image to generate an output image.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – IMAGE NEGATIVE (1)

Negative transformation function:


15

Some basic intensity transformation


functions. Each curve was scaled
independently so that all curves would
fit in the same graph.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – IMAGE NEGATIVE (2)

16

(a) A digital mammogram. (b) Negative image

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – LOG TRANSFORM

Log transformation function:


17

(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

Plots of the gamma transform


function for various values of 𝛾
and 𝑐 = 1. gamma correction transform:

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – CONTRAST
STRETCHING (1)

➢ Low-contrast images can result from poor illumination, lack 20

of dynamic range in the imaging sensor, or even the wrong


setting of a lens aperture during image acquisition.
➢ Contrast stretching expands the range of intensity levels in
an image so that it spans the ideal full intensity range of the
recording medium or display device.
Contrast stretching. Piecewise
linear transformation function.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 18, 2023
INTENSITY TRANSFORMATIONS – CONTRAST
STRETCHING (2)

21

Contrast stretching. (a) Piecewise


linear transformation function. (b) A
low contrast electron microscope
image of pollen, magnified 700
times. (c) Result of contrast
stretching. (d) Result of
thresholding.

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.

(a) This transformation function


highlights range [𝐴, 𝐵] and
reduces all other intensities to a
lower level. (b) This function
highlights range [𝐴, 𝐵] and leaves
other intensities unchanged.

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)

➢ 2-D linear transform


𝑀−1 𝑁−1
29
𝑇 𝑢, 𝑣 = ෍ ෍ 𝑓 𝑥, 𝑦 𝑟(𝑥, 𝑦, 𝑢, 𝑣)
𝑥=0 𝑦=0

where 𝑟(𝑥, 𝑦, 𝑢, 𝑣) is called a forward transformation kernel, variables 𝑢 and 𝑣 are


called the transform variables and 𝑇(𝑢, 𝑣) is called the forward transform of 𝑓(𝑥, 𝑦)
➢ Given 𝑇(𝑢, 𝑣), we can recover 𝑓(𝑥, 𝑦) using the inverse transform of 𝑇(𝑢, 𝑣):

𝑀−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)

➢ The forward transform kernel is separable if 𝒓 𝒙, 𝒚, 𝒖, 𝒗 = 𝒓𝟏 𝒙, 𝒖 𝒓𝟐 (𝒚, 𝒗) and


30
symmetric if 𝒓 𝒙, 𝒚, 𝒖, 𝒗 = 𝒓𝟏 𝒙, 𝒖 𝒓𝟏 (𝒚, 𝒗)
➢ The Fourier transform:
𝑢𝑥 𝑣𝑦
−𝑗2𝜋( + )
𝑟 𝑥, 𝑦, 𝑢, 𝑣 = 𝑒 𝑀 𝑁
1 𝑢𝑥 𝑣𝑦
𝑗2𝜋( 𝑀 + 𝑀 )
𝑠 𝑥, 𝑦, 𝑢, 𝑣 = 𝑒
𝑀𝑁
𝑀−1 𝑁−1
𝑢𝑥 𝑣𝑦
−𝑗2𝜋( 𝑀 + 𝑁 )
𝑇 𝑢, 𝑣 = ෍ ෍ 𝑓 𝑥, 𝑦 𝑒
𝑥=0 𝑦=0
𝑀−1 𝑁−1
1 𝑗2𝜋(𝑢𝑥+𝑣𝑦)
𝑓 𝑥, 𝑦 = ෍ ෍ 𝑇 𝑢, 𝑣 𝑒 𝑀 𝑀
𝑀𝑁
𝑢=0 𝑣=0

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.

Image 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
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

would only serve as a supplementary aid for your preparations.

➢ Hence, in case of any ambiguity regarding the completeness and correctness of these

slides, textbook has to be taken in to confidence.

➢ These slides are provided for your reference. Do not share or reproduce the content

without obtaining permission from the course instructor.

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

➢ Intensity or gray level (X axis) vs Frequency (Y axis)


➢ Unnormalized histogram of an image 𝑓(𝑥, 𝑦) is
ℎ 𝑟𝑘 = 𝑛𝑘 , for 𝑘 = 0, 1, 2, 3, … , 𝐿 − 1
where 𝑟𝑘 are the intensities of an 𝐿 intensity level digital image 𝑓(𝑥, 𝑦).
➢ Normalized histogram is given by

ℎ 𝑟𝑘 𝑛𝑘
𝑝 𝑟𝑘 = =
𝑀𝑁 𝑀𝑁
➢ 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

➢ Histogram manipulation can improve the visual appeal of the image.


6
➢ Histogram Sliding : increase or decrease brightness,
𝑔(𝑥, 𝑦) = 𝑓(𝑥, 𝑦) ± 𝛿
➢ Histogram Stretching is scaling the original histogram to increase the contrast.

➢ If 𝑓𝑚𝑖𝑛 ≤ 𝑓(𝑥, 𝑦) ≤ 𝑓𝑚𝑎𝑥 then, linear stretching can be written as,

𝑓 𝑥, 𝑦 − 𝑓𝑚𝑖𝑛
𝑔 𝑥, 𝑦 = 𝑓𝑛𝑒𝑤_𝑚𝑎𝑥 − 𝑓𝑛𝑒𝑤_𝑚𝑖𝑛 + 𝑓𝑛𝑒𝑤_𝑚𝑖𝑛
𝑓𝑚𝑎𝑥 − 𝑓𝑚𝑖𝑛

➢ The new contrast is 𝑓𝑛𝑒𝑤_𝑚𝑎𝑥 − 𝑓𝑛𝑒𝑤_𝑚𝑖𝑛

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION

➢ Stretching fails, if maximum and minimum intensities already exists


7
➢ Let 𝑟𝑘 be the normalized intensity values between [0, 1].
𝑠𝑘 = 𝑇(𝑟𝑘 ), 0 ≤ 𝑟𝑘 ≤ 1
be the transformation, where 𝑟𝑘 are original image’s intensity values and 𝑠𝑘 are the
new intensity values
➢ Properties needed for 𝑇(. )

➢ 𝑇(𝑟𝑘 ) is monotonically increasing

➢ 𝑇(𝑟𝑘 ) ∈ [0, 1] if 𝑟𝑘 ∈ [0, 1]

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

➢ Then, for a known 𝑝𝑟 (𝑟) and 𝑠 = 𝑇(𝑟) we can write,


𝑑𝑟
𝑝𝑠 𝑠 = 𝑝𝑟 𝑟
𝑑𝑠

➢ A transformation function of particular importance in image processing is


𝑟

𝑠 = 𝑇 𝑟 = (𝐿 − 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.

Histogram equalization (or histogram linearization) produces a transformation


function that seeks to generate an output image with a uniform histogram.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – STEPS

➢ In discrete values, the probability of getting a particular intensity 𝑟𝑘 is given by,


𝑛𝑘 12
𝑝𝑟 𝑟𝑘 = P 𝑟 = 𝑟𝑘 =
𝑀𝑁
where 𝑛𝑘 is the number of pixels with intensity 𝑟𝑘 .

➢ Cumulative distribution function (CDF) is given by


𝑘 𝑘
𝑛𝑖
P 𝑟 ≤ 𝑟𝑘 = ෍ = ෍ 𝑝𝑟 (𝑟𝑖 )
𝑀𝑁
𝑖=0 𝑖=0

➢ 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

Histogram equalization. (a) Original histogram. (b) Transformation function.


(c) Equalized histogram.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – EXAMPLE (3)

17

Equalized image

Simple gray image

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 23, 2023
HISTOGRAM EQUALIZATION – CONTRAST ENHANCEMENT

➢ Because a histogram is an approximation to a PDF, and no new allowed intensity


18
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 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

would only serve as a supplementary aid for your preparations.

➢ Hence, in case of any ambiguity regarding the completeness and correctness of these

slides, textbook has to be taken in to confidence.

➢ These slides are provided for your reference. Do not share or reproduce the content

without obtaining permission from the course instructor.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM EQUALIZATION

➢ In discrete values, the probability of getting a particular intensity 𝑟𝑘 is given by,


𝑛𝑘 3
𝑝𝑟 𝑟𝑘 = 𝑃 𝑟 = 𝑟𝑘 =
𝑀𝑁
where 𝑛𝑘 is the number of pixels with intensity 𝑟𝑘 .

➢ Cumulative distribution function (CDF) is given by


𝑘
𝑛𝑖
𝑃 𝑟 ≤ 𝑟𝑘 = ෍
𝑀𝑁
𝑖=0

➢ 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
𝑘

𝑠𝑘 = 𝑇 𝑟𝑘 = 𝐿 − 1 ෍ 𝑝𝑟 𝑟𝑖 , 0≤𝑘 ≤𝐿−1 −−−− −(1)


𝑖=0

➢ 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

(a) Histogram of a 3-bit image. (b) Specified histogram.

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

Transformation function obtained


from the specified histogram.

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

Result of histogram matching. Specified histogram.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – APPLICATION (1)

15

(a) An image, and (b) its histogram.

(a) Histogram equalization transformation obtained using the input


histogram. (b) Histogram equalized image. (c) Histogram of equalized image.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM MATCHING – APPLICATION (2)

16

Histogram of the matched output image.

(a) Specified histogram. (b) Transformation 𝐺(𝑧𝑞 ), labeled (1),


and 𝐺 −1 (𝑠𝑘 ), labeled (2). (c) Result of histogram specification.

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

where 𝑝𝑆𝑥𝑦 is the histogram of the pixels in region 𝑆𝑥𝑦 .

➢ The variance of the pixels in the neighborhood is similarly given by

𝐿−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

(a) Original image. (b) Result of global histogram equalization.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus August 25, 2023
HISTOGRAM STATISTICS – LOCAL ENHANCEMENT (2)

20

(a) Original image. (b) Result of local


enhancement based on local histogram statistics.

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

would only serve as a supplementary aid for your preparations.

Ø Hence, in case of any ambiguity regarding the completeness and correctness of these

slides, textbook has to be taken in to confidence.

Ø These slides are provided for your reference. Do not share or reproduce the content

without obtaining permission from the course instructor.

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)

The mechanics of linear spatial filtering


using a 3 × 3 kernel.

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)

Ø Separable filter kernels


Ø A 2-D function 4(#, $) is said to be separable if it can be written as the product of 11

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

requires on the order of ;<& multiplications and additions.


The result is of size ; × <
&×1 ;×<

requires on the order of ;<' multiplications and additions,


for a total of >?(@ + A) operations.
;×< '×1

Thus, the computational advantage of performing convolution


with a separable, as opposed to a nonseparable, kernel is

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

Ø By definition, a separable kernel is formed by such a product. Therefore, to determine if a


kernel is separable, all we have to do is determine if its rank is 1.
Ø Once you have determined that the rank of a kernel matrix is 1, the following three step
approach can be used to get two vectors 8 and 9 such that their outer product, " = 89 : .
Ø Find any nonzero element in the kernel and let B denote its value.
Ø Form vectors C and D equal, respectively, to the column and row in the kernel
containing the element found in Step 1.
Ø Let 8 = C and 9 : = DEB.

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)

Ø Gaussian kernel is circularly symmetric (also


18

called isotropic, meaning their response is

independent of orientation) and separable.

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

Distances from the center for


various sizes of square kernels.

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

enough that they can be ignored.

Ø With a Gaussian kernel of size WT × WT , we are assured of getting essentially the

same result as if we had used an arbitrarily large Gaussian kernel.

Ø Typical limit for the Gaussian kernel is WT × WT (usually select the smallest odd

integer that satisfies the condition e.g., a G3 × G3 kernel if T = X).

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

(a) Zero padding (b) Mirror padding (c) Replicate padding

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

would only serve as a supplementary aid for your preparations.

➢ Hence, in case of any ambiguity regarding the completeness and correctness of these

slides, textbook has to be taken in to confidence.

➢ These slides are provided for your reference. Do not share or reproduce the content

without obtaining permission from the course instructor.

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

the region encompassed by the filter.

➢ Smoothing is achieved by replacing the value of the center pixel with the value

determined by the ranking result.

➢ 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

salt and pepper noise).

➢ 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)

➢ First order derivative: 7

𝜕𝑓
= 𝑓 𝑥 + 1 − 𝑓(𝑥)
𝜕𝑥

➢ Second order derivative:

𝜕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.

A second order derivative:


1. Must be zero in areas of constant intensity.
2. Must be nonzero at the onset and end 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

the first derivative, a property ideally suited for sharpening images.

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

de-emphasizes regions of slowly varying intensities. 11

➢ This will tend to produce images that have grayish edge lines and other discontinuities, all

superimposed on a dark, featureless background.

➢ Background features can be “recovered” while still preserving the sharpening effect of the

Laplacian by adding the Laplacian image to the original.

𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑐∇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

previous slide , scaled to the full [0, 255] range of

intensity values. Black pixels correspond to the

most negative value in the Unscaled Laplacian

image, grays are intermediate values, and white

pixels corresponds to the highest positive value.

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:

➢ Blur the original image. 15

ҧ 𝑦)
𝑓(𝑥, 𝑦) → 𝑓(𝑥,

➢ Subtract the blurred image from the original (the resulting difference is called the mask.)
ҧ 𝑦)
𝑔𝑚𝑎𝑠𝑘 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 − 𝑓(𝑥,

➢ Add the mask to the original.


𝑔 𝑥, 𝑦 = 𝑓 𝑥, 𝑦 + 𝑘𝑔𝑚𝑎𝑠𝑘 (𝑥, 𝑦)

When 𝑘 = 1 we have unsharp masking.


When 𝑘 > 1, the process is referred to as highboost filtering.

Ravi Kadlimatti, "Digital Image Processing," BITS, Pilani – K. K. Birla Goa Campus September 1, 2023
UNSHARP MASKING AND HIGHBOOST FILTERING (2)

16

1 -D illustration of the mechanics of

unsharp masking.

(a) Original signal. (b) Blurred signal with

original shown dashed for reference. (c)

Unsharp mask. (d) Sharpened signal,

obtained by adding (c) to (a).

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

% Read the input image


inputImage = imread('RGB01.jpg'); % Replace 'your_image.jpg' with your image
file path
% Check if the image is grayscale (single channel) or color (three channels)
if size(inputImage, 3) == 3
% If it's a color image, convert it to grayscale
inputImage = rgb2gray(inputImage);
end
% Calculate the negative of the image
negativeImage = 255 - inputImage;
% Display the original and negative images
subplot(1, 2, 1); imshow(inputImage); title('Original Image');
subplot(1, 2, 2); imshow(negativeImage); title('Negative Image');

2) Threshold

% Read the input image


inputImage = imread('RGB01.jpg'); % Replace 'your_image.jpg' with your image
file path
% Check if the image is grayscale (single channel) or color (three channels)
if size(inputImage, 3) == 3
% If it's a color image, convert it to grayscale
inputImage = rgb2gray(inputImage);
end
% Set the threshold value
threshold = 200;
% Apply the threshold to create a binary image
binaryImage = inputImage >= threshold;
% Display the original and binary images
subplot(1, 2, 1); imshow(inputImage); title('Original Image');
subplot(1, 2, 2); imshow(binaryImage); title('Binary Image');

3) Slicing

% Read the input image


inputImage = imread('RGB01.jpg'); % Replace 'your_image.jpg' with your
image file path
% Check if the image is grayscale (single channel) or color (three
channels)
if size(inputImage, 3) == 3
% If it's a color image, convert it to grayscale
inputImage = rgb2gray(inputImage);
end
% Set the intensity range for highlighting
lowerThreshold = 100;
upperThreshold = 150;
% Create a copy of the input image and initialize it to intensity
level 20
outputImage = 20 * ones(size(inputImage));
% Highlight pixels in the specified intensity range
highlightPixels = (inputImage >= lowerThreshold) & (inputImage <=
upperThreshold);
outputImage(highlightPixels) = inputImage(highlightPixels);
% Display the original and processed images
subplot(1, 2, 1); imshow(inputImage); title('Original Image');
subplot(1, 2, 2); imshow(uint8(outputImage)); title('Processed
Image');

You might also like