0% found this document useful (0 votes)
14 views174 pages

DIP OJ Part A

The document provides an introduction to digital image processing, defining images and digital images, and explaining the scope and applications of digital image processing in various fields such as medical imaging and astronomy. It discusses fundamental concepts like image acquisition, representation, and processing techniques, including grayscale and color images, as well as the importance of spatial and intensity resolution. Additionally, it covers the basic relationships between pixels, including neighborhood and adjacency concepts.

Uploaded by

Ruhina Tabasshum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
14 views174 pages

DIP OJ Part A

The document provides an introduction to digital image processing, defining images and digital images, and explaining the scope and applications of digital image processing in various fields such as medical imaging and astronomy. It discusses fundamental concepts like image acquisition, representation, and processing techniques, including grayscale and color images, as well as the importance of spatial and intensity resolution. Additionally, it covers the basic relationships between pixels, including neighborhood and adjacency concepts.

Uploaded by

Ruhina Tabasshum
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 174

Introduction to

Digital Image Processing


Oishi Jyoti
Lecturer
Dept. of ECE, RUET
What is an image?

An image is a visual
representation of an
object or something.
It is the most
important sense of
human perception.
What is an image?
(0,0) (0,1000)
Mathematically, an image may be
defined as a two-dimensional
function, f(x,y), where x and y are
special co-ordinates and the amplitude
of f at any coordinate point (x,y) is
called the intensity or gray label at
(6000,0) (6000,1000)
that point.
What is a digital image image?

When, x,y, and the intensity (0,0) (0,1) (0,2) (0,3) (0,4)

values of f all are finite,


discrete quantities we call the
image a digital image.
Digital image processing

Digital image processing (DIP) refers to the


processing of digital images by means of the
computer. Here the input and output both are
digital images.
Scope of Digital image processing

❑ Humans are limited to the visual band of the


electromagnetic (EM) spectrum.
❑ Imaging machines cover almost entire EM
spectrum.
The origins of digital image processing.

Fig: Digital picture produced in 1921 from a coded tape by a telegraph printer
The origins of digital image processing (Cont.)

Fig: Digital picture


produced in 1922 from a
tape punched after the
signals had crossed the
Atlantic twice.
The origins of digital image processing (Cont.)

Fig: Unretouched cable


picture transmitted in 1929
from London to New York
by 15-tone equipment.
The origins of digital image processing (Cont.)

Fig: The first picture of the


moon by a U.S spacecraft
in 1964 (Computerized)
Applications of DIP

Fig: Electromagnetic spectrum


Applications of DIP
Gamma-ray Imaging
➢ Nuclear medicine: Inject patient radioactive isotope that
emits gamma rays as it decays. Images are produced from
the emissions collected by gamma-ray detectors. (Infection
and Tumor detection )
➢ Astronomical observations
Applications of DIP
Gamma-ray Imaging

Positron Emission
Tomography(PET)
Applications of DIP
X-ray Imaging

➢ Medical diagnosis: Uses a vacuum tube with anode


and cathode to generate x-ray. X-ray is passed
through the object(patient) and the other side
contains a film sensitive to x-ray.
➢ Angiography
Applications of DIP
X-ray Imaging
Applications of DIP
Fluorescence Microscopy Imaging

UV-ray Imaging

normal corn smut corn


Applications of DIP
Thermal Imaging

Infrared
Imaging

Grayscale representation Pseudo-color representation


(bright pixels correlate with (Human body dispersing
high-temperature regions) heat denoted by red)
Applications of DIP

Low Signal-to-Noise (SNR) Behavior

250

200

150

100

50

0 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1


noise
Thermal Imaging
signal
Applications of DIP
Infrared Satellite Image
Applications of DIP
Radar Imaging

Microwaves
Imaging

Mountains in Southeast Tibet

20
Applications of DIP
Synthetic Aperture Radar (SAR)
❑ Environmental monitoring,
earth-resource mapping,
and military systems
❑ SAR imagery must be
acquired in inclement
weather and all-day-all-
night.
❑ SAR produces relatively
fine azimuth resolution that
differentiates it from other
radars.
Applications of DIP

Magnetic Resonance Imaging (MRI)

knee spine head


Fundamental steps of DIP
Color Image Multiresolution Morphological
Compression
Processing Processing Processing

Image restoration Segmentation

Image filtering
Knowledge base Representation
and Enhancement

Image Object
Acquisition recognition
Visual perception of human
Visual perception of human

❑ The amount of light entering the eye


is controlled by the pupil, which
dilates and contracts accordingly.
❑ The cornea and lens, whose shape is
adjusted by the ciliary body, focus the
light on the retina.
Visual perception of human
❑ Retina receptors convert it into
nerve signals that pass to the brain.
Visual perception of human
Elements of visual perception
Cones
❑ 6 – 7 million in each eye
❑ Photopic or bright-light vision
❑ Highly sensitive to color
Rods
❑ 75 – 150 million
❑ Not involved in color vision
❑ Sensitive to low level of illumination (scotopic or dim-
light vision)
An object appears brightly colored in daylight will be seen colorless in
moonlight (why)?
Answer: Because only the rods are stimulated. This phenomenon is known as
scotopic or dim-light vision
Visual perception of human

Focal length: 14-17mm Length of tree image2.55mm


For distant objects (>3m), lens exhibits the least refractive power (flattened)
For nearby objects (<1m), lens is most strongly refractive (curved)
Q: What if the image is focused in one eye but not the other (i.e., lazy eye)?
http://en.wikipedia.org/wiki/Amblyopia
Lightness Perception: Objective Quantities
• Luminance is the amount of visible light that comes to the eye
from a surface.
• Illuminance is the amount of light incident on a surface.
• Reflectance (also called albedo) is the proportion of incident
light that is reflected from a surface.
• varies from 0% to 100% where 0% is ideal black and 100% is ideal white.
In practice, typical black paint is about 5% and typical white paint about
85%.

http://www-bcs.mit.edu/people/adelson
Lightness Perception: Objective Quantities

➢l(x,y) - illumination range

log (cd/m2)
Lightness Perception: Objective Quantities
➢r(x,y) – typical reflectance indixes
black velvet (0.01) silver plate (0.90)

stainless steel (0.65) snow (0.93) log (cd/m2)

white paint (0.80)


A simple Image formation model

f(x,y)=i(x,y)r(x,y)

0<f(x,y)<∞ luminance – proportional to energy


radiated by a physical source

0<i(x,y)<∞ Illumination/shading

0<r(x,y)<1 reflectance (“intrinsic images”)


A simple Image formation model

f(x,y) r(x,y) i(x,y)

Q: How to separate r(x,y) and i(x,y) from f(x,y)?


Introduction to Grayscale and Color Images

Image acquisition Image representation


➢ Light and Electromagnetic spectrum ➢ Spatial resolution
➢ Charge-Coupled Device (CCD) imaging
➢ Bit-depth resolution
and Bayer Pattern (the most popular
color-filter-array) ➢ Local neighborhood

➢ Sampling and Quantization ➢ Block decomposition


Image acquisition
EM spectrum for normal camera imaging

• The color of an object is determined by the nature of the light reflected by


the object
• Monochromatic light
• Three elements measuring chromatic light
Radiance, luminance and brightness
Image acquisition
Image acquisition process with CCD
Image acquisition
Image acquisition process with CCD
Color image acquisition

Observer (Camera)

RGB Camera Output

Light i(𝜆) Reflected Light = 𝑖(𝜆) ⋅ 𝑟(𝜆)

Object Reflectance 𝑟(𝜆)


Image acquisition
Filtering chromatic light for color imaging
Image acquisition
Filtering chromatic light for color imaging

𝑅(𝑥, 𝑦) = න𝑖(𝜆) ⋅ 𝑟(𝑥, 𝑦, 𝜆) ⋅ 𝐹𝑅 𝜆 𝑑𝜆

𝐺(𝑥, 𝑦) = න𝑖(𝜆) ⋅ 𝑟(𝑥, 𝑦, 𝜆) ⋅ 𝐹𝐺 𝜆 𝑑𝜆

𝐵(𝑥, 𝑦) = න𝑖(𝜆) ⋅ 𝑟(𝑥, 𝑦, 𝜆) ⋅ 𝐹𝐵 𝜆 𝑑𝜆

Color filters
Of the sensor
Image acquisition
Sampling and quantization
Image acquisition
Image after sampling and quantization
Image acquisition
Sampling and quantization
How many samples to take?
• Number of pixels (samples) in the image
• Nyquist rate

How many gray-levels to store?


• At a pixel position (sample), number of
levels of color/intensity to be represented
Image acquisition

Sampling
The Nyquist Rate

• Samples must be taken at a rate that is twice the frequency

of the highest frequency component to be reconstructed.

• Under-sampling: sampling at a rate that is too coarse, i.e., is

below the Nyquist rate.

• Aliasing: artefacts that result from under-sampling.


Image Representation

Gray scale Image representation with matrix

𝑓(0,0) 𝑓(0,1) ... 𝑓(0, 𝑁 − 1)


𝑓(1,0) 𝑓(1,1) ... 𝑓(1, 𝑁 − 1)
𝑓(𝑥, 𝑦) =
... ... ... ...
𝑓(𝑀 − 1,0) 𝑓(𝑀 − 1,1) . . . 𝑓(𝑀 − 1, 𝑁 − 1)
Image Representation

 Gray level bit representation, also known as grayscale bit-depth or pixel depth, refers to
the number of bits used to represent each pixel in a grayscale image.
 In digital imaging, pixels are the smallest units of an image, and they can represent
different shades of gray in a grayscale image.
 The gray level bit representation determines the number of different gray levels that can
be represented in an image.
 A higher bit depth allows for a greater number of distinct gray levels, which in turn results
in more detailed and smoother grayscale images.
 Each additional bit of depth doubles the number of possible gray levels.
Image Representation

 Here are some common gray level bit depths and the number of gray levels
they can represent:

• 1-bit depth: 2 gray levels (usually black and white)


• 2-bit depth: 4 gray levels
• 4-bit depth: 16 gray levels
• 8-bit depth: 256 gray levels
• 16-bit depth: 65,536 gray levels
Image Representation
Gray levels

Suppose, we have k bits to represent the intensity value f(x,y)


We can create 2k gray levels using k bits.

If k=8 bits then the number of gray levels will be


L = 2k = 256

We assume that discrete levels are equally spaced and


they are integers in the interval [0, L-1]
Image Representation

How many bits are required to represent a


100*100 size gray scale image?

Total bits = 100 x 100 x 8 = 80,000 bits

So, you would need 80,000 bits to represent a 100x100


grayscale image with 8 bits per pixel.
Image Representation
Color images
The RGB Color Model

𝑟(𝑥, 𝑦)
𝑓(𝑥, 𝑦) = 𝑔(𝑥, 𝑦)
𝑏(𝑥, 𝑦)
Image Representation
Color images
The RGB Color Model
• R, G, B at 3 axis ranging in [0 1] each
• Gray scale along the diagonal
• If each component is quantized into 256
levels [0:255], the total number of
different colors that can be produced is
(28)3 = 224 =16,777,216 colors.
Image Representation
Color images

=
Red Green Blue
Image Representation
Spatial Resolution
Spatial resolution is a measure of the smallest detectable detail in an image.
❑Line pairs per unit
❑Dots (pixels → The smallest unit of an image) per unit.

In the U.S measure is usually expressed as dots per inch (dpi)


Commonly used dpi:
newspapers → 75 dpi Books → 2400 dpi
Magazines → 133 dpi
Image Representation
Spatial Resolution
Suppose you have a phone which captures images of 3000*3000 size.
The number of pixels in the image is = 9*10^6 = 9 Mega Pixels

Your friend has a low-budget phone with a camera of 20 megapixels.

Whose camera is better?


Image Representation
Intensity Resolution
Intensity resolution is a measure of the smallest detectable change in the
intensity level.
❑8 bits (most common)
❑16 bits (some application)
❑32 bits (rare)
Basic Relationships Between Pixels
➢ Neighborhood
➢ Adjacency
➢ Connectivity
➢ Paths
➢ Regions and boundaries
Basic Relationships Between Pixels
Neighborhood
Neighbors of a pixel p at coordinates (x,y)
➢ 4-neighbors of p, denoted by N4(p):
(x-1, y), (x+1, y), (x,y-1), and (x, y+1).
➢ 4 diagonal neighbors of p, denoted by ND(p):
(x-1, y-1), (x+1, y+1), (x+1,y-1), and (x-1, y+1).
➢ 8 neighbors of p, denoted N8(p)
N8(p) = N4(p) U ND(p)
Basic Relationships Between Pixels
Adjacency

Let V be the set of intensity values

➢4-adjacency: Two pixels p and q with values from V


are 4-adjacent if q is in the set N4(p).

➢8-adjacency: Two pixels p and q with values from V


are 8-adjacent if q is in the set N8(p).
Spatial neighborhood
Neighbors of a pixel p=(i,j)

N8(p)={(i-1,j),(i+1,j),(i,j-1),(i,j+1),
N4(p)={(i-1,j),(i+1,j),(i,j-1),(i,j+1)} (i-1,j-1),(i-1,j+1),(i+1,j-1),(i+1,j+1)}

Adjacency
4-adjacency: p,q are 4-adjacent if p is in the set N4(q)
8-adjacency: p,q are 8-adjacent if p is in the set N8(q)
Note that if p is in N4/8(q), then q must be also in N4/8(p)
Spatial neighborhood

m-adjacency: Two pixels p and q with values from V are m-


adjacent if

(i) q is in the set N4(p), or


(ii) q is in the set ND(p) and the set N4(p) ∩ N4(q) has no
pixels whose values are from V.
Spatial neighborhood
V = {1, 2}
01,1 11,2 11,3 0 1 1
02,1 22,2 02,3 m adjacent

03,1 03,2 13,3 0 2 0

0 0 1
Spatial neighborhood
V = {1, 2}
01,1 11,2 11,3 0 1 1
02,1 22,2 02,3 m adjacent

03,1 03,2 13,3 0 2 0


m adjacent

0 0 1
Spatial neighborhood
V = {1, 2}
01,1 11,2 11,3 0 1 1
02,1 22,2 02,3 m adjacent
?
03,1 03,2 13,3 0 2 0
m adjacent

0 0 1
Spatial neighborhood
V = {1, 2}
01,1 11,2 11,3 0 1 1
02,1 22,2 02,3 m adjacent Not m adjacent

03,1 03,2 13,3 0 2 0


m adjacent

0 0 1
Spatial neighborhood
Path
➢A (digital) path (or curve) from pixel p with coordinates (x0, y0) to pixel
q with coordinates (xn, yn) is a sequence of distinct pixels with coordinates
(x0, y0), (x1, y1), …, (xn, yn)
Where (xi, yi) and (xi-1, yi-1) are adjacent for 1 ≤ i ≤ n.
➢Here n is the length of the path.
➢If (x0, y0) = (xn, yn), the path is closed path.
➢We can define 4-, 8-, and m-paths based on the type of adjacency used.
Spatial neighborhood
V = {1, 2}
Path finding
01,1 11,2 11,3 0 1 1
02,1 22,2 02,3
03,1 03,2 13,3 0 2 0
Can you find the m, 4 and 8-
0 0 1
path from (1,3) to (3,3)??
Spatial neighborhood
V = {1, 2}
Path finding
01,1 11,2 11,3 0 1 1
02,1 22,2 02,3 8 adjacent

03,1 03,2 13,3 0 2 0


The 8-path from (1,3) to (3,3):
(i)(1,3), (1,2), (2,2), (3,3) 0 0 1
(ii)(1,3), (2,2), (3,3)
Spatial neighborhood
V = {1, 2}
Path finding
01,1 11,2 11,3 0 1 1
02,1 22,2 02,3
03,1 03,2 13,3 0 2 0
m adjacent

The m-path from (1,3) to (3,3):


(1,3), (1,2), (2,2), (3,3)
0 0 1
Spatial neighborhood

Connected in S
Let S represent a subset of pixels in an image.
Two pixels p with coordinates (x0, y0) and q with
coordinates (xn, yn) are said to be connected in S if
there exists a path between them.
Spatial neighborhood
Let S represent a subset of pixels in an image

❑ For every pixel p in S, the set of pixels in S that are


connected to p is called a connected component of S.

❑ If S has only one connected component, then S is called


Connected Set.

❑ We call R a region of the image if R is a connected set

❑ Two regions, Ri and Rj are said to be adjacent if their union


forms a connected set.
❑ Regions that are not to be adjacent are said to be disjoint.
Spatial neighborhood

Boundary (or border)

➢The boundary of the region R is the set of pixels in the


region that have one or more neighbors that are not in
R.
➢If R happens to be an entire image, then its boundary
is defined as the set of pixels in the first and last rows
and columns of the image.
Spatial neighborhood
In the following arrangement of pixels, are the two
regions (of 1s) adjacent? (if 8-adjacency is used)
Region 1
1 1 1
1 0 1
0 1 0
0 0 1 Region 2
1 1 1
1 1 1
Spatial neighborhood
In the following arrangement of pixels, are the two parts
(of 1s) adjacent? (if 4-adjacency is used)
Part 1
1 1 1
1 0 1
0 1 0
0 0 1 Part 2
1 1 1
1 1 1
Spatial neighborhood
In the following arrangement of pixels, are the two
regions are disjoint. (if 4-adjacency is used)
Region 1
1 1 1
1 0 1
0 1 0
0 0 1 Region 2
1 1 1
1 1 1
Distance measure
Given pixels p, q and z with coordinates (x, y), (s, t), (u, v)
respectively.

The distance function D has following properties:

a. D(p, q) ≥ 0 [D(p, q) = 0, if p = q]

b. D(p, q) = D(q, p)

c. D(p, z) ≤ D(p, q) + D(q, z)


Distance measure
The following are the different Distance measures:

a. Euclidean Distance : c. Chess Board Distance:


D8(p, q) = max(|x-s|, |y-t|)
De(p, q) = [(x-s)2 + (y-t)2]1/2

b. City Block Distance:


D4(p, q) = |x-s| + |y-t|
Introduction to Mathematical Operations in DIP

Array vs. Matrix Operation

 a11 a12   b11 b12 


A=  B=
Array product
 21 22 
a a 
operator b21 b22 
 a11b11 a12b12  Array product
A .* B =  
Matrix product
 21 21 22 22 
a b a b
operator
 a11b11 + a12b21 a11b12 + a12b22  Matrix product
A*B= 
+ a b a b +
 21 11 22 21 21 12 22 22 
a b a b
Introduction to Mathematical Operations in DIP

Arithmetic operations between images are array


operations. The four arithmetic operations are denoted
as

s(x,y) = f(x,y) + g(x,y)


d(x,y) = f(x,y) – g(x,y)
p(x,y) = f(x,y) × g(x,y)
v(x,y) = f(x,y) ÷ g(x,y)
Addition of Noisy Images for Noise
Reduction
Noiseless image: f(x,y)
Noise: n(x,y) (at every pair of coordinates (x,y), the noise is
uncorrelated and has zero average value)
Corrupted image: g(x,y)
g(x,y) = f(x,y) + n(x,y)
Reducing the noise by adding a set of noisy images, {gi(x,y)}
K
1
g ( x, y ) =  g i ( x, y )
K i =1
Addition of Noisy Images for Noise
Reduction

1 K
g ( x, y ) =  g i ( x, y ) 1 K
E  g ( x, y ) = E   gi ( x, y ) 

K i =1  K i =1 
1 K 
= E    f ( x, y ) + ni ( x, y ) 
 K i =1 
1 K

= f ( x, y ) + E 
K

i =1
ni ( x, y ) 

= f ( x, y )
Set and Logical Operations
Set and Logical Operations

Let A be the elements of a gray-scale image


• The elements of A are triplets of the form (x, y, z), where
x and y are spatial coordinates and z denotes the intensity
at the point (x, y).
A = {( x, y, z ) | z = f ( x, y)}

• The complement of A is denoted Ac


Ac = {( x, y, K − z ) | ( x, y, z )  A}
K = 2k − 1; k is the number of intensity bits used to represent z
Image interpolation

Interpolation — Process of using known data to estimate unknown values


e.g., zooming, shrinking, rotating, and geometric correction
Interpolation (sometimes called resampling) — an imaging method to
increase (or decrease) the number of pixels in a digital image.
Some digital cameras use interpolation to produce a larger image than the
sensor captured or to create digital zoom

http://www.dpreview.com/learn/?/key=interpolation
Image interpolation
Nearest Neighbor Interpolation
f1(x2,y2) = f(x1,y1)
f(round(x2), round(y2))
=f(x1,y1)

f1(x3,y3) =
f(round(x3), round(y3))
=f(x1,y1)
Image interpolation
Nearest Neighbor Interpolation
Top, bottom, left, right
10 20 10 10 20 20
10 20 10 20
30 40 30 40 30 30 40 40
30 40
Image interpolation
Nearest Neighbor Interpolation
Top, bottom, left, right
10 10 20 20 10 10 20 20
10 20 10 10 20 20
30 30 40 40 30 30 40 40
30 40 30 30 40 40
Image interpolation

Nearest Neighbor Interpolation


Image interpolation

Bilinear Interpolation

Bi-linear interpolation means applying a linear interpolation


in two directions. Thus, it uses 4 nearest neighbors, takes
their weighted average to produce the output
Image interpolation
Bicubic Interpolation
• The intensity value assigned to point (x,y) is obtained by the
following equation
3 3

3 f ( x, y ) =  a x y ij
i j

i =0 j =0
• The sixteen coefficients are determined by using the sixteen
nearest neighbors.
http://en.wikipedia.org/wiki/Bicubic_interpolation
Image interpolation
Image interpolation
Image enhancement

Image enhancement is the procedure of improving the


quality and information content of original data before
processing. Common practices include contrast
enhancement, spatial filtering etc.
Domain of image processing

❑ Spatial Domain (Direct operation on image)

❑ Frequency domain ( Operation after Fourier


transformation)
Spatial processing

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

❑ f(x,y) → Input Image

❑ g(x,y) → Output image

❑ T → Operation/ Transform method


Spatial processing

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

❑ f(x,y) → Input Image

❑ g(x,y) → Output image

❑ T → Operation/ Transform
method defined over the
neighbourhood of point(x,y)
Spatial processing

For smallest neighbourhood of size 1 * 1, g depends only on value of f at a


single point (x,y) and T becomes a intensity transformer function. Also
called gray level mapping.

Hence for simplicity of notation it is described by

s = T (r)

Here s and r denotes intensity of g and f at a point (x,y)


Spatial processing

❑ Intensity transformation

→(Operates on single pixel)

❑ Spatial Filtering

→ (Operates in neighbourhood)
Intensity Transformation

Intensity transformations are applied on images for contrast


manipulation or image thresholding. These are in the spatial
domain, i.e. they are performed directly on the pixels.

Simplest off all image processing techniques.


Intensity Transformation

Thresholding:

s = 255 if r > Threshold


s = 0 if r <= Threshold
Intensity Transformation
Thresholding
Intensity Transformation
Thresholding T = 120 T = 135 T = 155

T = 187 T = 205 T = 220


Intensity Transformation
Thresholding
Intensity Transformation
Thresholding

T = 0.92
Intensity Transformation
Some basic subjective quality measurement terminologies:
1. Brightness
2. Contrast
3. Sharpness
Intensity Transformation
Brightness: In terms of digital image processing,
brightness is more properly described as the measured
intensity of all the pixels comprising an ensemble that
constitutes the digital image.
Traditional brightness simply brightens the entire image
from the shadows to the highlights equally.
Intensity Transformation

Brightness img+20
Intensity Transformation

Contrast: Contrast makes an object distinguishable. It is


the separation between the darkest and brightest areas of
the image. Increase contrast and you increase the
separation between dark and bright, making shadows
darker and highlights brighter.
Intensity Transformation

Contrast

Low contrast High contrast


Intensity Transformation

Sharpness: Sharpness can be defined as edge contrast, that


is, the contrast along edges in a photo. When we increase
sharpness, we increase the contrast only along/near edges
in the photo while leaving smooth areas of the image
alone.
Intensity Transformation

Sharpness
Some basic Intensity transformation Functions

There are three types of transformation:


1.Linear
2.Logarithmic
3.Power - law
Some basic Intensity transformation Functions
Linear
Identity transformation:
Each value of the image s = T(r)
is directly mapped to
=r
each other values of the
s
output image.
r
Some basic Intensity transformation Functions
Linear
Negative transformation: s = T(r)
It is the opposite of = 255-r
identity transformation.
Here, each value of the
input image is subtracted
from L-1 and then it is
mapped onto the output
image.
Some basic Intensity transformation Functions
Linear
Negative transformation
Some basic Intensity transformation Functions
Logarithmic

Logarithmic transformation is
divided into two types:
❑ Log transformation
❑ Inverse log transformation
Some basic Intensity transformation Functions
Logarithmic
❑ Log transformation

s = T(r)
= c*log(1+r)
Some basic Intensity transformation Functions
Logarithmic
❑ Log transformation
Some basic Intensity transformation Functions
Logarithmic

❑ Inverse log transformation


Some basic Intensity transformation Functions
Logarithmic
❑ Inverse Log transformation
Some basic Intensity transformation Functions
Power law (Gamma transformation)

s = T(r)
= c*rγ
Some basic Intensity transformation Functions

Power law (Gamma transformation)


γ=1 γ = 1.5 γ=2
Some basic Intensity transformation Functions

Contrast stretching
Contrast stretching (also called Normalization) attempts to
improve an image by stretching the range of intensity values it
contains to make full use of possible values.
Some basic Intensity transformation Functions

Contrast stretching
Some basic Intensity transformation Functions

Contrast stretching
In Min-Max Stretching, the lower and upper values of the input
image are made to span the full dynamic range.
Some basic Intensity transformation Functions
Contrast stretching
Some basic Intensity transformation Functions
Contrast stretching
Min-Max Stretching
Some basic Intensity transformation Functions

Contrast stretching
One problem with this method is that outliers can reduce the
effectiveness of the operation.

Suppose we have assigned some noise:


im[0][0] = 0.0
im[0][1]= 1.0
Some basic Intensity transformation Functions

Contrast stretching

No effect after
stretching
Some basic Intensity transformation Functions

Contrast stretching
❑ Sometimes, when Min-Max is performed, the tail ends of the histogram

becomes long resulting in no improvement in the image quality.

❑ So, it is better to clip a certain percentage like 1%, 2% of the data from the

tail ends of the input image histogram.

❑ This is known as Percentile Stretching. The formulae is same as Min-Max

but now the Xmax and Xmin are the clipped values
Some basic Intensity transformation Functions

Bit plane slicing One can use only MSB to represent the
Bit plane slicing is a method of pixel, which reduces the original gray level
representing an image with one or to a binary image. The three main goals of
more bits of the byte used for each bit plane slicing is:
pixel. ❑ Converting a gray level image to a
binary image.
❑ Representing an image with fewer bits
❑ Enhancing the image by focussing.
Some basic Intensity transformation Functions

Bit plane slicing


Some basic Intensity transformation Functions

Bit plane slicing


Histogram equalization

Histogram
Histogram is a graphical representation of the intensity distribution
of an image. In simple terms, it represents the number of pixels for
each intensity value considered.
Histogram equalization

Histogram Equalization: It is a computer image processing technique


used to improve contrast in images. It accomplishes this by effectively
spreading out the most frequent intensity values, i.e. stretching out
the intensity range of the image. This method usually increases the
global contrast of images when its usable data is represented by close
contrast values. This allows for areas of lower local contrast to gain a
higher contrast.
Histogram equalization

The Histogram Equalization algorithm enhances the contrast of


images by transforming the values in an intensity image so that the
histogram of the output image is approximately flat.
Histogram equalization
Count the frequency
Intensity Freq
0 0
1 1 4 4 1 2
4 4 4 4 2 0
3 0
5 5 5 5
4 6
5 5 5 7 5 7
6 0
7 1
Histogram equalization
Draw the histogram
Intensity Freq
0 0
1 2
2 0
3 0
4 6
5 7
6 0
7 1
Histogram equalization

The Probability Density Function(PDF) defines the


probability function representing the density of a
continuous random variable lying between a specific
range of values.

PMF - Probability mass function refers to discrete


probabilities.
Histogram equalization
Calculate PMF for our intensities
PMF
Intensity Freq
(Freq/Total Pixels)
0 0 0
1 2 0.125
2 0 0
3 0 0
4 6 0.375
5 7 0.4375
6 0 0
7 1 0.0625
Histogram equalization

The cumulative distribution function (CDF) calculates


the cumulative probability for a given x-value. It can
be used as mapping function for equalization.

It is statistically proven that if we use CDF as


Transformation function the PDF of the output image
becomes uniform.
Histogram equalization
Calculating CDF
PMF
Intensity Freq CDF
(Freq/Total Pixels)
0 0 0 0
1 2 0.125 0.125
2 0 0 0.125
3 0 0 0.125
4 6 0.375 0.5
5 7 0.4375 0.9375
6 0 0 0.9375
7 1 0.0625 1
Histogram equalization
Converting CDF to required gray range
PMF
Intensity Freq CDF CDF*(L-1)
(Freq/Total Pixels)

0 0 0 0 0
1 2 0.125 0.125 0.875
2 0 0 0.125 0.875
3 0 0 0.125 0.875
4 6 0.375 0.5 3.5
5 7 0.4375 0.9375 6.5625
6 0 0 0.9375 6.5625
7 1 0.0625 1 7
Histogram equalization
CDF Function
Histogram equalization
Transforming levels to nearest integers
PMF Output Intensity
Intensity Freq CDF CDF*(L-1)
(Freq/Total Pixels) level

0 0 0 0 0 0
1 2 0.125 0.125 0.875 1
2 0 0 0.125 0.875 1
3 0 0 0.125 0.875 1
4 6 0.375 0.5 3.5 4
5 7 0.4375 0.9375 6.5625 7
6 0 0 0.9375 6.5625 7
7 1 0.0625 1 7 7
Histogram equalization
New Image

1 1 4 4
4 4 4 4
7 7 7 7
7 7 7 7
Histogram equalization
Histogram Comparison
Spatial filtering
A spatial filter consists of
(a) a neighborhood, and
(b) a predefined operation

Linear spatial filtering of an image of size M*N with a filter of size


m*n is given by the expression-
a b
g ( x, y) =   w(s, t ) f ( x + s, y + t )
s =− a t =− b

Here, a = (m-1)/2 and b=(n-1)/2


Spatial filtering
Spatial filtering
Correlation
The correlation of a filter 𝑤(𝑥, 𝑦) of size 𝑚 × 𝑛 with an image 𝑓(𝑥, 𝑦),
denoted as 𝑤(𝑥, 𝑦) 𝑓(𝑥, 𝑦)
𝑎 𝑏

𝑤(𝑥, 𝑦) 𝑓(𝑥, 𝑦) = ෍ ෍ 𝑤(𝑠, 𝑡)𝑓(𝑥 + 𝑠, 𝑦 + 𝑡)


𝑠=−𝑎 𝑡=−𝑏
Spatial filtering

Convolution
The convolution of a filter 𝑤(𝑥, 𝑦) of size 𝑚 × 𝑛
with an image 𝑓(𝑥, 𝑦), denoted as 𝑤(𝑥, 𝑦) 𝑓(𝑥, 𝑦)

𝑎 𝑏

𝑤(𝑥, 𝑦) 𝑓(𝑥, 𝑦) = ෍ ෍ 𝑤(𝑠, 𝑡)𝑓(𝑥 − 𝑠, 𝑦 − 𝑡)


𝑠=−𝑎 𝑡=−𝑏
Spatial filtering

Convolution
In order to perform convolution on an image, following steps should be taken.

➢ Flip the mask (horizontally and vertically) only once


➢ Slide the mask onto the image.
➢ Multiply the corresponding elements and then add them
➢ Repeat this procedure until all values of the image has been calculated.
Spatial filtering

Convolution
Spatial filtering

Convolution
Spatial filtering

Convolution

Do padding for
running the filter
on boundary pixels
Spatial filtering
MASK
A filter is also known as a mask. Concept of spatial filtering is also
known as masking. It is done by convolving a mask with an image.

Filters are applied on image for multiple purposes. The two most
common uses are as following:
➢ Filters are used for Blurring and noise reduction
➢ Filters are used or edge detection and sharpness
Spatial filtering

Smoothing Spatial Filters

➢ Smoothing filters are used for blurring and for noise reduction

➢ Blurring is used in removal of small details and bridging of small


gaps in lines or curves

➢ Smoothing spatial filters include linear filters and nonlinear filters.


Spatial filtering

Smoothing Spatial Filters


The general implementation for filtering an M × N image
with a weighted averaging filter of size m × n is given

σ𝑎𝑠=−𝑎 σ𝑏𝑡=−𝑏 𝑤(𝑠, 𝑡)𝑓(𝑥 + 𝑠, 𝑦 + 𝑡)


𝑔(𝑥, 𝑦) =
σ𝑎𝑠=−𝑎 σ𝑏𝑡=−𝑏 𝑤(𝑠, 𝑡)

where 𝑚 = 2𝑎 + 1, 𝑛 = 2𝑏 + 1.
Spatial filtering

Smoothing Spatial Filters

Box filter Weighted average filter


Spatial filtering

Smoothing Spatial Filters (Blurring)


Spatial filtering

Smoothing Spatial Filters (Noise reduction)


Spatial filtering

Smoothing Spatial Filters (Noise reduction)


Spatial filtering

Order-statistic (Nonlinear) Filters


— Nonlinear

— Based on ordering (ranking) the pixels contained in the filter mask

— Replacing the value of the center pixel with the value determined by the
ranking result

E.g., median filter, max filter, min filter


Spatial filtering

Order-statistic (Nonlinear) Filters

Mean filter Median filter


Sharpening Spatial Filters

► Foundation

► Laplacian Operator

► Unsharp Masking and Highboost Filtering

► Using First-Order Derivatives for Nonlinear Image Sharpening —


The Gradient
Sharpening Spatial Filters
Foundation

► The first-order derivative of a one-dimensional function f(x) is the


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

► The second-order derivative of f(x) as the difference

𝜕2𝑓
2
= 𝑓(𝑥 + 1) + 𝑓(𝑥 − 1) − 2𝑓(𝑥)
𝜕𝑥
Sharpening Spatial Filters
The second-order isotropic derivative operator is the Laplacian for
a function (image) f(x,y)

 f  f 2 2
 f = 2 + 2
2

x y
2 f
= f ( x + 1, y) + f ( x − 1, y) − 2 f ( x, y)
x 2

2 f
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y )
y 2

 2 f = f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)
- 4 f ( x, y)
Sharpening Spatial Filters

Laplacian mask
Sharpening Spatial Filters
In Positive Laplacian we have standard mask in which center element of the
mask should be negative and corner elements of mask should be zero.

In negative Laplacian operator we also have a standard mask, in which center


element should be positive.
Sharpening Spatial Filters

Image sharpening in the way of using the Laplacian:


𝑔(𝑥, 𝑦) = 𝑓(𝑥, 𝑦) + 𝑐 ∇2 𝑓(𝑥, 𝑦)
where,
𝑓(𝑥, 𝑦) is input image,
𝑔(𝑥, 𝑦) is sharpenend images,
𝑐 = −1 if ∇2 𝑓 𝑥, 𝑦 corresponding to 2 𝑝𝑜𝑠𝑖𝑡𝑖𝑣𝑒 𝑚𝑎𝑠𝑘
and 𝑐 = 1 if either of two negative filters is used.
Sharpening Spatial Filters

Image sharpening
in the way of
using the
Laplacian
Sharpening Spatial Filters
Unsharp Masking and Highboost Filtering

► Unsharp masking

Sharpen images consists of subtracting an unsharp


(smoothed) version of an image from the original image

► Steps

1. Blur the original image

2. Subtract the blurred image from the original

3. Add the mask to the original


Sharpening Spatial Filters
Unsharp Masking and Highboost Filtering

Let f ( x, y ) denote the blurred image, unsharp masking is


g mask ( x, y) = f ( x, y) − f ( x, y)
Then add a weighted portion of the mask back to the original
g ( x, y ) = f ( x, y) + k * g mask ( x, y) k 0

when k  1, the process is referred to as highboost filtering.


Sharpening Spatial Filters

Unsharp Masking and


Highboost Filtering
Sharpening Spatial Filters

Other edge detection masks (study)

1. Prewitt Operator

2. Sobel Operator

3. Robinson Compass Masks

4. Krisch Compass Masks


THANK YOU

You might also like