Digital Image Processing CPE3643
Lecture 4:
Image Enhancement and Histogram
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 1
Image Enhancement
Process an image to make the result more suitable than the original
image for a specific application
– Image enhancement is subjective (problem/application
oriented)
Image enhancement methods
Spatial domain: Direct manipulation of pixel in an image(on the
image plane)
Frequency domain: Processing the image based on modifying the
Fourier transform of an image
Many techniques are based on various combinations of methods from
these two categories
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 2
1
Image Enhancement
Types of image enhancement operations
Point/pixel operations Output value at specific coordinates (x,y) is
dependent only on the input value at (x,y)
Local operations The output value at (x,y) is dependent on the
input values in the neighborhood of (x,y)
Global operations The output value at (x,y) is dependent on all
the values in the input image
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 3
Basic concepts
Spatial domain enhancement methods can be generalized as
g(x,y)=T[f(x,y)]
f(x,y) : input image
g(x,y): processed (output) image
T[*] : an operator on f (or a set of input images),
defined over neighborhood of (x,y)
Neighborhood about (x,y): a square or rectangular sub-
image area centered at (x,y)
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 4
2
Basic Concepts
3x3 neighborhood about (x,y)
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 5
Basic concepts
Pixel/point operation:
Neighborhood of size 1x1: g depends only on f at (x,y)
T: a gray-level/intensity transformation/mapping function
Let r = f(x,y) s = g(x,y)
r and s represent gray levels of f and g at (x,y)
Then s = T(r)
Local operations:
g depends on the predefined number of neighbors of f at (x,y)
Implemented by using mask processing or filtering
Masks (filters, windows, kernels, templates) :
a small (e.g. 3×3) 2-D array, in which the values of the
coefficients determine the nature of the process
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 6
3
Common pixel operations
▪ Image negatives
▪ Log transformations
▪ Power-law
transformations
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 7
Image negatives
▪ Reverses the gray level order
▪ For L gray levels the transformation function is
s =T(r) = (L-1)-r
Input image (X-ray image) Output image (negative)
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 8
4
Image negatives
Application: To enhance the visibility for images with more
dark portion
Original digital mammogram Output image
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 9
Image scaling
s =T(r) = a.r (a is a constant)
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 10
10
5
Log transformations
Function of s = c Log(1+r)
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 11
11
Log transformations
Properties of log transformations
– For lower amplitudes of input image the range of gray levels is
expanded
– For higher amplitudes of input image the range of gray levels is
compressed
Application:
– Dynamic range of a processed image far exceeds the capability
of the display device
• (e.g. display of the Fourier spectrum of an image)
– Also called “dynamic-range compression / expansion”
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 12
12
6
Log transformations
Fourier spectrum with values of The result applying log transformation,
range 0 to 1.5 x 106 scaled linearly c=1
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 13
13
Power-law Transformation
Basic form:
s = crg ,
where c & g
are positive
Plots of equation
s = crg,
For various values of g
(c = 1)
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 14
14
7
Power-law Transformation
For γ < 1: Expands values of dark pixels, compress values of
brighter pixels
For γ > 1: Compresses values of dark pixels, expand values of
brighter pixels
If γ=1 & c=1: Identity transformation (s = r)
A variety of devices (image capture, printing, display) respond
according to a power law and need to be corrected;
Gamma (γ) correction
The process used to correct the power-law response phenomena
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 15
15
Power-law Transformation
▪ Example of gamma correction
▪ To linearize the CRT response a pre-distortion circuit is
needed s = cr1/g
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 16
16
8
Gamma correction
Linear Response of
wedge gray CRT to Linear
scale image wedge
Gamma Output of
corrected monitor
wedge
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 17
17
Power-law Transformation: Example
MRI image of Result of applying Result of applying Result of applying
fractured human power-law power-law power-law
spine transformation transformation transformation
c = 1, g = 0.6 c = 1, g = 0.4 c = 1, g = 0.3
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 18
18
9
Power-law Transformation: Example
Original Result of applying
satellite power-law
image transformation
c = 1, g = 3.0
Result of Result of applying
applying power-law
power-law transformation
transformation
c = 1, g = 5.0
c = 1, g = 4.0
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 19
19
Histograms
Histogram of an image with gray level (0 to L-1):
A discrete function h(rk) = nk , where rk is the kth gray level and nk is
the number of pixels in the image having gray level rk .
How a histogram is obtained?
– For B-bit image, initialize 2B counters with 0
– Loop over all pixels x,y
– When encountering gray level f(x,y)=i, increment counter # i
Normalized histogram:
A discrete function p(rk) = nk/n , where n is the total number of
pixels in the image. p(rk) estimates probability of occurrence of
gray-level rk
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 20
20
10
Histogram: application
▪ Distribution of gray-levels can be judged by measuring a histogram
▪ Histogram provides global descriptions of the image (no local
details)
▪ Fewer, larger bins can be used to trade off amplitude resolution
against sample size.
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 21
21
Example Histogram
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 22
22
11
Example Histogram
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 23
23
Histogram Examples
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 24
24
12
Contrast Stretching
Contrast stretching
Goal:
Increase the dynamic range of the gray levels for low contrast
images
Low-contrast images can result from
– poor illumination
– lack of dynamic range in the imaging sensor
– wrong setting of a lens aperture during image acquisition
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 25
25
Contrast stretching through histogram
If rmax and rmin are the maximum and minimum gray level of the input
image and L is the total gray levels of output image
The transformation function for contrast stretching will be
s = T (r ) = (r − rmin )
L
rmax − rmin
rmin rmax
0 L-1
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 26
26
13
Piecewise-linear transformation: contrast stretching
Method
where a1, a2, and a3 control the result of contrast stretching
if a1 = a2 = a3 = 1 no change in gray levels
if a1 = a3 = 0 and r1 = r2, T(*) is a thresholding function,
the result is a binary image
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 27
27
Contrast Stretching Example
Form of
Transformation Original low-
function contrast image
Result of Result of
contrast thresholding
stretching
3/18/2025 Capital University of Science and Technology Digital Image Processing CPE3643 28
28
14