Module 2 IVP
Module 2 IVP
Image Enhancement
Why we need image enhancement?
⚫ Images may suffer from the following degradations:
⚫ Combination Methods
There are some enhancement techniques based on various combinations of
methods from the first two categories
Image Enhancement in the Spatial Domain
Image Enhancement: –
⚫ - To “improve” the usefulness of an image by using some transformation on the
image.
⚫ -- “better” looking, such as increasing the intensity or contrast.
⚫ A mathematical representation of spatial domain enhancement:
⚫ g(x,y) = T [f(x,y)]
⚫ Point processing
⚫ Neighborhood processing
Some Basic Intensity (Gray-level) Transformation
Functions(point processing functions)
⚫ Logarithmic Functions:
⚫ Log Transformation
⚫ Inverse-log Transformation
⚫ Power-Law Functions:
th
⚫ n power transformation
th
⚫ n root transformation
Linear Functions
⚫ Identity Function
⚫ The gray level in the range [0, L-1], where L = Largest value in an image
the negative transformation’s expression:
⚫ s=L–1–r
⚫ s = c log (1+r)
Where c is a constant, and r ≥ 0
⚫ Log curve maps a narrow range of low gray-level values in the input
image into a wider range of the output levels.
⚫ Used to expand the values of dark pixels in an image while compressing
the higher-level values.
⚫ It compresses the dynamic range of images with large variations in pixel
values.
expand the values of high pixels expand the values of dark pixels
in an image while compressing in an image while compressing
the darker-level values the higher-level values
Log
InvLog
Power-Law Transformations
⚫ Power-law transformations have the basic form of:
⚫ s = c.rᵞ
⚫ Where c and ᵞ are positive constants
• γ>1
• Compresses dark values
• Expands bright values
γ<1
Expands dark values
Compresses bright values
Power-Law Transformations
⚫ A variety of devices used for image capture, printing and display respond
according to a power law.
⚫ By convention, the exponent in the power law equation is referred as
gamma.
⚫ The process used to correct these power-law response phenomenon is
called as gamma correction.
⚫ E.g. CRT devices have an intensity-to-voltage response that is a power
function, with exponent varying from 1.8 to 2.5
⚫ With reference to the curve for gamma=2.5, the display system would tend
to produce images that are darker than intended.
Power-Law Transformation
Example 1: Gamma Correction
Example 2: Gamma Correction
Example 3: Gamma Correction
Piecewise-Linear Transformation Functions
⚫ Advantage:
⚫ the form of piecewise functions can be arbitrary complex over the
previous functions
⚫ Two approaches:
1. 1) Display high value for range of interest, low value else (‘discard
background’)
1
⚫ Image is composed of eight -bit planes.
BP 5
BP 7
Advantages of bit plane slicing
⚫ It is useful for analyzing the relative importance of each bit in the image, a
process that aids in determining the adequacy of the number of bits used
to quantize the image.
⚫ Reconstruction:
⚫ The reconstruction is done by multiplying the pixels of the nth plane by
the constant 2 rest to n-1 and added all planes.
Neighborhood processing/ Spatial Filtering
⚫ For each output pixel, some neighborhood of input pixels is used in the
computation.
⚫ In general, linear filtering of an image f of size M X N with a filter mask
of size m x n is given by
e e e
y Image f (x, y)
Strange Things Happen At The Edges! (cont…)
1 2 1
/16 /16 /16
⚫ Pixels closer to the
central pixel are more 2 4 2
/16 /16 /16
important
1 2 1
/16 /16 /16
⚫ Often referred to as a
weighted averaging Weighted averaging
filter
Smoothing Spatial Filtering
Origin x
1 1 1
104 100 108 /9 /9 /9
1 1 1
99
95
106
90
98
85
* 1
/9
/9 1
/9
/9 1
/9
/9
1 10
/9 110
/9 110
/9
Original Image Filter
4 0 8
Simple 3*3 1
/9
99 1106
/9 1
/9
98
3*3 Smoothing Pixels
Neighbourhood 1
/95 1
/9
90 1
/9
85
Filter
9
1
e= /9*106 +
1
/9*104 + 1/9*100 + 1/9*108 +
1
/9*99 + 1/9*98 +
1
y Image f (x, y) /9*95 + 1/9*90 + 1/9*85
=98.3333
The above is repeated for every pixel in the original image to
generate the smoothed image
Smoothing Spatial Filters
⚫ replacing the value of center pixel with value determined by the ranking
result.
Median filtering example
Median filtering example
⚫ Order-statistic filters:
⚫ Median filter: to reduce impulse noise (salt-and-pepper
noise)
A B
st nd
1 and 2 Derivative
f(x)
f’(x)
f’’(x)
st
1 Derivative (cont…)
f(x)
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
0 -1 -1 -1 -1 -1 0 0 6 -6 0 0 0 1 2 -2 -1 0 0 0 7 0 0
f’(x)
nd
2 Derivative (cont…)
f(x)
5 5 4 3 2 1 0 0 0 6 0 0 0 0 1 3 1 0 0 0 0 7 7 7 7
-1 0 0 0 0 1 0 6 -12 6 0 0 1 1 -4 1 1 0 0 7 -7 0 0
f’’(x)
Using Second Derivatives For Image sharpening
⚫The 2nd derivative is more useful for image enhancement than the 1st derivative
⚫ Stronger response to fine detail
⚫ Simpler implementation
1 -4 1
0 1 0
Use of Second Derivatives for Enhancement
The Laplacian
The Laplacian (cont…)
⚫Applying the Laplacian to an image we get a new image that highlights edges and
other discontinuities and deemphasize regions with slowly varying intensities.
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Produce images that have greyish edge lines and other discontinuities , all
superimposed on black featureless background.
Laplacian
Filtered Image
Scaled for
Display
Laplacian Image Enhancement
- =
Original Laplacian Sharpened
Image Filtered Image Image
⚫In the final sharpened image edges and fine detail are much more
obvious
Laplacian Image Enhancement
Simplified Image Enhancement
⚫The entire enhancement can be combined into a single filtering operation
Simplified Image Enhancement (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
⚫This gives us a new filter which does the whole job for us in one step
0 -1 0
-1 5 -1
0 -1 0
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
0 1 0 1 1 1
Simple Variant of
1 -4 1 1 -8 1
Laplacian Laplacian
0 1 0 1 1 1
-1 -1 -1
-1 9 -1
-1 -1 -1
Unsharp Masking & Highboost Filtering
⚫Using sequence of linear spatial filters in order to get
Sharpening effect.
Avg.
-
+
+
K<1 de-emphasize the contribution of the unsharp
mask
Example of unsharp masking
st
1 Derivative for image sharpening – The Gradient
⚫ An image gradient is a directional change in the intensity or color in an
image. Image gradients may be used to extract information from images.
Δx
good
(x+1/2,y)
approximation (x,y+1/2)
at (x+1/2,y) *
*
good approximation
at (x,y+1/2)
Roberts cross –gradient operators
A different approximation of the gradient:
good approximation
(x+1/2,y+1/2)
*
• Other approximations
Sobe
l
st
1 Derivative Filtering (cont…)
• Other approximations
⚫There is some debate as to how best to calculate these gradients but we will use:
z1 z2 z3
z4 z5 z6
z7 z8 z9
Sobel Operators
⚫Based on the previous equations we can derive the Sobel
Operators
-1 -2 -1 -1 0 1
0 0 0 -2 0 2
1 2 1 -1 0 1
⚫To filter an image it is filtered using both operators the results of which
are added together
Sobel Example
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
Sobel
st nd
1 & 2 Derivatives
⚫Comparing the 1st and 2nd derivatives we can conclude the following:
⚫ 1st order derivatives generally produce thicker edges
⚫ 2nd order derivatives have a stronger response to fine detail e.g.
thin lines
⚫ 1st order derivatives have stronger response to grey level step
⚫ 2nd order derivatives produce a double response at step changes in
grey level
Combining Spatial Enhancement Methods (cont…)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
(a)
Laplacian filter of bone scan
(a)
(b)
Sharpened version of bone
scan achieved by subtracting (c)
(a) and (b)
Sobel filter of bone scan (a)
(d)
Combining Spatial Enhancement Methods (cont…)
Result of applying a (h)
power-law trans. to (g)
Images taken from Gonzalez & Woods, Digital Image Processing (2002)
(e)
What is Histogram?
0 1 1 2 4
2 1 0 0 2
5 2 0 0 4
1 1 2 4 1
image histogram
Why Histogram?
⚫ Histograms are the basis for numerous spatial domain processing techniques.
Dark image
The horizontal axis of each histogram plot corresponds to gray level values, rk.
The vertical axis corresponds to values of h(rk)=nk or p(rk)=nk/n if the
values are normalized.
Bright image
Over-exposed image
Histogram Processing
1 4 5 0
3 1 5 1
Types of processing:
Histogram equalization
Histogram matching (specification)
Number of
Pixels
gray level
Histogram Equalization Example:
Histogram of an image represents the relative frequency of occurrence of various
gray levels in the image
•Let us assume for the moment that the input image to be enhanced has
continuous gray values, with r = 0 representing black and r = L-1
representing white.
1 1
⚫ (2) T(r) maps [0, L- ] into [0, L- ] (preserves the range of allowed
Gray values).
-1
∙Ιnverse transformation r = T (s) .
0 ≤ s ≤ L -1
∙ Consider an 8-level 64 x 64 image with gray values (0, 1, …,7). The normalized gray
values are (0, 1/7, 2/7, …, 1). The normalized histogram is given below:
NB: The gray values in output are also (0, 1/7, 2/7, …, 1).
# pixels Fraction of #
pixels
# pixels
Gray values
∙ Note that the histogram of output image is only approximately, and not
exactly, uniform. This should not be surprising, since there is no result
that claims uniformity in the discrete case.
Example Original image and its histogram
Histogram equalized image and its histogram
∙ Comments:
Histogram equalization may not always produce desirable results,
particularly if the given histogram is very narrow. It can produce
false edges and regions. It can also increase image “graininess” and
“patchiness.”
Histogram Equalization
Histogram Specification
desired
equaliz G equalize
e -1
G
Histogram Specification(Histogram Matching)
⚫ Histogram equalization yields an image whose pixels are (in theory)
uniformly distributed among all gray levels.
Goal
⚫ Derive a point operation, H(r), that maps the input image into an
output image that has the user-specified histogram.
s=T(r) v=G(z)
⚫ Suppose, the input image has probability density in p(r) . We
⚫ want to find a transformation z = H (r) , such that the probability density of
the new image obtained by this transformation is pout(z) , which is not
necessarily uniform.
⚫ First apply the transformation
-1
Z=H(r)= G [ v=s =T(r)]
⚫ For discrete gray levels, we have
Algorithm for histogram specification:
⚫ (1) Equalize input image to get an image with uniform gray values, using the
discrete equation:
⚫ (2) Based on desired histogram to get an image with uniform gray values,
using the discrete equation:
Example:
# pixels
Gray value
∙ It is desired to transform this image into a new image, using a
transformation Z=H(r)= G-1[T(r)], with histogram as specified below:
# pixels
Gray values
∙The transformation T(r) was obtained earlier (reproduced
below):