Lab3
Lab3
Lab 03
Objective:
Changing gray levels and spatial resolution and Intensity Transformations
Student Information
Student Name
Student ID
Date
Assessment
Marks Obtained
Remarks
Signature
Page 1 of 8
UIT University
Department of Computer Science
CSC321 – Digital Image Processing
Lab 03
Instructions
Come to the lab in time. Students who are late more than 15 minutes, will not be allowed to attend the lab.
Students have to perform the examples and exercises by themselves.
Raise your hand if you face any difficulty in understanding and solving the examples or exercises.
Lab work must be submitted on or before the submission date.
Lab Objectives
The objective of this lab is to understand and work with:
1. The effect of changing the gradient of gray levels in the input image.
2. The effect of changing spatial resolution in the input image using
a) Nearest neighbor interpolation b) Bilinear interpolation
3. Image enhancement in spatial domain using the following gray level transformation function
o Linear Transformation
• Image Negation function
• Identity function o Logarithmic Transformation o Power
Law Transformation
Page 3 of 8
Figure 2 Reducing the Spatial Resolution
Image enhancement is a very basic image processing task that defines us to have a better subjective
judgment over the images. And Image Enhancement in spatial domain (that is, performing operations
directly on pixel values) is the very simplistic approach. Enhanced images provide better contrast of the
details that images contain. Image enhancement is applied in every field where images are ought to be
understood and analyzed. For example, Medical Image Analysis, Analysis of images from satellites, etc.
Image enhancement simply means, transforming an image f into image g using T. Where T is the
transformation. The values of pixels in images f and g are denoted by r and s, respectively. As said, the
pixel values r and s are related by the expression,
s = T(r)
where T is a transformation that maps a pixel value r into a pixel value s. The results of this
transformation are mapped into the grey scale range as we are dealing here only with grey scale digital
images. So, the results are mapped back into the range [0, L-1], where L=2 k, k being the number of bits
in the image being considered. So, for instance, for an 8-bit image the range of pixel values will be [0,
255].
There are three basic types of functions (transformations) that are used frequently in image
enhancement. They are,
• Linear,
• Logarithmic,
• Power-Law.
Page 4 of 8
The transformation map plot shown below depicts various curves that fall into the above three types of
enhancement techniques.
The Identity and Negative curves fall under the category of linear functions. Identity curve simply
indicates that input image is equal to the output image. The Log and Inverse-Log curves fall under the
category of Logarithmic functions and nth root and nth power transformations fall under the category of
Power-Law functions.
Image Negation
The negative of an image with grey levels in the range [0, L-1] is obtained by the negative
transformation shown in figure above, which is given by the expression,
s = L - 1 - r
This expression results in reversing of the grey level intensities of the image thereby producing a
negative like image. The output of this function can be directly mapped into the grey scale lookup table
consisting values from 0 to L-1.
Log Transformations
The log transformation curve shown in fig. 3, is given by the expression,
s = c log(1 + r)
where c is a constant and it is assumed that r≥0. The shape of the log curve in fig. A tells that this
transformation maps a narrow range of low-level grey scale intensities into a wider range of output
values. And similarly maps the wide range of high-level grey scale intensities into a narrow range of
high level output values. The opposite of this applies for inverse-log transform. This transform is used to
expand values of dark pixels and compress values of bright pixels.
Page 5 of 8
Power-Law Transformations
The nth power and nth root curves shown in fig. 3 can be given by the expression,
s = crγ
This transformation function is also called as gamma correction. For various values of γ different levels
of enhancements can be obtained. This technique is quite commonly called as Gamma Correction. If you
notice, different display monitors display images at different intensities and clarity. That means, every
monitor has built-in gamma correction in it with certain gamma ranges and so a good monitor
automatically corrects all the images displayed on it for the best contrast to give user the best experience.
The difference between the log-transformation function and the power-law functions is that using
the power-law function a family of possible transformation curves can be obtained just by varying
the λ.
These are the three basic image enhancement functions for grey scale images that can be applied easily
for any type of image for better contrast and highlighting. Using the image negation formula
given above, it is not necessary for the results to be mapped into the grey scale range [0,L-1]. Output of
L-1-r automatically falls in the range of [0, L-1]. But for the Log and Power-Law transformations
resulting values are often quite distinctive, depending upon control parameters like λ and logarithmic
scales. So the results of these values should be mapped back to the grey scale range to get a meaningful
output image. For example, Log function s = c log(1 + r) results in 0 and 2.41 for r varying between 0
and 255, keeping c=1. So, the range [0, 2.41] should be mapped to [0, L-1] for getting a meaningful
image.
OUTPUT
Enter the value for c==>1 Enter the value for gamma==>.2 % for gamma value less than 1 u gets Bright
image
Page 6 of 8
Original Image Result after Applying Power Law
Transformation
Enter the value for c==>1 Enter the value for gamma==>5 % for gamma value GREATER THAN 1 u
gets dark image
Student Exercise:
Task 1: Using the data provided in the lab perform the following:
Task 2
Zooming and Shrinking Images by Nearest Neighbor
Write a computer program capable of zooming and shrinking an image by nearest neighbor algorithm.
Assume that the desired zoom/shrink factors are integers. You may ignore aliasing effects.
Page 7 of 8
Task 3
Zooming and Shrinking Images by Bilinear Interpolation
Write a computer program capable of zooming and shrinking an image by bilinear interpolation. The
input to your program is the desired size of the resulting image in the horizontal and vertical direction.
You may ignore aliasing effects.
Task 4
Implement the following transformation on your selected image and comment your observation:
• Negation transform.
• Logarithmic transform.
• Power transform.
Page 8 of 8