SOLUTION OF 21CS613
DIGITAL IMAGE PROCESSING
SECTION – A (3 marks * 5 Questions = 15 Marks)
1. Explain the 4, 8 and m connectivity of pixels with the help of an example.
Solution Two pixels ‘p’ and ‘q’ are said to be connected if they are neighbours and their gray levels satisfy a
specified condition/criterion of similarity (or equal).
Let, ‘V’ be the set of gray levels used to define connectivity.
4 - Connectivity: Two pixels ‘p’ and ‘q’ with values from ‘V’ are 4-connected if q ∈ N4 (p). 8 -
Connectivity: Two pixels ‘p’ and ‘q’ with values from ‘V’ are 8-connected if q ∈ N8 (p).
m - Connectivity: Two pixels ‘p’ and ‘q’ with values from ‘V’ are m-connected if
(i) q ∈ N4 (p). (ii) q ∈ ND (p) and set N4 (p) ∩ N4 (q) = Ø.
2. Explain the fundamental steps of image processing with the help of a block diagram.
Solution Image Acquisition: This step aims to obtain the digital image of an object. Image Enhancement:
This step is used to improve the quality of the image, so that the analysis of the image is reliable.
Image Restoration: It deals with improving the appearance of an image. Restoration
techniques are based on mathematical or probabilistic models of image degradation.
Image Compression: It is used to reduce the storage requirements to save an image or to
reduce bandwidth required to transmit an image.
Morphological Image Processing: It deals with tools for extracting image components that
are useful in the representation and description of image. Segmentation: This step divides
the image into its constituent parts or objects or sub regions and extracts the regions that are
necessary for further analysis. Representation & Description: It is the process where the
features of the object are extracted (description) and represented using various schemes.
Recognition : It is the process that assigns a label to an object based on its descriptors.
3. Explain the sampling and quantization of images with the help of a suitable diagram.
Solution To create a digital image, continuous sensed data needs to be converted into digital form, which
involves two processes : Sampling and Quantization.
Sampling is the process in which the coordinate values of an image are digitized.
Quantization is the process in which the amplitude values of an image are digitized.
4. Obtain the digital negative of the following 8 - bit sub image.
139 205 105
141 252 99
201 15 76
Solution As, the given sub image is of 8-bit, therefore, L = 256.
Using the image negative transformation given by s=L– 1– r
116 50 150
114 3 156
54 240 179
5. Describe image subtraction and image averaging.
Solution Image Subtraction : The difference between two images f(x,y) and h(x,y) is obtained by computing
the difference between all pairs of corresponding pixels from ‘f’ and ‘h’. Mathematical expression for
image subtraction is given as :
g(x, y) = f(x, y) – h(x, y)
It is used for enhancement of differences between images and applications includes image
segmentation and in the area of medical imaging called mask mode radiography.
Image Averaging : It is used for noise reduction. It is achieved by adding the corresponding
pixel image of all the noisy images and then dividing them with the number of noisy images to get the
averaged intensity. If the noise at each pixel is uncorrelated, then, it gets cancelled out during averaging.
Better results can be obtained as the numbers of noisy images are increased.
g(x, y) = f(x, y) + n(x, y) ;
where, g(x, y), f(x, y) and n(x, y) are the noisy image, original image and noise respectively.
𝐾
𝑔̅
𝐾𝑖
E{ f(x, y)
SECTION – B (5 marks * 1 Questions = 5 Marks)
6. An image segment is shown below. Let, V be the set of gray level values used to define connectivity in the
image. Compute D4, D8 and Dm distances between pixels ‘p’ and ‘q’ for :
(i) V = {2,3} (ii) V = {2,6}
2 (p) 3 2 6 1
6 2 3 6 2
5 3 2 3 5
2 4 3 5 2
4 5 2 3 6 (q)
Solution As, D4 and D8 distance depends only on the coordinates of pixels and not on the
gray levels of pixels. Therefore,
Coordinates of p (x, y) = (0, 0) and Coordinates of q (s, t) = (5, 5).
D4 (p, q) = |x - s| + |y - t| = |0 - 5| + |0 - 5| = 5 + 5 = 10 units.
D8 (p, q) = max (|x - s| , |y - t| ) = max (|0 - 5| , |0 - 5| ) = 5 units.
Dm distance between two pixels depends on the values of the pixels along with the path and also on the
values of their neighbours.
(i) If V = {2, 3}, Here, gray level of pixel ‘q’ = 6, which doesn’t belongs to ‘V’. So, there is no path
through which ‘p’ and ‘q’ are connected. Therefore, Dm distance for this case can’t be
computed.
2 (p) 3 2 6 1
6 2 3 6 2
5 3 2 3 5
2 4 3 5 2
4 5 2 3 6 (q)
(ii) If V = {2, 6}.
There is no path through which ‘p’ and ‘q’ are connected. Therefore, Dm distance for this case
can’t be computed.
2 (p) 3 2 6 1
6 2 3 6 2
5 3 2 3 5
2 4 3 5 2
4 5 2 3 6 (q)
OR
Explain the various techniques of gray level slicing and contrast stretching with the help of a diagram.
Solution Gray level slicing is required to highlight a specific range of gray levels in an image. Two techniques of
gray level slicing are –
(A) To display a high value for all gray levels in the specific range of interest and a low value for all
other gray levels. This transformation produces a binary image.
(B) Brightens the desired range of gray levels but preserves the background and gray level tonalities
in the image. This transformation produces a gray scale image.
Contrast Stretching: It is a simple piecewise linear transformation function which is used to increase
the dynamic range of the gray levels in the image being processed.
The location of points (r1, s1) and (r2, s2) in figure (c) controls the shape of the transformation
function. If r1 = s1 and r2 = s2, it is a linear function that produces no change in the gray level. If r1 =
r2, s1 = 0 and s2 = L – 1, the transformation becomes a thresholding function that creates a binary
image
In general, r1 ≤ r2 and s1 ≤ s2 is assumed so that the function is single valued and monotonically
increasing.
SECTION – C (10 marks * 1 Questions = 10 marks)
7. Explain histogram matching. What is the need of histogram specification. Deduce the formula for histogram
specification. Perform the histogram equalization for 8 × 8 image shown below.
Gray 0 1 2 3 4 5 6 7
Levels
No. of 9 8 11 4 10 15 4 3
pixels
Solution Histogram matching is the method used to generate a processed image that has a specified histogram.
Histogram specification is useful in the applications where uniform histogram is not the best
approach for image enhancement. Therefore, it is required to specify the shape of the histogram that
we wish the processed image to have.
For Continuous Case: Let, ‘r’ and ‘z’ are the gray levels of the input and processed images and p r(r)
and pz(z) denotes their corresponding continuous probability density functions.
𝑟
𝑠 𝑑𝑤
𝑧
𝐺 𝑠
Therefore, 𝐺(𝑧) = 𝑇(𝑟)
𝑧 = 𝐺−1(𝑠) = 𝐺−1[𝑇(𝑟)]
For Discrete Case:
Gray 0 1 2 3 4 5 6 7
Levels(rk)
No. of 9 8 11 4 10 15 4 3
pixels(nk)
p(rk)=nk/n 0.141 0.125 0.172 0.0625 0.156 0.234 0.0625 0.047
Applying histogram equalization,
s = T[ r ] = (L – 1) ∑𝑘 𝑛j = 7∑𝑘 𝑝(𝑟 ) k k
j=0 𝑛 j=0 j
s0 = 7(0.141) = 0.987 → 1 s1 = 7(0.141 + 0.125) = 7(0.266) = 1.862 → 2 s2 = 7(0.141 + 0.125 + 0.172)
= 7(0.438) = 3.066 → 3 s3 = 7(0.141 + 0.125 + 0.172 + 0.0625) = 7(0.5005) = 3.5035 → 4 s4 = 7(0.141
+ 0.125 + 0.172 + 0.0625 + 0.156) = 7(0.6565) = 4.5955 → 5 s5 = 7(0.141 + 0.125 + 0.172 + 0.0625 +
0.156 + 0.234) = 7(0.8905) = 6.2335 → 6 s6 = 7(0.141 + 0.125 + 0.172 + 0.0625 + 0.156 + 0.234 +
0.0625) = 7(0.953) = 6.671 → 7 s7 = 7(0.141 + 0.125 + 0.172 + 0.0625 + 0.156 + 0.234 + 0.0625 +
0.047) = 7(1) = 7 → 7
rk 0 1 2 3 4 5 6 7
sk 1 2 3 4 5 6 7 7
p(sk) 0.141 0.125 0.172 0.0625 0.156 0.234 0.1095 0.1095
************