Module 21
Module 21
Process an image so that the result will be more suitable than the original
image for a specific application.
The suitableness is up to each application.
A method which is quite useful for enhancing an image may not
necessarily be the best approach for enhancing another images
2 domains
• Spatial Domain : (image plane)
– Techniques are based on direct manipulation of pixels in an image
– Procedures that operate directly on pixels
• Frequency Domain :
– Techniques are based on modifying the Fourier transform of an image
• There are some enhancement techniques based on various combinations of
methods from these two categories.
Good images
• A certain amount of trial and error usually is required before a particular image
enhancement approach is selected.
Pont Processing
• g(x,y) = T[f(x,y)]
– where
– f(x,y) is the input image
– g(x,y) is the processed image
– T is an operator on f defined over f(x,y)
Image Negatives
• An image with gray level in the range [0,
Negative L-1]
nth root where L = 2n ; n = 1, 2…
Log • Negative transformation :
nth power
s = L – 1 –r
• Reversing the intensity levels of an image.
• Suitable for enhancing white or gray detail
Identity Inverse Log
embedded in dark regions of an image,
especially when the black area dominant in
Input gray level, r size.
Contrast Stretching
Contrast Stretching
Thresholding
• Produce a two-level (binary) image
Identity function
• Output intensities are identical to
Negative
nth root input intensities.
Log nth power • Is included in the graph only for
completeness.
Identity Inverse Log
Log Transformations
s = c log (1+r)
Negative
nth root • c is a constant
Log and r 0
nth power
• Log curve maps a narrow range of low
gray-level values in the input image
into a wider range of output levels.
Identity Inverse Log • Used to expand the values of dark
pixels in an image while compressing
Input gray level, r
the higher-level values.
Log Transformations
• It compresses the dynamic range of images with large variations in pixel values
• Example of image with dynamic range: Fourier spectrum image
• It can have intensity range from 0 to 106 or higher.
• We can’t see the significant degree of detail as it will be lost in the display.
Power-Law Transformations
s = cr
• c and are positive constants
• Power-law curves with fractional
values of map a narrow range of
dark input values into a wider range
of output values, with the opposite
being true for higher values of input
Input gray level, r levels.
Plots of s = cr for various values of • c = = 1 Identity function
(c = 1 in all cases)
Gray-level slicing
Bit-plane slicing
Example
8 bit planes
Bit-plane Bit-plane
7 6
Bit- Bit- Bit-
plane plane plane
5 4 3
Bit- Bit- Bit-
plane plane plane
2 1 0
Histogram Processing
• Histogram of a digital image with gray levels in the range [0,L-1] is a discrete
function
• h(rk) = nk
• Where
– rk : the kth gray level
– nk : the number of pixels in the image having gray level rk
– h(rk) : histogram of a digital image with gray levels rk
Normalized Histogram
• dividing each of histogram at gray level rk by the total number of pixels in the
image, n
• p(rk) = nk / n
• For k = 0,1,…,L-1
• p(rk) gives an estimate of the probability of occurrence of gray level rk
• The sum of all components of a normalized histogram is equal to 1
Example
Components of histogram are
Dark image concentrated on the low side of the
gray scale.
Example
Low-contrast image
histogram is narrow and centered
toward the middle of the gray scale
High-contrast image
histogram covers broad range of the gray scale
and the distribution of pixels is not too far from
uniform, with very few vertical lines being much
higher than the others
Histogram Equalization
• As the low-contrast image’s histogram is narrow and centered toward the middle
of the gray scale, if we distribute the histogram to a wider range the quality of the
image will be improved.
• We can do it by adjusting the probability density function of the original histogram
of the image so that the probability spread equally
Histogram Equalization
• The probability of occurrence of gray level in an image is approximated by
nk
pr ( rk ) = where k = 0 , 1, ..., L- 1
n
• The discrete version of transformation
k
sk = T ( rk ) = pr ( r j )
j =0
k nj
= where k = 0 , 1, ..., L-1
j =0 n
Continuous case:
s = T (r ) = ( L − 1) pr ( w)dw
r
Discrete values:
k
sk = T (rk ) = ( L − 1) pr (rj )
j =0
knj L −1 k
= ( L −1) = nj k=0,1,..., L-1
j =0 MN MN j =0
Histogram Equalization
• Thus, an output image is obtained by mapping each pixel with level rk in the input
image into a corresponding pixel with level sk in the output image
• In discrete space, it cannot be proved in general that this discrete transformation
will produce the discrete equivalent of a uniform probability density function,
which would be a uniform histogram
Example
Histogram
before after
equalization
Example
No. of pixels
2 3 3 2
4 2 4 3 6
5
3 2 3 5
4
2 4 2 4 3
2
4x4 image
1
Gray level
Gray scale = [0,9]
0 1 2 3 4 5 6 7 8 9
histogram
Department of Computer Science & Engineering
Dr. Justin Varghese Slide 28
19ECS352: IMAGE PROCESSING
Gray
0 1 2 3 4 5 6 7 8 9
Level(j)
No. of
0 0 6 5 4 1 0 0 0 0
pixels
n
j =0
j 0 0 6 11 15 16 16 16 16 16
nk 6 11 15 16 16 16 16 16
s= j 0 0 / / / / / / / /
j =0 n
16 16 16 16 16 16 16 16
Example
No. of pixels
6
3 6 6 3
5
8 3 8 6 4
6 3 6 9 3
2
3 8 3 8
1
Output image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level
Histogram equalization
Department of Computer Science & Engineering
Dr. Justin Varghese Slide 30
19ECS352: IMAGE PROCESSING
Logic Operations
Logic operation performs on gray-level images, the pixel values are processed as
binary numbers
light represents a binary 1, and dark represents a binary 0
NOT operation = negative transformation
Example of OR Operation
Image Subtraction
g(x,y) = f(x,y) – h(x,y)
a b
c d
Department of Computer Science & Engineering
Dr. Justin Varghese Slide 34
19ECS352: IMAGE PROCESSING
Spatial Filtering
Linear Filtering
•Linear Filtering of an image f of size MxN filter mask of size mxn is given by the
expression
a b
g ( x, y) = w(s, t ) f ( x + s, y + t )
t =− a t =−b
output is simply the average of the pixels contained in the neighborhood of the filter
mask called averaging filters or lowpass filters.
replacing the value of every pixel in an image by the average of the gray levels in the
neighborhood will reduce the “sharp” transitions in gray levels.
sharp transitions
random noise in the image
edges of objects in the image
thus, smoothing can reduce noises (desirable) and blur edges (undesirable)
•the basic strategy behind weighting the center point the highest and then
reducing the value of the coefficients as a function of increasing distance from the
origin is simply an attempt to reduce blurring in the smoothing process.
w(s, t ) f ( x + s, y + t )
g ( x, y) = s = − at = − b
a b
w(s, t )
s = − at = − b
Example
a b
c d
e f
Example
we can see that the result after smoothing and thresholding, the remains are the largest
and brightest objects in the image.
the response is based on ordering (ranking) the pixels contained in the image area
encompassed by the filter
example
median filter : R = median{zk |k = 1,2,…,n x n}
max filter : R = max{zk |k = 1,2,…,n x n}
min filter : R = min{zk |k = 1,2,…,n x n}
note: n x nis the size of the mask
Median Filters
replaces the value of a pixel by the median of the gray levels in the
neighborhood of that pixel (the original value of the pixel is included in the
computation of the median)
quite popular because for certain types of random noise (impulse noise
salt and pepper noise) , they provide excellent noise-reduction capabilities,
with considering less blurring than linear smoothing filters of similar size.
forces the points with distinct gray levels to be more like their neighbors.
isolated clusters of pixels that are light or dark with respect to their
neighbors, and whose area is less than n2/2 (one-half the filter area), are
eliminated by an n x n median filter.
eliminated = forced to have the value equal the median intensity of the
neighbors.
larger clusters are affected considerably less
to highlight fine detail in an image or to enhance detail that has been blurred,
either in error or as a natural effect of a particular method of image
acquisition.
Derivative operator
First-order derivative
the difference
f
= f ( x + 1) − f ( x)
x
Second-order derivative
• when we consider an image function of two variables, f(x,y), at which time we will
dealing with partial derivatives along the two spatial axes.
f ( x, y) f ( x, y) f ( x, y)
Gradient operator f = = +
xy x y
Laplacian operator 2 f ( x, y) 2 f ( x, y)
2 f = +
x 2 y 2
(linear operator)
yield,
2
f = [ f ( x + 1, y) + f ( x − 1, y)
+ f ( x, y + 1) + f ( x, y − 1) − 4 f ( x, y)]
as it is a derivative operator,
it highlights gray-level discontinuities in an image
it deemphasizes regions with slowly varying gray levels
tends to produce images that have
grayish edge lines and other discontinuities, all superimposed on a dark,
featureless background.
Example
1 1 1
1 -8 1
1 1 1
•to simply the computation, we can create a mask which do both operations,
Laplacian Filter and Addition the original image.
g ( x, y) = f ( x, y) − [ f ( x + 1, y) + f ( x − 1, y)
0 -1 0
+ f ( x, y + 1) + f ( x, y − 1) + 4 f ( x, y)] -1 5 -1
= 5 f ( x, y) − [ f ( x + 1, y) + f ( x − 1, y)
+ f ( x, y + 1) + f ( x, y − 1)] 0 -1 0
Example
Note
f ( x, y) − 2 f ( x, y)
g ( x, y) =
f ( x, y) + f ( x, y)
2
0 -1 0 0 0 0 0 -1 0
-1 5 -1 = 0 1 0 + -1 4 -1
0 -1 0 0 0 0 0 -1 0
0 -1 0 0 0 0 0 -1 0
-1 9 -1 = 0 1 0 + -1 8 -1
0 -1 0 0 0 0 0 -1 0
Unsharp masking
f s ( x, y) = f ( x, y) − f ( x, y)
sharpened image = original image – blurred image
High-boost filtering
f hb ( x, y) = Af ( x, y) − f ( x, y)
f hb ( x, y) = ( A −1) f ( x, y) + f ( x, y) − f ( x, y)
= ( A − 1) f ( x, y) + f s ( x, y)
f hb ( x, y) = ( A − 1) f ( x, y) + f s ( x, y)
• if we use Laplacian filter to create sharpen image fs(x,y) with addition of original
image
f ( x, y) − 2 f ( x, y)
f s ( x, y) =
f ( x, y ) + 2
f ( x, y)
High-boost Masks
• A1
• if A = 1, it becomes “standard”
Laplacian sharpening
Department of Computer Science & Engineering
Dr. Justin Varghese Slide 61
19ECS352: IMAGE PROCESSING
Example
Background
1 M −1 N −1
F (u, v) =
MN x=0 y =0
f ( x, y )e − j 2 ( ux / M + vy / N )
M −1 N −1
f ( x, y) = F (u, v)e j 2 (ux / M +vy / N )
u =0 v =0
1
F (u, v) = R (u, v) + I (u, v)
2 2 2 ( spectrum)
I (u, v)
(u, v) = tan−1 (phase angle)
R(u, v)
P(u,v) = F (u, v) = R 2 (u, v) + I 2 (u, v) (powerspectrum)
2
f ( x, y)(−1) x + y = F (u −
M
2
N
, v − ) (shift)
2
1 M −1 N −1
F (0,0) =
MN x =0 y =0
f ( x, y) (average)
shift
Department of Computer Science & Engineering
Dr. Justin Varghese Slide 72
19ECS352: IMAGE PROCESSING
DFT
DFT
A
DFT
B
DFT
A
DFT
B DFT
Rectangle
Its DFT
Questions?
Thank You