Image Processing Lab Manual 2017
Image Processing Lab Manual 2017
Image Processing Lab Manual 2017
a) Image Processing:
Introduction: Fundamental Steps in Image Processing, Elements of Image Processing Systems.
Relationships between Pixels – Neighbours, Connectivity, Distance Measures, Arithmetic & Logic
Operations.
Two Dimensional Orthogonal Transforms - DFT, FFT, WHT, Haar transform, KLT, DCT.
Image Restoration - Degradation Model, Discrete Formulation, Circulant and Block Circulant Matrices,
Restoration using Inverse Filtering, Removal of blur caused by uniform linear motion, LMS Wiener
Filter.
Image Compression – Lossless and Lossy Coding, Transform Coding, JPEG, MPEG.
Edge detection – Detection of point, line, discontinuities. Gradient Operators, Laplacian, LoG Filters,
Global Processing via Hough Transform.
Mathematical morphology - Binary Morphology, Dilation, Erosion, Opening and Closing, Duality
Relations, Gray Scale Morphology, Hit-and-Miss Transform, Thinning and Shape Decomposition.
Computer Tomography - Radon transform, Back-Projection Operator, Fourier-slice theorem, CBP and
FBP methods.
Textbooks / References
1. Digital Image Processing by Rafael C. Gonzalez and Richard E. Woods, Pearson, 2009
2. Fundamentals of Digital Image Processing by Anil K. Jain, Prentice Hall of India, 1989.
3. Digital image processing by W. K. Pratt, Prentice Hall, 1989.
4. Sonka, Hlavac, Boyle, Image Processing, Analysis and Machine Vision, Thomson, 2001
Table of Contents
Experiment No. 1
Aim: Write a program to perform basic arithmetic and logical operations on images.
Theory :
Image arithmetic applies one of the standard arithmetic operations or a logical operator to two
or more images. The operators are applied in a pixel-by-pixel way, i.e. the value of a pixel in the
output image depends only on the values of the corresponding pixels in the input images.
Hence, the images must be of the same size. Although image arithmetic is the most simple form
of image processing, there is a wide range of applications. A main advantage of arithmetic
operators is that the process is very simple and therefore fast.
Logical operators are often used to combine two (mostly binary) images. In the case of integer
images, the logical operator is normally applied in a bitwise way.
Various arithmetic such as subtraction and averaging as well as logic operations such as Not,
And, and OR are performed on images.
1. Image Addition:
Adding two images: H(x,y) = I(x,y) + J(x,y)
Applications Brightening an image, Image Compositing, (Additive) Dissolves
2. Image Subtraction:
Subtracting two images: H(x,y) = I(x,y) - J(x,y)
Applications
Motion Detection, Frame Differencing for Object Detection, Digital Subtraction
Angiography
3. Image Multiplication:
Multiplying two images: H(x,y) = I(x,y) × J(x,y)
Applications:
Masking image parts
4. Image Division:
Dividing two images: H(x,y) = I(x,y) / J(x,y)
Applications:
Masking image parts
B. Logical operations on images:
1. And:
H(x,y) = I(x,y) AND J(x,y)
2. Or:
H(x,y) = I(x,y) OR J(x,y)
3. Not:
H(x,y) = NOT( I(x,y))
Algorithm:
Program:
To be performed by students.
Expected Output:
Conclusion:
a) Negative transformation
b) Log transformation
c) Power law transformation
d) Contrast stretching
Theory :
Enhancing an image provides better contrast and a more detailed image as compared to non
enhanced image. Image enhancement has many applications. It is used to enhance medical
images, images captured in remote sensing, images from satellite etc. The transformation
function has been given below
s=T(r)
where r is the pixels of the input image and s is the pixels of the output image. T is a
transformation function that maps each value of r to each value of s. Image enhancement can
be done through gray level transformations
2. Logarithmic
3. Power – law
The overall graph of these transitions has been shown below:
1. Identity transformation:
Identity transition is shown by a straight line. In this transition, each value of the input image is
directly mapped to each other value of output image. That results in the same input image and
output image.
2. Negative transformation:
This is invert of identity transformation. In negative transformation, each value of the input
image is subtracted from the L-1 and mapped onto the output image. The result is somewhat
like this.
(a) (b)
Figure: Negative Transformation: a) Input Image b)Output images
3. Logarithmic transformations:
Logarithmic transformation further contains two type of transformation. Log transformation
and inverse log transformation.
Log transformation:
The log transformations can be defined by this formula
s = c log(r + 1).
Where s and r are the pixel values of the output and the input image and c is a constant. The
value 1 is added to each of the pixel value of the input image because if there is a pixel
intensity of 0 in the image, then log (0) is equal to infinity. So 1 is added, to make the minimum
value at least 1.
During log transformation, the dark pixels in an image are expanded as compare to the higher
pixel values. The higher pixel values are kind of compressed in log transformation. This result
in following image enhancement. The value of c in the log transform adjust the kind of
enhancement you are looking for.
(a) (b)
Figure: Log Transformation: a) Input Image b)Output images
Correcting gamma.
s=cr^γ
s=cr^(1/2.5)
The same image but with different gamma values has been shown here.
For example
The contrast of an image is a measure of its dynamic range, or the "spread" of its histogram.
The dynamic range of an image is defined to be the entire range of intensity values contained
within an image, or put a simpler way, the maximum pixel value minus the minimum pixel
value. Contrast stretching (often called normalization) is a simple image enhancement
technique that attempts to improve the contrast in an image by `stretching' the range of
intensity values it contains to span a desired range of values.
Algorithm:
Program:
To be performed by students.
Expected Output:
Conclusion:
1. Image enhancement
2. Different Gray level transformations and their applications
Detailed MATLAB Code with explanation:
Experiment No. 3
Aim: Write a program to plot histogram of an image and to perform histogram Equalization.
Theory :
If P(r) = probability density function of input gray level. P(s) = probability density function of
output gray level.
As per probability theory,
CDF of an image
Substitute in eq.( 1)
Algorithm:
Program:
To be performed by students.
Expected Output:
Display of Input images, plot histogram of that image, display histogram equalized image and
plot histogram of that equalized image
Conclusion:
Theory :
Instead of highlighting gray level images, 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 the image is composed of 8, 1-bit planes ranging from bit
plane1-0 (LSB) to bit plane 7 (MSB).
In terms of 8-bits bytes, plane 0 contains all lowest order bits in the bytes comprising the pixels
in the image and plane 7 contains all high order bits.
Separating a digital image into its bit planes is useful for analyzing the relative importance
played by each bit of the image, implying, it determines the adequacy of numbers of bits used
to quantize each pixel, useful for image compression.
In terms of bit-plane extraction for a 8-bit image, it is seen that binary image for bit plane 7 is
obtained by proceeding the input image with a thresholding gray-level transformation function
that maps all levels between 0 and 127 to one level (e.g 0)and maps all levels from 129 to 253
to another (eg. 255)
Algorithm:
Program:
To be performed by students.
Expected Output:
Figure: Image reconstructed using 8 and 7 planes and 5,6,7 and 8 planes
Conclusion:
Theory :
Following steps are used to compute the output pixel at position (x,y):
1. Rotate the correlation kernel 180 degrees about its center element to create a convolution
kernel.
2. Slide the center element of the convolution kernel so that it lies on top of the (x,y) element
of A.
3. Multiply each weight in the rotated convolution kernel by the pixel of A underneath.
4. Sum the individual products from step 3.
a b
w(0,-1) w(0,0) w(0,1) g( x, y ) ω( s,t ) f ( x s, y t )
s a t b
The basic idea is replace each pixel by the average of the pixels in a square window surrounding the
pixel. This is also called as average filtering or smoothing operation. The results can be observed as
shown in figure:
Figure: From top row to bottom: a) Original Image b) Filtering with filter size 3×3 c) Filter size
5×5 d) Filter size 9×9 e) Filter size 15×15 f) Filter size 35×35
Advantages Disadvantages
These are also called as sharpening filters. The main idea of sharpening is the enhance line
structures of other details in an image. Thus, the enhanced image contains the original image
with the line structures and edges in the image emphasized.
The first order derivative at an image location is approximated using intensity difference values
around a pixel. Examples of operators used for computing intensity differences are the Robert’s
cross gradient, Prewitt, and Sobel operators. Robert’s cross gradient operators use an even
sized mask and hence lack in symmetry. Prewitt operator uses a 3×3 mask, but performs poorly
in the presence of noise. Commonly used gradient operator is the sobel operator. It provides
for smoothing against noise while performing the differentiation.
Convolving the sobel mask or a robert’s mask approximates the x and y components of gradient
using linear operations. Computation of the gradient is a non-linear operation because
computing the gradient magnitude involves taking the square root of the sum of the square and
computing the gradient angle involves taking atan.
Formulation
To compute 1st derivative at location
x we subtract the value of the To compute 2nd derivative at
function at that location from the location x we use the previous
next point. and the next points in the
computation.
1st order derivative 2nd order derivative
Denoting we
Taking and
Robert’s cross gradient operator mask: The filter mask to implement the
Laplacian:
The formulated masks give a zero response in areas of The formulated masks give a zero
constant intensity. response in areas of constant intensity.
Applications:
1. Image denoising
2. Image enhancement (i.e., “make the image more vivid”)
3. Edge detection, etc.
Algorithm:
Program:
To be performed by students.
Expected Output:
Input images, Output images of low pass and high pass filtering.
Conclusion:
Theory :
Morphology is a broad set of image processing operations that process images based on
shapes. Morphological operations apply a structuring element to an input image, creating an
output image of the same size. In a morphological operation, the value of each pixel in the
output image is based on a comparison of the corresponding pixel in the input image with its
neighbors. By choosing the size and shape of the neighborhood, you can construct a
morphological operation that is sensitive to specific shapes in the input image.
The most basic morphological operations are dilation and erosion. Dilation adds pixels to the
boundaries of objects in an image, while erosion removes pixels on object boundaries. The
number of pixels added or removed from the objects in an image depends on the size and
shape of the structuring element used to process the image. In the morphological dilation and
erosion operations, the state of any given pixel in the output image is determined by applying a
rule to the corresponding pixel and its neighbors in the input image. The rule used to process
the pixels defines the operation as a dilation or an erosion.
Dilation:
Dilation is an operation that “grows” or “thickens” objects in a binary image. The specific
manner and extend of this thickening is controlled by a shape referred to as structuring
element.
Mathematically, dilation is defined in terms of set operations. The dilation of A by B, denoted
by is defined as:
27
Erosion:
The process is also known as “shrinking”. The manner and extent of shrinking is controlled by
a structuring element. Simple erosion is a process of eliminating all the boundary points from
an object, leaving the object smaller in area by one pixel all around its perimeter.
The erosion of A by B, denoted as A Θ B, is defined as
AΘB=
In other words, erosion of A by B is the set of all structuring element origin locations where
the translated B has no overlap with the background of A
Opening:
Opening generally smoothens the contour of an image, eliminates thin protrusions. The
opening of set A by structuring element B, denoted A◦B, is defined as
A◦B= (A Θ B) B -(3)
In other words, opening of A by B is simply the erosion of A by B, followed by dilation of the
result by B.
The opening operation satisfies the following properties:
1) A◦B is a subset of A.
2) If C is a subset of D, then C◦B is a subset of D◦B.
3) (A ◦ B) ◦ B = A◦B.
Algorithm:
Program:
To be performed by students.
Expected Output:
Conclusion:
Experiment No. 7
Aim: Write a program to perform Image compression using Block Truncation Coding (BTC)
Theory :
Using sub-blocks of 4×4 pixels gives a compression ratio of 4:1 assuming 8-bit integer values are
used during transmission or storage. Larger blocks allow greater compression ("a" and "b"
values spread over more pixels) however quality also reduces with the increase in block size
due to the nature of the algorithm
A pixel image is divided into blocks of typically 4×4 pixels. For each block
the Mean and Standard Deviation of the pixel values are calculated; these statistics generally
change from block to block. The pixel values selected for each reconstructed, or new, block are
chosen so that each block of the BTC compressed image will have (approximately) the same
mean and standard deviation as the corresponding block of the original image. A two level
quantization on the block is where we gain the compression and is performed as follows:
.......................................(1)
Here x(i,j) are pixel elements of the original block and y(i,j) are elements of the compressed
block. In words this can be explained as: If a pixel value is greater than the mean it is assigned
the value "1", otherwise "0". Values equal to the mean can have either a "1" or a "0" depending
on the preference of the person or organization implementing the algorithm.
This 16-bit block is stored or transmitted along with the values of Mean and Standard
Deviation. Reconstruction is made with two values "a" and "b" which preserve the mean and
the standard deviation. The values of "a" and "b" can be computed as follows:
.................................................(2)
Where σ is the standard deviation, m is the total number of pixels in the block and q is the
number of pixels greater than the mean 𝑥̅ .
To reconstruct the image, or create its approximation, elements assigned a 0 are replaced with
the "a" value and elements assigned a 1 are replaced with the "b" value.
.................................................(3)
This demonstrates that the algorithm is asymmetric in that the encoder has much more work to
do than the decoder. This is because the decoder is simply replacing 1's and 0's with the
estimated value whereas the encoder is also required to calculate the mean, standard deviation
and the two values to use.
Algorithm:
Program:
To be performed by students.
Expected Output:
Conclusion:
1. Image compression
2. Block truncation coding technique.
Experiment No. 8
Theory :
Vector quantization (VQ) is a lossy data compression method. In the earlier days, the design of
a vector quantizer (VQ) is considered to be a challenging problem due to the need for multi-
dimensional integration. In 1980, Linde, Buzo, and Gray (LBG) proposed a VQ design algorithm
based on a training sequence. The use of a training sequence bypasses the need for multi-
dimensional integration.
Algorithm:
Let the codebook size be NC and the training vectors be { x(n)| n=1,…,M}
1. Let the initial codebook C={ y(i) | i = 1,…,NC} be randomly selected from { x(n)| n =
1,…,M}
2. Cluster the training vectors into NC groups G(i),i =1,…,NC, where
G(i)={x(k) | d(x(k), y(i)) < d (x(k), y(j)); j ≠ i and d(p, q)
denotes the distance between p and q}
3. If the distortion decreases, then go to Step 4 ; otherwise stop
Program:
To be performed by students.
Expected Output:
Conclusion:
1. Image compression
2. Vector quantization, significance and applications.
Experiment No. 9
Aim: Write a program to obtain Gray level co-occurrence matrix (GLCM) for texture representation
Theory :
A statistical method of examining texture that considers the spatial relationship of pixels is the
gray-level co-occurrence matrix (GLCM), also known as the gray-level spatial dependence
matrix. The GLCM functions characterize the texture of an image by calculating how often pairs
of pixel with specific values and in a specified spatial relationship occur in an image, creating a
GLCM, and then extracting statistical measures from this matrix. A GLCM is a histogram of co-
occurring greyscale values at a given offset over an image. The gray-level co-occurrence matrix
can reveal certain properties about the spatial distribution of the gray levels in the texture
image. For example, if most of the entries in the GLCM are concentrated along the diagonal, the
texture is coarse with respect to the specified offset.
Algorithm:
Program:
To be performed by students.
Expected Output:
Conclusion: