DIP OJ Part A
DIP OJ Part A
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)
Fig: Digital picture produced in 1921 from a coded tape by a telegraph printer
The origins of digital image processing (Cont.)
Positron Emission
Tomography(PET)
Applications of DIP
X-ray Imaging
UV-ray Imaging
Infrared
Imaging
250
200
150
100
50
Microwaves
Imaging
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
Image filtering
Knowledge base Representation
and Enhancement
Image Object
Acquisition recognition
Visual perception of human
Visual perception of human
http://www-bcs.mit.edu/people/adelson
Lightness Perception: Objective Quantities
log (cd/m2)
Lightness Perception: Objective Quantities
➢r(x,y) – typical reflectance indixes
black velvet (0.01) silver plate (0.90)
f(x,y)=i(x,y)r(x,y)
0<i(x,y)<∞ Illumination/shading
Observer (Camera)
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
Sampling
The Nyquist Rate
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:
𝑟(𝑥, 𝑦)
𝑓(𝑥, 𝑦) = 𝑔(𝑥, 𝑦)
𝑏(𝑥, 𝑦)
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.
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
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
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
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
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
a. D(p, q) ≥ 0 [D(p, q) = 0, if p = q]
b. D(p, q) = D(q, p)
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
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
Bilinear Interpolation
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
g(x,y) = T [ f(x,y)]
g(x,y) = T [ f(x,y)]
❑ T → Operation/ Transform
method defined over the
neighbourhood of point(x,y)
Spatial processing
s = T (r)
❑ Intensity transformation
❑ Spatial Filtering
→ (Operates in neighbourhood)
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
Sharpness
Some basic Intensity transformation Functions
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
s = T(r)
= c*rγ
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.
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
❑ So, it is better to clip a certain percentage like 1%, 2% of the data from the
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
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
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
Convolution
The convolution of a filter 𝑤(𝑥, 𝑦) of size 𝑚 × 𝑛
with an image 𝑓(𝑥, 𝑦), denoted as 𝑤(𝑥, 𝑦) 𝑓(𝑥, 𝑦)
𝑎 𝑏
Convolution
In order to perform convolution on an image, following steps should be taken.
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 filters are used for blurring and for noise reduction
where 𝑚 = 2𝑎 + 1, 𝑛 = 2𝑏 + 1.
Spatial filtering
— Replacing the value of the center pixel with the value determined by the
ranking result
► Foundation
► Laplacian Operator
𝜕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.
Image sharpening
in the way of
using the
Laplacian
Sharpening Spatial Filters
Unsharp Masking and Highboost Filtering
► Unsharp masking
► Steps
1. Prewitt Operator
2. Sobel Operator