Image Enhancement in Spatial Domain
Pixel Operations and Histogram Processing
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
Some techniques are based on various combinations of methods from
these two categories
Image Enhancement
• No general theory
• Viewer is ultimate judge
• Highly subjective process
• Easier in machine perception
Types of image enhancement operations - Pixel point processing
Pixel point processing is a form of image enhancement based only on
the intensity of single pixels. No consideration what-so-ever is taken
of neighbouring pixels, or the spatial arrangement of groups of pixels,
or of the position of the pixel within the digital image.
Pixel point processing is a simple but important type of image
enhancement technique. All pixels are processed individually.
Pixel Point Processing
The general equation for a point process is given by:
g(x,y) = M[f(x,y)]
Where g(x,y) is the output digital image, f(x,y) is the input digital
image, and M is the mapping function.
M maps or converts input pixel brightness to an output pixel
brightness.
The mapping function can be non-linear.
Types of image enhancement operations
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
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)
Basic Concepts
3x3 neighborhood about (x,y)
Basic concepts
g(x,y) = T [f(x,y)]
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
Common pixel operations
• Image negatives
• Log
transformations
• Power-law
transformations
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)
Application: To enhance the visibility for images with more dark portion
Contrast Scaling
s =T(r) = a.r (a is a constant)
Log transformations
Function of s = c Log(1+r)
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:
– This transformation is suitable for the case when the 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”
Log transformations
Fourier spectrum with values of The result applying log transformation,
range 0 to 1.5 x 106 scaled linearly c=1
Power-law Transformation
Basic form:
s = crg ,
where c & g
are positive
Plots of equation
s = crg,
For various values of g
(c = 1)
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
Power-law Transformation
• Example of gamma correction
• To linearize the CRT response a pre-distortion circuit is needed
s = cr1/g
Gamma correction
Linear wedge Response of CRT
gray scale to Linear wedge
image
Gamma Output of
corrected monitor
wedge
Power-law Transformation: Example
MRI image of Result of Result of Result of
fractured human applying power- applying power- applying power-
spine law law law
transformation transformation transformation
c = 1, g = 0.6 c = 1, g = 0.4 c = 1, g = 0.3
Power-law Transformation: Example
Original Result of
satellite applying power-
image law
transformation
c = 1, g = 3.0
Result of
applying Result of
power-law applying power-
transformation law
c = 1, g = 4.0 transformation
c = 1, g = 5.0
Piecewise-linear transformation
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
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
Contrast Stretching Example
Form of
Transformation Original low-
function contrast image
Result of Result of
contrast thresholding
stretching
Pixel Point Processing
Non-linear contrast stretching is implemented using look-up tables, not
formulas.
The Histogram
The histogram concisely displays the brightness distribution of an image,i.e. the
number of pixels with a certain brightness. The histogram shows the likelihood
of finding a pixel with a certain grey level.
The Histogram
The Histogram
The histogram
contains no
information about
the spatial
distribution of the
pixels within the
image.
The Histogram
Low contrast
image.
High contrast
image.
The Histogram
Well balanced
contrast image.
A well balanced contrast image will make optimum use of the available
brightness dynamic range.
The total sum of all pixels in the histogram equals the number of pixels
in the digital image.
The Histogram
The average brightness of a digital image of size x_pix and y_pix and
steps grey levels (e.g. steps = 256) is:
temp = 0;
for(grey = 0; grey < steps; grey++) {
temp = temp + (grey * histo(grey));
}
average = temp / (x_pix * y_pix);
The Histogram
The maximum brightness grey level of a digital image of steps grey
levels (e.g. steps = 256) is:
for(grey = steps - 1; grey >= 0; grey--) { if(histo(grey) > 0) break; }
max_grey = grey;
The most common grey level is:
num = 0;
for(grey = 0; grey < steps; grey++) {
if (histo(grey) > num) {
num = histo(grey);
common = grey;
}
}
Pixel Point Processing
Histogram sliding adds or
subtracts a constant offset
brightness to each pixel
intensity. Example:
Pixel Point Processing
The resultant image has the same contrast as before. The pixel
brightness range has simply been relocated within the available grey
level dynamic range.
Pixel Point Processing
Histogram stretching multiplies each
pixel brightness with a constant gain
factor. This increases (decreases) contrast
for gain factors greater than one (< 1).
Example:
I(x,y) > 65, O(x,y) = 255
0 < I(x,y) <= 65, O(x,y) = 3.9 * I(x,y)
If I(x,y) = 0 then O(x,y) = 0
If I(x,y) = 65 then O(x,y) = 3.9*65 =
253.5
Non-integer pixel values must be rounded
to the nearest integer.
Pixel Point Processing
The resultant digital image fully utilises the available grey level
dynamic range. The image has good contrast revealing important
detail. The image is pleasing to the human eye.
Pixel Point Processing
Linear contrast stretching is a
combination of histogram sliding and
stretching.
Assume the darkest and brightness input
image grey values are rmin and rmax and the
desired darkest and brightest output
grey levels are 0 and L then the formula
for a linear contrast stretch is:
L
s T (r ) r rmin
rmax rmin
Usually, contrast stretching is done to
occupy the maximum available grey level
dynamic range (e.g. min=0, max=255)
Pixel Point Processing
rmin rmax
0 L-1
Pixel Point Processing
Binary contrast enhancement, or
thresholding, is an extreme
example of contrast stretching. All
grey levels below (above) a selected
threshold are set to black (white).
This is commonly used to refresh
old, faded or (water) damaged
documents.
Pixel Point Processing
In adaptive thresholding, the threshold
value varies across the image. This is not
strictly pixel point processing.
Pixel Point Processing
Brightness slicing does a double binary
contrast enhancement. This is used to
highlight features within a chosen
grey level range, e.g. enhanced sea-
land boundary.
Pixel Point Processing
Histogram equalisation
rearranges the pixel grey
levels in order to achieve an
equal density distribution.
This rearrangement process is
different for every digital
image.
This can enhance detail. The
full grey level dynamic range is
exploited.
Pixel Point Processing
Histogram equalisation can reveal detail otherwise invisible.
Histogram equalization
• Idea: To find a non-linear transformation
Y = T (x )
to be applied to each pixel of the input image f(x,y), such that a uniform
distribution of gray levels in the entire range results for the output image
g(x,y).
0 r 1 and 0 s 1
• Assuming ideal, continuous case, with normalized histograms
– T(x) is single valued i.e., there exists x= T-1(y)
– T(x) is monotonically increasing
• Monotonic functions are functions that tend to move in only one direction as
x increases
Histogram equalization
A function T(x) is monotonically increasing
if T(r1) < T(r2) for r1 < r2,
and monotonically decreasing
if T(r1) > T(r2) for r1 < r2.
Example of a transformation function which
is both single valued and monotonically
increasing
Implementation
• Consider a grayscale image, and let ni be the number of
occurrences of gray level i. The probability of an occurrence of
a pixel of level i in the image is
• L being the total number of gray levels in the image, n being the
total number of pixels in the image, and p being the image's
histogram, normalized to 0..1.
Histogram equalization
Implementation
• Let us also define c as the cumulative distribution function
corresponding to p, defined by:
• c is the image's accumulated normalized histogram.
Implementation
• We would like to create a transformation of the form that will produce
a level y for each level x in the original image, such that the cumulative
probability function of y will be linearized across the value range. The
transformation is defined by:
• Notice that the T maps the levels into the domain of 0..1. In order to
map the values back into their original domain, the following simple
transformation needs to be applied on the result:
Histogram equalization
Histogram equalization examples
Input image Output image
Input histogram and cdf Output histogram and cdf
Histogram equalization examples
Low contrast image Output image
Equalized histogram
Equalized histogram
high contrast image Output image
Histogram equalization examples
Dark input image Output image
Equalized histogram
Bright input image Output image Equalized histogram
Histogram equalization examples
Transformation functions for histogram
equalization
Histogram equalization examples
Histogram equalization examples