Chapter 2
Chapter 2
com
Objectives of Enhancement
Background Infomation
Chapter 3
Image Enhancement in the
Spatial Domain
Point Processing
s = T (r )
§ Where
§ r =gray level of f ( x, y )
§ s=gray level of g ( x, y)
Contrast Stretching
and
Thresholding
3 basic gray-level
transformation functions
Ø Linear function
Ø Negative and identity
transformation
Ø Logarithm function
Ø Log and inverse-log
transformation
Ø Power-low function
Additional Source:
Ø nth power and nth root https://www.tutorialspoint.com/dip/gray_lev
transformation el_transformations.htm
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Identity function
Image Negatives
Log Transformations
s = c log(1 + r )
Ø c is a contrast and r≥0
Ø Log curve maps a narrow
range of low gray-level
values in the input image
into a wider range of
output levels.
Ø Used to expand the values
of dark pixels in an image
while compressing the
Additional source: higher-level values.
https://www.geeksforgeeks.org/log-
transformation-of-an-image-using- If any pixel value is ‘0’ then its log value will
python-and-opencv/ become infinite. That’s 1 is added
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Power-Law
Transformations/Gamma correction
γ < 1, nth root
γ > 1, nth power
s = cr g
Ø c and g are positive constants
Ø Power-low curves with fractional
values of r map a narrow range of
dark input values with the opposite
being true for higher values of input
levels.
Ø c= g =1 → Identity function
Gamma correction
g =2.5
ü Gamma correction is
done by preprocessing
the image before
inputting it to the
1/ g
monitor with s = cr
g =1/2.5=4
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Another example
Another example
Piecewise-Linear
Transformation Functions
Ø Advantage :
Ø The form of piecewise function can be arbitrarily
complex
Ø Disadvantage:
Ø Their specification requires considerably more user
input
a b
Contrast Stretching (1/6) c d
ü Increase the dynamic range of
the gray levels in the image
ü (b) a low-contrast image: result
from poor illumination, lack of
dynamic range in the imaging
sensor, or even wrong setting of a
lens aperture of image acquisition
ü (c) result of contrast stretching
ü (d) result of thresholding
r
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Gray-level slicing
Bit-plane slicing
Example
8 bit planes
Bit-plane 7 Bit-plane 6
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 digital image with gray levels
Normalized Histogram
Histogram Processing
Example
rk
ü Dark image
components of histogram
are concentrated on the low
side of the gray scale
ü Bright image
components of histogram
are concentrated on the high
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
Histogram Transformation
s = T (r )
Ø Where 0 ≤ r ≤ 1
Ø T(r) satisfies
Ø T(r) is single-valued and
monotonically increasing in the
interval 0 ≤ r ≤ 1
Ø 0 ≤ T(r) ≤ 1 for 0 ≤ r ≤ 1
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Discrete Transformation
Function
r The probability of occurrence of gray level in an image is
approximated by
, where k = 0, 1, …, L-1
, where k = 0, …, L-1
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 equality
Ø Equalization can be achieved by the following
transformation function
Example
Example-Transformation
Example-Result
Example
Example
ü Image is dominated by
large, dark areas,
resulting in a histogram
characterized by a large
concentration of pixels in
pixels in the dark end of
the gray scale
Image Equalization
Histogram Specification
Histogram Mapping
Note
§ Histogram specification is s trial-and-error
process
§ There are no rules for specifying histograms, and
one must resort to analysis on a case-by-case basis
for any given enhancement task.
§ Histograms processing methods are global
processing, in the sense that pixels are modified by
a transformation function based in the gray-level
content of an entire image.
§ Sometimes, we may need to enhance details over
small areas in an image, which in called a local
enhancement.
Local Enhancement
Ø define a square or rectangular neighborhood and move the center of this area
from pixel to pixel.
Ø at each location, the histogram of the points in the neighborhood is computed
and either histogram equalization or histogram specification transformation
function is obtained.
Ø another approach used to reduce computation is to utilize nonoverlapping
regions, but it usually produces an undesirable checkerboard effect.
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Histogram Specification
Histogram Equalization
Histogram Equalization
using Desired Histogram of
of input image, S.
output image, Z.
vk
zk
1 4 6 13 15 20 24 25 1 8 13 18 20 23 25 25
Accumulative distribution of input Accumulative distribution of output
- S à R’ mapping RßZ
- In continuous space, the two
-Construct LUT as follows: equalize images (R and R’)
+ Map rk to sk using T(r) should be the same.
LUT 0 0 1 2 2 4 5 6
Histogram Specification
(1) the transformation
function G(z) obtained
from
k
G ( z k ) = å p z ( zi ) = s k
i =0
k = 0,1, 2,...L - 1
(2) the inverse
transformation G -1 ( s)
Enhancement using
Arithmetic/Logic Operations
Note
§ We may have to adjust the gray-scale of the
subtracted image to be [0,255] (if 8-bit is used)
§ first, find the minimum gray value of the subtracted
image
§ second, find the maximum gray value of the subtracted
image
§ Set the minimum value to be zero and the maximum to
be 255
§ We may also adjust the image as:
§ While the rest are adjusted according to the interval
[0,255], by timing each value with 255/max
§ Subtraction is used in segmentation of moving
pictures to track the changes
§ After subtract the sequenced images, what is left should
be the moving elements in the image, plus noise
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Addition
§ Useful for combining information between
two image
a b
Enhancement by
image subtraction.
(a) Mask image.
(b) An image with
mask subtracted
out.
a b
c d
Logic Operations
. =
+ =
Image Averaging
E{g ( x, y )} = f ( x, y )
1 2
s 2
g ( x, y ) = s h ( x, y )
K
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Image Averaging
Original K=1
K=8 K=16
K=64 K=128
Image Averaging
K=8
K=16
K=64
K=128
Spatial Filtering
Convolution
a b
g( x, y ) = å å ω( s,t ) f ( x - s, y - t )
s =- a t =- b
g = ω* f
Convolution
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
Rotate 180o 1 3 2 2
1 1 1
-1 2 1
-1 -1 1
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2
-1 4 2 2 3 5
Output
2 1
-1 -2 3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
-2
2 4
2 2 3 5 4
Output
2 -1
-2 1 3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 -2
2 4
2 3 5 4 4
Output
2 -1
1 -3
3 3 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 1 1
2 2 -2
2 36 1 5 4 4 -2
Output
2 1 3 -3
-3 3 1 Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
1 2 2 2 3 5 4 4 -2
Output
-1 4
2 1 3 3 9 Image, g
-1 -2
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Convolution
1 1 1 2 2 2 3
-1 2 1 2 1 3 3
-1 -1 1 2 2 1 2
1 3 2 2
2 2 2 3 5 4 4 -2
Output
-2
2 2
1 3 3 9 6 Image, g
-2
2 -2
2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Convolution
5 4 4 -2
9 6 14 5
11 7 6 5
9 12 8 5
Final output Image, g
Correlation
a b
g( x, y ) = å å ω( s,t ) f ( x + s, y + t )
s =- a t =- b
g = ω f
Correlation
correlation kernel, ω
1 -1 -1
Input Image f
1 2 -1
2 2 2 3
1 1 1
2 1 3 3
Don’t rotate use it directly
2 2 1 2
1 3 2 2
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 -1 -1 1 3 2 2
1 2 -2
4 2 2 3 5
1 2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 -2
4 2 3 5 10
2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 2 -3
4 3 5 10 10
2 1 3 3 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -1 -1
2 2 2 3
6 -1 5 10 10 15
2 1 3 3 1 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
1 -2
2 -2
2 2 3 5 10 10 15
1 4
2 -1
1 3 3 3 output
Image, g
1 2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Correlation
1 -1 -1 2 2 2 3
1 2 -1 2 1 3 3
1 1 1 2 2 1 2
1 3 2 2
2 -2
2 -2
2 3 5 10 10 15
2 2
1 -3
3 3 3 4 output
Image, g
2 2 1 2
1 3 2 2
Input Image, f
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Correlation
5 10 10 15
3 4 6 11
7 11 4 9
-5 4 4 5
Final output Image, g
Linear Filtering
Ø Linear Filtering of an image f of size M x N filter
mask of size m x n is defined as
$ &
Original 3x3
Note:
ü Big mask is used to
eliminate small objects
from an image
5x5 9x9
ü The size of the mask
establishes that relative
size of the objects that
will be blended with the
background.
15x15 35x35
Order-Statistics Filters
(Nonlinear Filters)
Ø 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,…,nxn}
Ø max filter : R=max{Zk | k=1,2,…,nxn}
Ø min filter : R=min{Zk | k=1,2,…,nxn}
Ø note : nxn is 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 such as impulse noise(or salt and pepper
noise), they provide excellent noise-reduction
capabilities, with considering less blurring than linear
smoothing filters of similar size.
Median Filters
r Forces the points with distinct gray levels to be
more like their neighbors.
r Isolated clusters of pixels that are light or dark
with respect to their neighbors, and whose area
is less than one-half the filter area, are
eliminated by an n x n median filter.
r Forced to have the value equal the median
intensity of the neighbors.
r Larger clusters are affected considerably less
© 2002 R. C. Gonzalez & R. E. Woods
Digital Image Processing, 2nd ed. www.imageprocessingbook.com
Derivative operator
Ø The response of a derivative operator is
proportional to the degree of discontinuity of the
image at the point at which the operator is applied.
Ø Thus, image differentiation
Ø enhances edges and other discontinuities (noise)
Ø deemphasizes area with slowly varying gray-level
values.
Example
Laplacian masks
Ø As 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
Example
Sharpening
f s ( x, y) = f ( x, y) - f ( x, y)
High-pass image = original image – blurred image
High-boost filtering
High-boost filtering
High-boost Masks
Example
Gradient Operator
Gradient Mask
Gradient Mask
Gradient Mask
Ø Sobel operators, 3x3
Note
§ The summation of coefficients in all
masks equals 0, which means that
they would give a response of 0 in an
area of constant gray level.
Edge Masks
Example
Ø solution :
1. Laplacian to highlight fine detail
2. gradient to enhance prominent edges
3. gray-level transformation to increase the dynamic
range of gray levels
Thank You