Image Processing
Sanjay Bhanderi
Pattern Recognition and Image Analysis
Digital Image Processing
• What is Digital Image Processing?
Digital Image
— a two-dimensional function
x and y are spatial coordinates
The amplitude of f is called intensity or gray level at the point (x, y)
Digital Image Processing
— process digital images by means of computer, it covers low-, mid-, and
high-level processes
low-level: inputs and outputs are images – Image Processing
mid-level: outputs are attributes extracted from input images – Image Analysis
high-level: an ensemble of recognition of individual objects – Image Understandig
Pixel
— the elements of a digital image
Pattern Recognition and Image Analysis
Simple Image Formation Model
Pattern Recognition and Image Analysis
Representing Digital Images
• The representation of an M×N numerical array
as
Pattern Recognition and Image Analysis
Representing Digital Images
• Discrete intensity interval [0, L-1], L=2k
• The number b of bits required to store a M × N
digitized image
b=M×N×k
Pattern Recognition and Image Analysis
Image Processing
• An image processing operation typically
defines a new image g in terms of an existing
image f.
• We can transform either the range of f.
g(x,y) = t(f(x,y))
Pattern Recognition and Image Analysis
Key Stages in Digital Image Processing
Image Morphological
Restoration Processing
Image
Segmentation
Enhancement
Image Object
Acquisition Recognition
Representation
Problem Domain
& Description
Colour Image Image
Processing Compression
Pattern Recognition and Image Analysis
Image Interpolation
• Interpolation is used in tasks such as zooming,
shrinking, rotating, and geometrically
correcting digital images.
• Interpolation is the process of using known
data to estimate values at unknown locations.
• Nearest Neighbor Interpolation because it
assigns to each new location the intensity of
its nearest neighbor in the original image
Pattern Recognition and Image Analysis
Image Interpolation (cont…)
• Bilinear Interpolation, the assigned value is
obtained using the equation
• where the four coefficients are determined
from the four equations in four unknowns that
can be written using the four nearest
neighbors of point (x, y).
Pattern Recognition and Image Analysis
Image Interpolation (cont…)
• Bicubic Interpolation, which involves the
sixteen nearest neighbors of a point.
• The intensity value assigned to point (x, y) is
obtained using the equation
Pattern Recognition and Image Analysis
Basic Relationships Between Pixels
• 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)
Pattern Recognition and Image Analysis
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).
Pattern Recognition and Image Analysis
Basic Relationships Between Pixels
• Adjacency
Let V be the set of intensity values
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(p) has no pixels whose values
are from V.
Pattern Recognition and Image Analysis
Basic Relationships Between Pixels
• 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.
Pattern Recognition and Image Analysis
Examples: Adjacency and Path
V = {1, 2}
0 1 1 1,1 1,2 1,3 0 1 1 0 1 1
0 2 0 2,1 2,2 2,3 0 2 0 0 2 0
0 0 1 3,1 3,2 3,3 0 0 1 0 0 1
8-adjacent m-adjacent
The 8-path from (1,3) to (3,3): The m-path from (1,3) to (3,3):
(i) (1,3), (1,2), (2,2), (3,3) (1,3), (1,2), (2,2), (3,3)
(ii) (1,3), (2,2), (3,3)
Pattern Recognition and Image Analysis
Basic Relationships Between Pixels
• 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
(x0, y0), (x1, y1), …, (xn, yn)
Where
Pattern Recognition and Image Analysis
Basic Relationships Between Pixels
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.
Pattern Recognition and Image Analysis
Distance Measures
• 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, iff p = q]
b. D(p, q) = D(q, p)
c. D(p, z) ≤ D(p, q) + D(q, z)
Pattern Recognition and Image Analysis
Distance Measures
The following are the different Distance measures:
a. Euclidean Distance :
De(p, q) = [(x-s)2 + (y-t)2]1/2
b. City Block Distance:
D4(p, q) = |x-s| + |y-t|
c. Chess Board Distance:
D8(p, q) = max(|x-s|, |y-t|)
Pattern Recognition and Image Analysis
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).
• The complement of A is denoted Ac
Pattern Recognition and Image Analysis
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).
• The complement of A is denoted Ac
Pattern Recognition and Image Analysis
Set and Logical Operations
Pattern Recognition and Image Analysis
Geometric Spatial Transformations
• Geometric transformation (rubber-sheet transformation)
— A spatial transformation of coordinates
— intensity interpolation that assigns intensity values to the spatially transformed
pixels.
• Affine transform
Pattern Recognition and Image Analysis
Pattern Recognition and Image Analysis
Image Transform
• Important class of 2-D linear transforms, denoted T(u, v)
Pattern Recognition and Image Analysis
Image Transform
• Given T(u, v), the original image f(x, y) can be recoverd using
the inverse tranformation of T(u, v).
Pattern Recognition and Image Analysis
Image Transform
Pattern Recognition and Image Analysis
2-D Fourier Transform
Pattern Recognition and Image Analysis
Probabilistic Methods
Pattern Recognition and Image Analysis
Probabilistic Methods
Pattern Recognition and Image Analysis
Contrast Stretching
• Contrast stretching expands the range of
intensity levels in an image
Pattern Recognition and Image Analysis
Contrast Stretching (Cont…)
• The locations of (r1,s1) and (r2,s2) control the shape of the
transformation function.
– If r1= s1 and r2= s2 the transformation is a linear function and
produces no changes.
– If r1=r2, s1=0 and s2=L-1, the transformation becomes a
thresholding function that creates a binary image.
– Intermediate values of (r1,s1) and (r2,s2) produce various degrees
of spread in the gray levels of the output image, thus affecting
its contrast.
– Generally, r1≤r2 and s1≤s2 is assumed.
Pattern Recognition and Image Analysis
Intensity-Level Slicing
• Highlight a specific range of intensities in an image
• One approach is to display in one value(say, white)
all the values in the range of interest and in
another (say, black) all other intensities.
• Second based on the transformation in, brightens
(or darkens) desired range of intensities, but
leaves all other intensity levels in the image
unchanged
Pattern Recognition and Image Analysis
Bit-Plan Slicing
• To highlight the contribution made to the total
image appearance by specific bits.
– i.e. Assuming that each pixel is represented by 8
bits, the image is composed of 8 1-bit planes.
– Plane 0 contains the least significant bit and plane
7 contains the most significant bit.
– Only the higher order bits (top four) contain
visually significant data. The other bit planes
contribute the more subtle details.
Pattern Recognition and Image Analysis
Histogram Processing
• The histogram of a digital image with gray levels
from 0 to L-1 is a discrete function h(rk)=nk, where:
– rk is the kth gray level
– nk is the # pixels in the image with that gray level
– n is the total number of pixels in the image
– k = 0, 1, 2, …, L-1
• Normalized histogram: p(rk)=nk/n
– sum of all components = 1
• -
Pattern Recognition and Image Analysis
Histogram Equilization
Pattern Recognition and Image Analysis
Example: Histogram Equalization
• Suppose that a 3-bit image (L=8) of size 64 × 64 pixels (MN = 4096) has the
intensity distribution shown in following table.
• Get the histogram equalization transformation
function and give the ps(sk) for each sk.
Pattern Recognition and Image Analysis
Example: Histogram Equalization
Pattern Recognition and Image Analysis
Example: Histogram Equalization
• (a) Original histogram. (b) Transformation
function. (c) Equalized histogram.
Pattern Recognition and Image Analysis
Histogram Specification (Matching)
• Histogram matching or histogram
specification is the transformation of an image
so that its histogram matches a specified
histogram.
Pattern Recognition and Image Analysis
Convolution and Correction
Pattern Recognition and Image Analysis
Cross-Correlation
● A 2D function
Can be filtered by a 2D filter (kernel)
To get a new image
● This is called a cross-correlation operation
Or a sliding dot-product
Pattern Recognition and Image Analysis
● Cross-correlation in which the filter is flipped
horizontally and vertically is called convolution
Pattern Recognition and Image Analysis
Convolution vs. Cross-Correlation
● If the kernel is symmetric
convolution = cross-correlation
Pattern Recognition and Image Analysis
Mean Filter
• Replace each pixel with the average of a kxk
window around it
• kernel for a 3x3 mean filter
Pattern Recognition and Image Analysis
Gausian Filter
• A Gaussian kernel gives less weight to pixels
further from the center of the window
Pattern Recognition and Image Analysis
Median Filter
• The value of the center pixel by the median of
the intensity values in the neighborhood of
that pixel
Pattern Recognition and Image Analysis
HighPass / LowPass Filter
• High frequencies (which are responsible for
fine details) are passed, while low frequencies
are rejected.
• Filter that passes low frequencies is called a
lowpass filter.
• The net effect produced by a lowpass filter is
to smooth an image by blurring it.
Pattern Recognition and Image Analysis
Histogram Of Gradient
• The Image Gradient Vector is defined as a
metric for every individual pixel, containing
the pixel color changes in both x-axis and
y-axis.
• gradient vector of the pixel (x, y) is defined as
follows:
Pattern Recognition and Image Analysis
Histogram Of Gradient
• here are two important attributes of an image
gradient:
• Magnitude is the L2-norm of the vector,
• Direction is the arctangent of the ratio
between the partial derivatives on two
directions,
Pattern Recognition and Image Analysis
Step of Histogram of Gradient
• Preprocess the image, including resizing and
color normalization
• Compute the gradient vector of every pixel, as
well as its magnitude and direction.
• Divide the image into many 8x8 pixel cells. In
each cell, the magnitude values of these 64
cells are binned and cumulatively added into 9
buckets of unsigned direction (no sign, so
0-180 degree rather than 0-360 degree
Pattern Recognition and Image Analysis
Step of Histogram of Gradient
Pattern Recognition and Image Analysis
Step of Histogram of Gradient
• Then we slide a 2x2 cells (thus 16x16 pixels) block
across the image. In each block region, 4
histograms of 4 cells are concatenated into
one-dimensional vector of 36 values and then
normalized to have an unit weight.
• The final HOG feature vector is the concatenation
of all the block vectors. It can be fed into a
classifier learning object recognition tasks.
•
Pattern Recognition and Image Analysis
Morphological Image Processing
• Tool for extracting image components, that
are useful in the representation and
description of region shape.
Pattern Recognition and Image Analysis
Dilation
• Dilation is used for expanding an element A by using structuring
element B
• Dilation of A by B and is defined by the following equation:
• This equation is based on obtaining the reflection of B
about its origin and shifting this reflection by z.
• The dilation of A by B is the set of all displacements z,
such that and A overlap by at least one element. Based
On this interpretation the equation of (9.2-1) can be
rewritten as:
Pattern Recognition and Image Analysis
Dilation – Example 2
Pattern Recognition and Image Analysis
Erosion
• Erosion is used for shrinking of element A by using element B
• Erosion for Sets A and B in Z2, is defined by the
following equation:
• This equation indicates that the erosion of A by B
is the set of all points z such that B, translated by
z, is combined in A.
Pattern Recognition and Image Analysis
Erosion – Example 1
Pattern Recognition and Image Analysis
Erosion – Example 2
Pattern Recognition and Image Analysis
Duality between dilation and erosion
• Dilation and erosion are duals of each other
with respect to set complementation and
reflection. That is,
• One of the simplest uses of erosion is for
eliminating irrelevant details (in terms of size)
from a binary image.
Pattern Recognition and Image Analysis
Opening And Closing
• Opening –
– First – erode A by B, and then dilate the result by B
– In other words, opening is the unification of all B
objects Entirely Contained in A
Pattern Recognition and Image Analysis
Opening And Closing
• Closing –
– First – dilate A by B, and then erode the result by B
– In other words, closing is the group of points,
which the intersection of object B around them
with object A – is not empty
Pattern Recognition and Image Analysis
Basic Morphological Algorithms
• 1 – Boundary Extraction
• 2 – Region Filling
• 3 – Extraction of Connected Components
• 4 – Convex Hull
• 5 – Thinning
• 6 – Thickening
• 7 – Skeletons
Pattern Recognition and Image Analysis
Boundary Extraction
• First, erode A by B, then make set difference
between A and the erosion
• The thickness of the contour depends on the
size of constructing object – B
Pattern Recognition and Image Analysis
Region Filling
• This algorithm is based on a set of dilations,
complementation and intersections
• p is the point inside the boundary, with the
value of 1
• X(k) = (X(k-1) xor B) conjunction with
complemented A
• The process stops when X(k) = X(k-1)
• The result that given by union of A and X(k), is a
set contains the filled set and the boundary
Pattern Recognition and Image Analysis
Region Filling
Pattern Recognition and Image Analysis
Extraction of Connected Components
Pattern Recognition and Image Analysis
?
Thank You.
Pattern Recognition and Image Analysis