Module 2 - Full
Module 2 - Full
Module 2 - Full
image processing
S5 Minor
Reference Textbook: Digital Image Processing by Rafael C. Gonzalez and Richard E. Woods
Image Enhancement
■ Process an image so that the result will be more suitable than the original
image for a specific application.
Spatial domain techniques are performed to the image plane itself and
they are based on direct manipulation of pixels in an image.
6
Basic Intensity transformation functions
▪ Suitable for enhancing white or gray detail embedded in dark regions of an image,
especially when the black area dominant in size.
0 50 255 205 0
100 75 200
S = L-1-r
0 100 50 255
205 = 255-50
r = F (x, y) 08/02/2022 s = G (x, y) 9
Example of Negative Image
• s = c log(1 + r)
• c is constant
• It maps a narrow range of low intensity values in the input into a
wide range of output levels
• The opposite is true of higher values of input levels
• It expands 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
• Inverse log transformation : Do opposite to the Log
Transformations; Used to expand the values of high pixels in an
image while compressing the darker-level values.
• Example of image with large 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.
=1/2.5 = 0.4
Another example : MRI
(a) a magnetic resonance image of
an upper thoracic human spine
with a fracture dislocation and
spinal cord impingement
■ The picture is predominately dark
■ An expansion of gray levels are
desirable needs < 1
(b) result after power-law
transformation with = 0.6, c=1
(c) transformation with = 0.4
(best result)
(d) transformation with = 0.3
(under acceptable level)
Effect of decreasing gamma
■ When the is reduced too much, the
image begins to reduce contrast to the
point where the image started to have
very slight “wash-out” look, especially in
the background
22
Another example (a)image has a washed-out
appearance, it needs a
compression of gray levels
needs > 1
(b) result after power-law
transformation with = 3.0
(suitable)
(c)transformation with = 4.0
(suitable)
(d) transformation with = 5.0
(high contrast, the image
has areas that are too dark,
some detail is lost)
Piecewise-Linear Transformation Functions
• Contrast Stretching
• Low contrast images can result from
• poor illuminations.
• Lack of dynamic range in the imaging sensor, or even the wrong
setting of a lens aperture during image acquisition.
• It expands the range of intensity levels in an image so that it spans the
full intensity range of display devices.
• Contrast stretching is obtained by setting (r1,s1) = (rmin , 0)
and (r2,s2) = (rmax , L-1)
• Thresholding : A special case of stretching where (r1,
s1)=(m,0) and (r2,s2)=(m, L-1) where m is the mean
intensity of the image
Piecewise-Linear Transformation Functions
Piecewise-Linear Transformation Functions
• Intensity Level Slicing
• Highlighting specific range of intensities in an image.
• Enhances features such as masses of water in satellite imagery and
enhancing flaws in X-ray images.
• It can be Implemented two ways:
• 1) To display only one value (say, white) in the range of interest
and rests are black which produces binary image.
• 2) brightens (or darkens) the desired range of intensities but
leaves all other intensity levels in the image unchanged.
Piecewise-Linear Transformation Functions
• Intensity Level Slicing
Piecewise-Linear Transformation Functions
• Intensity Level Slicing
Piecewise-Linear Transformation Functions
• The reconstruction is done by multiplying the pixels of the nth plane by the constant
2n−1.
• This converts the nth significant binary bit to decimal.
• Each bit plane is multiplied by the corresponding constant, and all resulting planes are
added to obtain the grayscale image.
• To obtain Fig. 3.15(a), we multiplied bit plane 8 by 128, bit plane 7 by 64,
• and added the two planes.
Histogram ….
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.
32
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 th3a4n the others
Histogram Equalization
−1
r = T ( s ), 0 s 1
Transformation Function
nk
pr ( rk ) = where k = 0 , 1, ..., L-1
n
The discrete version of transformation
k
sk = T (rk ) = pr (rj )
j =0
k nj
sk = where k = 0, 1, ..., L-1
j =0 n
Example
No. of pixels
6
2 3 3 2
5
4 2 4 3 4
3 2 3 5 3
2 4 2 4 2
1 Gray level
4x4 image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9]
histogram
Example
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
6 11 15 16 16 16 16 16
k nj
s= 0 0 / / / / / / / /
j =0 n 16 16 16 16 16 16 16 16
No. of pixels
6
3 6 6 3
5
8 3 8 6
4
6 3 6 9 3
3 8 3 8 2
1
Output image
0 1 2 3 4 5 6 7 8 9
Gray scale = [0,9] Gray level
Histogram equalization
Histogram Matching (Specification)
The histogram equalization doesn’t make the result image look better than the
original image.
Consider the histogram of the result image, the net effect of this method is to
map a very narrow interval of dark pixels into the upper end of the gray scale of
the output image.
As a consequence, the output image is light and has a washed-out appearance.
Solve the Problem
Since the problem with the transformation function of the
histogram equalization was caused by a large concentration of
pixels in the original image with levels near 0
A reasonable approach is to modify the histogram of that image
so that it does not have this property
k = 0 ,1,2 ,..., L − 1
(2) the inverse transformation G-1(s)
Result Image and its Histogram
54
Image Subtraction
■ a). original fractal image
■ b). result of setting the four
lower-order bit planes to zero
■ refer to the bit-plane slicing
■
the higher planes contribute
significant detail
■ the lower planes contribute more
to fine detail
■ image b). is nearly identical
visually to image a), with a very
slightly drop in overall contrast
due to less variability of the
gray-level values in the image.
■ c). difference between a). and b).
(nearly black)
■ d). histogram equalization of c).
(perform contrast stretching
transformation)
100
Image Averaging
■ consider a noisy image g(x,y) formed by
the addition of noise (x,y) to an original
image f(x,y)
56
Image Averaging
■ if noise has zero mean and be
uncorrelated then it can be shown that if
g (x, y) =
1
K
g (x, y)
i
i=1
57
Image Averaging
■ then
1 2
2
g ( x, y) = ( x, y)
K
2
g ( x, y) , 2
( x, y) = variances of g and
59
Image Averaging
■ Note: the images gi(x,y) (noisy images)
must be registered (aligned) in order to
avoid the introduction of blurring and
other artifacts in the output image.
60
Example
■ a) original image
■ b)image corrupted by
additive Gaussian noise
with zero mean and a
standard deviation of 64
gray levels.
■ c). -f). results of
averaging K = 8, 16, 64
and 128 noisy images
61
Geometric Operations
⚫ Geometric transformations modify the spatial arrangement of pixels in an
image.
Examples of Geometric
operations
Geometric Operations
❑ Geometric transformations of digital images consist of two basic operations:
1. Spatial transformation of coordinates.
pixels
❑ where (x, y) are pixel coordinates in the original image and (x’,y’) are the corresponding
pixel coordinates of the transformed image.
❑ For example, the transformation (x’ ,y’ ) = (x/2 ,y/2) shrinks the original image to half its
size in both spatial directions
Affine Transformation
An affine transformation maps variables (e.g. pixel intensity values
located at position in an input image) into new variables (e.g. in an
output image) by applying a linear combination of translation, rotation,
scaling operations.
An affine transformation is equivalent to the composed effects of
translation, rotation and scaling, and shearing.
The key characteristic of an affine transformation in 2-D is that it
preserves points, straight lines, and planes
The general affine transformation is commonly expressed as below:
Image interpolation
Interpolation is the process of using known data to estimate
values at unknown locations
Interpolation is a basic tool used for image resizing(shrinking and
zooming)
Three methods of interpolation are
Nearest neighbour interpolation
Bilinear interpolation use the four nearest neighbour to assign
the value
Bicubic interpolation- involves 16 nearest neighbours of a
point
Nearest neighbour interpolation
It assigns to each new location the intensity of its nearest neighbour in the original
image
Most basic method; simple
Requires the least processing time
Only considers one pixel: the closest one to the interpolated point
Has the effect of simply making each pixel bigger
It has the tendency to produce undesirable artifacts, such as severe distortion of
straight edges
Bilinear interpolation
Bilinear interpolation
➢ Considers the closest 2x2 neighborhood of known pixel values surrounding the
unknown pixels
➢ Takes a weighted average of these 4 pixels to arrive at the final interpolated
values
➢ Results in smoother looking images than nearest neighborhood
➢ Needs more processing time
Figure: Case when all known pixel distances are equal. Interpolated value is simply
their sum divided by four.
Bilinear Interpolation
How a 4x4 image would be interpolated to produce an 8x8 image?
f (x + 1, y') = f (x + 1, y + 1) + (1 − ) f (x + 1, y )
one interpolated
Along the y’ column we have
pixel value
f (x' , y') = f (x + 1, y') + (1 − ) f ( x, y' )
Bilinear
interpolation
Bicubic interpolation
➢ One step beyond bilinear by considering the closest 4x4 neighborhood of known
pixels, for a total of 16 pixels
➢ Since these are at various distances from the unknown pixel, closer pixels are
given a higher weighting in the calculation
➢ Produces sharper images than the previous two methods.
➢ Good compromise between processing time and output quality Standard in many
image editing programs, printer drivers and in-camera interpolation
Bicubic interpolation
Interpolation method Principle
NN interpolation output pixel is assigned the value of the
closest pixel
Bilinear interpolation output pixel value is a weighted average of
pixels in the nearest 2-by-2 neighborhood
Bicubic interpolation output pixel value is a weighted average of
pixels in the nearest 4-by-4 neighborhood
Bilinear method takes longer than nearest neighbour interpolation, and the bicubic method
takes longer than bilinear.
The greater the number of pixels considered, the more accurate the computation is, so
there is a trade-off between processing time and quality.
Spatial Filtering
• A predefined operation that is performed between an image f and a filter kernel, w.
• Other terms used to refer to a spatial filter kernel are mask, template, and window
➢ Convolution process is same except that the filter kernel is first rotated
by 180 degree.
➢ When the values of a kernel are symmetric about its center, correlation
and convolution yield the same result
Gaussian
Results of box filter
Results of Gaussian filter
Applications of low pass filter
▪ Using lowpass filtering and thresholding for region extraction
Applications of low pass filter
▪ Shading correction using lowpass filtering
• Consider the 2048 2048 × checkerboard image whose inner squares are of size 128 x 128 pixels.
• Figure (b) is the result of lowpass filtering the image with a 512 x 512 Gaussian kernel (four times
the size of the squares), K = 1, and s = 128 (equal to the size of the squares).
• This kernel is just large enough to blur-out the squares (a kernel three times the size of the
squares is too small to blur them out sufficiently).
Order-Statistic (Nonlinear) Filters
• Response is based on ordering (ranking) the pixels contained in the image
area encompassed by the filter, and then replacing the value of the center
pixel with the value determined by the ranking result.
• The median, ξ, of a set of values is such that half the values in the set are
less than or equal to ξ and half are greater than or equal to ξ.
Order-Statistic (Nonlinear) Filters
• In order to perform median filtering at a point in an image,
• we first sort the values of the pixels in the neighborhood,
• determine their median,
• assign that value to the pixel in the filtered image corresponding to the center of
the neighborhood.
• For example, in a 3 x 3 neighborhood the median is the 5th largest value, in a 5 x 5
neighborhood it is the 13th largest value, and so on.
• The principal function of median filters is to force points to be more like their
neighbors.
• Isolated clusters of pixels that are light or dark with respect to their neighbors, and
whose area one-half the filter area, are forced by an m x m median filter to have the
value of the median intensity of the pixels in the neighborhood
Median Filter (Nonlinear)
Sharpening Spatial Filters
• Objective of sharpening is to highlight transitions in intensity.
f
( x) = f ( x + 1) − f ( x) first-order derivative
x
f
( x − 1) = f ( x) − f ( x − 1)
x
2 f
= f ( x + 1) + f ( x − 1) − 2 f ( x) second-order derivative
x 2
Foundation
Foundation
• At the ramp
• First-order derivative is nonzero along the ramp
• Second-order derivative is zero along the ramp
• Second-order derivative is nonzero only at the onset and
end of the ramp
•At the step
• Both the first- and second-order derivatives are nonzero
• Second-order derivative has a transition from positive to
negative (zero crossing)
•
Foundation
• Edges in digital images often are ramp-like transitions in intensity
• the first derivative of the image would result in thick edges
because the derivative is nonzero along a ramp.
• On the other hand, the second derivative would produce a
double edge one pixel thick, separated by zeros.
Foundation
• From this, we conclude that the second derivative enhances fine
detail much better than the first derivative, a property ideally suited
for sharpening images.
• Also, second derivatives require fewer operations to implement than
first derivatives
• First-order derivatives generally have a stronger response to a gray-
level step.(better for edge detection)
• Second-order derivatives produce a double response at step changes
in gray level. (better for image enhancement)
Use of Second Derivatives for Enhancement
2 f 2 f
f = 2 + 2
2
2-D Laplacian operation
x y
2 f
= f ( x + 1, y ) + f ( x − 1, y ) − 2 f ( x, y ) x-direction
x 2
2 f y-direction
= f ( x, y + 1) + f ( x, y − 1) − 2 f ( x, y )
y 2
2 f ( x, y ) = [ f ( x + 1, y ) + f ( x − 1, y ) + f ( x, y + 1) + f ( x, y − 1)] − 4 f ( x, y )
Use of Second Derivatives for Enhancement
4 neighbors 8 neighbors
negative center coefficient negative center coefficient
Laplacian
kernels
4 neighbors
8 neighbors
positive center coefficient
positive center coefficient
Because the Laplacian is a derivative operator, it highlights sharp intensity transitions in
an image and de-emphasizes regions of slowly varying intensities.
This will tend to produce images that have grayish edge lines and other discontinuities,
all superimposed on a dark, featureless background.
Background features can be “recovered” while still preserving the sharpening effect of
the Laplacian by adding the Laplacian image to the original.
It is important to keep in mind which definition of the Laplacian is used. If the
definition used has a negative center coefficient, then we subtract the Laplacian image
from the original to obtain a sharpened result.
Use of Second Derivatives for Enhancement
• Thus, the basic way in which we use the Laplacian for image sharpening is
• where f(x,y) and g(x,y) are the input and sharpened images, respectively. We let
positive
Laplacian image
Enhanced image
(original-Laplacian)
Unsharp Masking and Highboost Filtering
Subtracting an unsharp (smoothed) version of an image from the original image is
process that has been used since the 1930s by the printing and publishing industry to
sharpen images. This process, called unsharp masking, consists of the following steps:
1. Blur the original image.
2. Subtract the blurred image from the original (the resulting difference is called
the mask.)
3. Add the mask to the original
g ( x, y ) = f ( x, y ) + k g mask ( x, y )
• When k=1, unsharp masking
• When k > 1, highboost filtering
Unsharp Masking and Highboost Filtering
Unsharp Masking and Highboost Filtering
Using First-Order Derivatives for Image Sharpening
g x x
f
f grad( f ) g = f gradient of f at (x,y)
y y
M ( x, y ) = mag(f ) = [ g x2 + g 2y ]1/ 2
2 1/ 2
f f
2
magnitude of gradient
= +
x y
M ( x, y ) g x + g y Approximation of magnitude
of gradient by absolute values
Using First-Order Derivatives for Image Sharpening
3x3 region
Roberts cross-gradient
operators
Sobel operators
Example
-2 0 2
-1 0 1
1 2 5 2
Gx 24
2 1 6 9
24.18 = 32 + 242
3 3 4 9
1 0 1 8
-1 -2 -1
0 0 0
1 2 1 -1*1 +2*-2 +5*-1 +….. +3*2 +4*1 =3
Gy
106
Use of First Derivatives for Enhancement
109
Example of Combining Spatial Enhancement
Methods
solve :
110
111
112
Frequency domain image enhancement
Any spatial or temporal signal has an equivalent frequency representation
High frequencies correspond to pixel values that change rapidly across the image
(e.g. text, texture, leaves, etc.)
Strong low frequency components correspond to large scale features in the image
(e.g. a single, homogenous object that dominates the image)
Discrete Fourier transform is the most important transform employed in image processing
applications
Discrete Fourier transform is generated by sampling the basis functions of the continuous
transform, i.e., the sine and cosine functions
Discrete Fourier transform
The Fourier transform decomposes a complex signal into a weighted sum
of sinusoids, starting from zero frequency to a high value determined by
the input function
08/02/2022 124
• A severe ringing effect is seen in
blurred images, which is a
characteristic of ideal filters.
• It is due to the discontinuity in
the filter transfer function
2/8/2022 130
Gaussian filters
2/8/2022 132
Image sharpening using frequency domain
filters(High pass filter)
Sharpening Fourier Domain Filters
2/8/2022 134
Sharpening Spatial Domain Representations
2/8/2022 135
Sharpening Fourier Domain Filters (Examples)
2/8/2022 136
Sharpening Fourier Domain Filters (Examples)
2/8/2022 137
Sharpening Fourier Domain Filters (Examples)
2/8/2022 138