Module - 2notes - Part1 DIP
Module - 2notes - Part1 DIP
Module - 2notes - Part1 DIP
18CS741
[As per Choice Based Credit System (CBCS) scheme]
(Effective from the academic year 2018 -2019)
SEMESTER – VII
MODULE 2
Notes
Prepared By
Athmaranjan K
Associate Professor
Dept. of Information Science & Eng.
Srinivas Institute of Technology, Mangaluru
MODULE 2
SYLLABUS
Image Enhancement In The Spatial Domain: Some Basic Gray Level Transformations, Histogram
Processing, Enhancement Using Arithmetic/Logic Operations, Basics of Spatial Filtering, Smoothing Spatial
Filters, Sharpening Spatial Filters, Combining Spatial Enhancement Methods.
Textbook 1: Ch.3
Textbook 1: Rafael C G., Woods R E. and Eddins S L, Digital Image Processing, Prentice Hall, 2nd edition,
2008
Where f(x, y) is an input image and g(x, y) is the output image and the term T is known as the operator. T can
be applied to the set of image or a single image.
Basic Implementation of this Equation on a single image is shown in below Figure:
Operator T is applied on a single image.
(x, y) is the arbitrary location in an image and the region next to this pixel is known as neighbourhood
of this pixel (x, y).
Spatial domain process consist of moving the origin of neighbourhood from pixel to pixel and
applying the operator T on to the pixels in the neighbourhood that will yielding the output of the
location.
The simplest form of T is when the neighbourhood is of size 1 x 1 (that is, a single pixel). In this case, g
depends only on the value of f at (x, y), and T becomes a gray-level (also called an intensity or mapping)
transformation function of the form:
Where s is the output image pixel value and r is the input image pixel value.
What is gray level or Intensity level Transformation function. Explain the gray level transformation
function for contrast enhancement.
Spatial domain processes will be denoted by the expression:
Where f(x, y) is an input image and g(x, y) is the output image and the term T is known as the operator which
is applied on image pixel. The simplest form of T is when the neighbourhood is of size 1 x 1 (that is, a single
pixel). In this case, g depends only on the value of f at (x, y), and T becomes a gray-level (also called an
intensity or mapping) transformation function of the form:
Where s is the output image pixel value and r is the input image pixel value
Where s is the output image pixel value (after processing) and r is the input image pixel value (before
processing) and T is the Transformation function which maps value of r to s using look up table.
Frequently used 3-Basic types of gray level Transformation Functions for Image Enhancement:
1. Linear Transformation Function: It consists of Image Negative and Image Identity.
2. Logarithmic Transformation Function: It consists of Log functions and Inverse log functions
b) Image Negative: Here also intensity value represented in the range [0, L-1]. Image negative can be
represented by the function:
s=L–1–r
In image negative the intensity value are the pixel value will be reversed to produce an equivalent
photographic negative image. To produce photographic negative we will use Image negative
transformation. It is as shown in below figure:
Use: Particularly suited for enhancing white or gray detail embedded in dark regions of an image, especially
when the black areas are dominant in size. It is very much easier to analyse the negative image.
2. Logarithmic Transformation Function:
Transformation function can be represented as: s = c log (1 + r) where c is a constant scaling factor and r ≥ 0
• By using this transformation we can compress the gray level or expand the gray level.
ATHMARANJAN K DEPT OF ISE, SRINIVAS INSTITUTE OF TECHNOLOGY MANGALURU Page 6
DIGITAL IMAGE PROCESSING 18CS741 Module 2
• At the output of image we get high contrast or low contrast image depending upon the function which
we perform.
• The shape of the log curve is as shown below
Transformation maps a low input intensity level into larger output intensity. The opposite is true of higher
values of input levels. We would use a transformation of this type to expand the values of dark pixels in an
image while compressing the higher-level values. The opposite is true of the inverse log transformation.
3. Power-Law Transformations
It consists of nth root and nth power functions. It can be represented as :
Here when Gama value > 1 power law will act as nth power and < 1 it will act as nth root. It is also known as
gamma corrections.
Plots of s versus r for various values of gamma are shown below:
As in the case of the log transformation, power-law curves with fractional values of gamma map a narrow
range of dark input values into a wider range of output values, with the opposite being true for higher values
of input levels. Curves generated with values of gamma >1 have exactly the opposite effect as those
generated with values of gamma < 1. When gamma = 1curve reduces to identity transformation.
PIECEWISE-LINEAR TRANSFORMATION FUNCTIONS
A complementary approach to the methods which we discussed so far is to use piecewise linear functions.
The principal advantage of piecewise linear functions over the basic types of functions which we have
discussed thus far is that the form of piecewise functions can be arbitrarily complex. The principal
disadvantage of piecewise functions is that their specification requires considerably more user input.
*****Explain the following transformations
The 3 piecewise-linear transformation functions are:
1. Contrast Stretching
2. Gray Level or Intensity level slicing
3. Bit plane slicing
CONTRAST STRETCHING
Contrast: is the difference between the highest gray level and lowest gray level of an image. Low-contrast
images can result from :
Above figure shows a typical transformation used for contrast stretching. The locations of points (r1, s1) and
(r2, s2) control the shape of the transformation function.
If r1= s1 and r2 = s2, the transformation is a linear function that produces no changes in gray levels.
If r1= r2, s1 = 0and s2 = L-1, the transformation Becomes a thresholding function that creates a
binary image, as illustrated in below figure
:
The second approach brightens the desired range of gray levels but preserves the background and gray-level
tonalities in the image. This transformation, shown below:
Use: Its application includes enhancing features such as masses of water in satellite imagery and enhancing
flaws in X-ray images
BIT-PLANE SLICING:
Instead of highlighting gray-level ranges, highlighting the contribution made to total image appearance by
specific bits might be desired. Suppose that each pixel in an image is represented by 8 bits. Imagine that the
image is composed of eight 1-bit planes, ranging from bit-plane 0 for the least significant bit to bit plane 7 for
Use: It is useful for analyzing the relative importance played by each bit of the image, a process that aids in
determining the adequacy of the number of bits used to quantize each pixel.
USE OF HISTOGRAM STATISTICS FOR IMAGE ENHANCEMENT
*********Define histogram and normalized histogram.
Histogram:
Histogram of an image is the graphical representation of frequency of pixels intensity (gray) values. In an
image histogram, the X axis is the gray level intensities and the Y axis is the frequency of these intensities.
The histogram of a digital image with gray levels in the range [0, L-1] is a discrete function of the form
H(rk) = nk
Where rk is the kth gray level and nk is the number of pixels in the image having the gray level rk.
Normalize Histogram:
A normalized histogram is given by the equation
P(rk) = nk / n for k = 0,1,2,…..,L-1
P(rk) gives the estimate of the probability of occurrence of gray level rk. The sum of all components of a
normalized histogram is equal to 1.
The histogram plots are simple plots of H(rk) = nk versus rk.
HISTOGRAM EQUALIZATION
Discuss histogram equalization for contrast enhancement in digital image processing
Histogram equalization is a common technique for enhancing the appearance of images. Suppose we have an
image which is predominantly dark. Then its histogram would be skewed towards the lower end of the gray
scale and all the image detail are compressed into the dark end of the histogram. If we could stretch out the
gray levels at the dark end to produce a more uniformly distributed histogram then the image would become
much clearer.
• Histogram equalization automatically determines a transformation function that seeks to produce an
output image that has a uniform histogram..
• Histogram equalization method is simple image enhancement method which is applied on entire
image.
Thus, the PDF of the transformed variable s is the determined by the gray levels PDF of the input image and
by the chosen transformations function. The cumulative distribution function of r is given by
Where n is the total number of pixels in the image, nk is the number of pixels that have gray level rk, and L is
the total number of possible gray levels in the image.
The discrete form of transformation function s = T(r) is given by:
Thus, a processed (output) image is obtained by mapping each pixel with level rk in the input image into a
corresponding pixel with level sk in the output image. The transformation T(rk) is known as histogram
equalization.
HISTOGRAM MATCHING (SPECIFICATION)
In some image enhancement application we wish to apply for a specific region of an image, then Histogram
matching method is used. The goal of histogram matching is to take an input image and generate an output
image that is based upon the shape of a specific (or reference) histogram. Histogram matching is also known
as histogram specification.
*****What is histogram matching or specification? Explain
Histogram matching is the process of generating an output image for an input image based upon the shape of
a specific or reference histogram.
• Obtain the histogram for both the input image and the specified image (same method as in histogram
equalization).
• Obtain the cumulative distribution function CDF for both the input image and the specified image
(same method as in histogram equalization).
• Calculate the transformation T to map the old intensity values to new intensity values for both the
input image and specified image (same method as in histogram equalization).
NOTE: For the above problem we have to consider the given maximum gray level value as 7 (that is 0 to 7
in 3 bit). Here n is sum of all pixels = 4096
Histogram of input image Histogram Equalized image
[plot of rk vs P(rk) = rk/n] [plot of sk vs P(sk) = sk/n]
Answer:
Step1: Find the histogram equalized gray level values for the input (Original) image
Gray Levels (rk) No. of Pixels PDF p(rk) = nk / n CDF Transformed Equalized Gray
(input) (nk) Gray levels level value (sk)
sk = CDF x max. (output)
gray value (7)
NOTE:
In first row when the input gray level value is 0 which is equalized to gray value 1 and in equalized Gray
level target image we don’t have the gray value 1; so it is mapped to next higher gray level value which is
equal to 2; therefore the input gray level value corresponding to this gray value 2 is 4 is considered as the
final mapped value for input 0
noisy images that are obtained from a given input image. Here the assumption is that at every pair of
coordinates (x, y) the noise is uncorrelated and has zero average value.
An important application of image averaging is in the field of astronomy, where imaging with very low light
levels is routine, causing sensor noise frequently to render single images virtually useless for analysis.
Subtraction:
One of the main applications of image subtraction is:
In the area of medical imaging called mask mode radiography: In this case h(x, y), the mask, is an X-ray
image of a region of a patient’s body captured by an intensified TV camera located opposite an X-ray source.
The procedure consists of injecting a contrast medium into the patient’s bloodstream, taking a series of
images of the same anatomical region as h(x, y), and subtracting this mask from the series of incoming
images after injection of the contrast medium. The net effect of subtracting the mask from each sample in the
incoming stream of TV images is that the areas that are different between f(x, y) and h(x, y) appear in the
output image as enhanced detail.
Multiplication and Division operations are used:
1. In shading correction
2. Masking or Region of interest operations.
Logic operations such as AND, OR and NOT similarly operate on a pixel-by-pixel basis.
Performing the NOT operation on a black, 8-bit pixel (a string of eight 0’s) produces a white pixel
The AND and OR operations are used for masking; that is, for selecting sub-images in an image.
w(0, 0) coincides with image value f(x, y), indicating that the mask is centred at (x, y) when the computation
of the sum of products takes place.
For a mask of size m x n, we assume that m = 2a + 1 and n = 2b + 1, where a and b are nonnegative integers.
The size of mask must be odd (i.e. 3×3, 5×5, etc.) to ensure it has a center. The smallest meaningful size is
3×3.
where the w’s are mask coefficients, the z’s are the values of the image gray levels corresponding to those
coefficients, and mn is the total number of coefficients in the mask.
For example the mask size of 3 x 3 the response at any point (x, y) in the image is given by:
Noise reduction can be achieved effectively with a nonlinear filter whose basic function is to compute the
median gray-level value in the neighbourhood in which the filter is located.
which is the average of the gray levels of the pixels in the 3 x 3 neighbourhood defined by the mask.
The idea here is that it is computationally more efficient to have coefficients valued 1. At the end of the
filtering process the entire image is divided by 9. An m x n mask would have a normalizing constant equal to
1/mn.
WEIGHTED AVERAGE FILTER:
Pixels are multiplied by different coefficients, thus giving more importance (weight) to some pixels at
the expense of others.
The pixel at the centre of the mask is multiplied by a higher value than any other, thus giving this
pixel more importance in the calculation of the average.
The other pixels are inversely weighted as a function of their distance from the centre of the mask.
The diagonal terms are further away from the centre than the orthogonal neighbours (by a factor of
square root of 2) and, thus, are weighed less than these immediate neighbours of the centre pixel.
ORDER-STATISTICS FILTERS
Order-statistics filters are nonlinear spatial filters whose 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.
For Median filter: write pixels of mask in ascending order and find the median, which is equal to 5
0, 1, 2, 4, 5, 6, 7, 8, 9 = 5
For 3 x 3 Neighbourhood:
Min filter the minimum value = 0
Max filter Maximum value = 9
***Give example for order statistics or Non-linear filters in spatial domain
X-ray image of a circuit board heavily corrupted by salt-and-pepper noise. Median filtering is much better
suited for the removal of additive salt-and-pepper noise.
SHARPENING SPATIAL FILTERS
The principal objective of sharpening is to highlight fine detail in an image or to enhance detail that has been
blurred, either in error or as a natural effect of a particular method of image acquisition. We saw that image
blurring could be accomplished in the spatial domain by pixel averaging in a neighbourhood. Since averaging
is analogous to integration, it is logical to conclude that sharpening could be accomplished by spatial
differentiation.
Applications of Image sharpening: ranging from electronic printing and medical imaging to industrial
inspection and autonomous guidance in military systems
BASIC FOUNDATION
Explain the fundamental properties of First and second order derivatives in a digital image processing
Image sharpening filters are based on first- and second-order derivatives respectively. The derivatives of a
digital function are defined in terms of differences.
ATHMARANJAN K DEPT OF ISE, SRINIVAS INSTITUTE OF TECHNOLOGY MANGALURU Page 25
DIGITAL IMAGE PROCESSING 18CS741 Module 2
Definition for first derivatives:
Must be zero in flat segments (areas of constant gray-level values)
Must be nonzero at the onset of a gray-level step or ramp;
Must be nonzero along ramps.
Definition for second derivatives:
Must be zero in flat areas;
Must be nonzero at the onset and end of a gray-level step or ramp;
Must be zero along ramps of constant slope
A basic definition of the first-order derivative of a one-dimensional function f(x) is the difference:
Example: A simple image with its 1-D gray level profile along the centre of the image including isolated
noise point is shown below:
• First, we note that the first-order derivative is nonzero along the entire ramp, while the second-order
derivative is nonzero only at the onset and end of the ramp.
• We conclude that first-order derivatives produce thicker edges and second-order derivatives
derivatives have a stronger response to fine detail, such as thin lines and isolated points.
• Hence a second-order derivative to enhance fine detail (including noise) much more than a first-order
derivative.
• First order derivatives generally have a stronger response to a gray-level step. Second- order
derivatives produce a double response at step changes in gray level.
USE OF SECOND DERIVATIVES FOR ENHANCEMENT–THE LAPLACIAN
*********Explain the Laplacian second derivatives for spatial enhancement
Laplacian filter, which is defined with respect to x & y coordinates; for a function (image) f(x, y) of two
variables, is defined as:
Using this equation we can design Laplacian filter. This equation can be implemented using the mask as
shown below:
OR
The above basic laplacian filter can be modified by subtracting the laplacian filtered image from the original
image f (x, y) in order to obtain a sharpened result.
Application: its use highlights gray-level discontinuities in an image and deemphasizes regions with slowly
varying gray levels. This will tend to produce images that have grayish edge lines and other discontinuities,
all superimposed on a dark, featureless background
To approximate the magnitude of the gradient by using absolute values instead of squares and square roots
We use
Gradient of an image measures the change in image function f(x, y) in X and Y directions.
A 3 x 3 region of an image (the z’s are gray-level values) and masks used to compute the gradient at point
labeled z5 is shown below:
Gx =
Gy =
Sobel operator
All the mask co-efficient in Robert and Sobel operator sum to zero, as expected for derivative operator. As
the center value of sobel operator is zero, it does not include original value of image but it calculates the
difference of right and left pixel values ( or top & bottom values)
2 What is gray level or Intensity level Transformation function. Explain the gray level 8
transformation function for contrast enhancement
3 Explain the following gray level transformation functions with a neat graph: i) Linear 8
1. Contrast Stretching
2. Gray Level or Intensity level slicing
3. Bit plane slicing
5 Define histogram and normalized histogram, discuss histogram equalization for contrast 8
enhancement
6 What is histogram matching or specification? Explain 6
14 Describe how the first order derivatives are used for Image sharpening 10