Digital Image Processing LAB MANUAL 6th Sem-Final
Digital Image Processing LAB MANUAL 6th Sem-Final
DEPARTMENT
OF
CSE (ARTIFICIAL INTELLIGENCE & MACHINE LEARNING)
LABORATORY MANUAL
SEMESTER – VI
Vision
“To impart quality education to cater the needs of Industries, Business
Establishments, Research and Development Organizations, create
Knowledgeable and competent Engineers of global standard.”
Mission
“To create Industry enabled Engineers manifesting in excellence with
extraordinary progress, to give bright and challenging future for
deserving students who are underprivileged.”
Vision
“To promote partnership between the academic and industry sectors to
bring to bring in a innovative ecosystem and being very beneficial to the
whole society.”
Mission
1. Artificial Intelligence and Machine Learning department intends to
provide a major support to enable R&D contributing to the
fundamental research in AI and ML
2. Commit to openness and inclusiveness in a collaborative and
constructive spirit to boldly attack challenging problems with high
social and economic impact
3. Initiate the education and training paying special attention two the
necessary skills of the next generation workforce
Program Specific Outcomes (PSOs)
CREDITS – 2
• Programming tools preferred: SCILAB, Python, Java or any other relevant platform.
• For Part A: Students must exhibit the results and its print copy to be attached to Lab record.
• For Part B: Real Time Images can be used to demonstrate the work.
During the practical exam: the students should demonstrate and answer Viva-Voce
Programs List: PART A
1 Write a Program to read a digital image. Split and display image into 4 quadrants, up,
down, right and left
2 Write a program to show rotation, scaling, and translation of an image.
3 Read an image, first apply erosion to the image and then subtract the result from the
original. Demonstrate the differencein the edge image if you use dilation instead of erosion.
4 Read an image and extract and display low-level features such as edges, textures using
filtering techniques
5 Demonstrate enhancing and segmenting low contrast 2D images.
Experiment distribution
o For laboratories having only one part: Students are allowed to pick one experiment from the
lot with equal opportunity.
o For laboratories having PART A: Students are allowed to pick one experiment from PART
A, with equal opportunity. The mini project from PART B to be run &exhibit the results also a
report on the work is produced.
Change of experiment is allowed only once and marks allotted for procedure to be made zero
of the changed part only.
Marks Distribution (Subjected to change in accordance with university regulations)
o) For laboratories having only one part – Procedure + Execution + Viva-Voce: 15+70+15 =
100 Marks
p) For laboratories having PART A and PART B
i. Part A – Procedure + Execution + Viva = 6 + 28 + 6 = 40 Marks
ii. Part B – Procedure + Execution + Viva = 9 + 42 + 9 = 60 Marks
CONTENTS
PAGE
SL.NO PROGRAM NAME
NO.
PART-A
Write a Program to read a digital image. Split and display image into 4
1 1
quadrants, up, down, right and left
2 Write a program to show rotation, scaling, and translation of an image. 2
Read an image, first apply erosion to the image and then subtract the result
3 from the original. Demonstrate the difference in the edge image if you use 3
dilation instead of erosion.
Read an image and extract and display low-level features such as edges,
4 textures using filtering techniques 4
Write a Program to read a digital image. Split and display image into 4 quadrants, up, down,
right and left
import cv2
img = cv2.imread(r'C:\Users\DBIT-R&D\Desktop\ip.jpg')
h, w, channels = img.shape
half = w // 2
half2 = h // 2
quadrant1 = img[:half2, :half]
cv2.imshow('image1', quadrant1)
quadrant2 = img[half2:, half:]
cv2.imshow('image2', quadrant2)
quadrant3 = img[:half2, half:]
cv2.imshow('image3', quadrant3)
quadrant4 = img[half2:, :half]
cv2.imshow('image4', quadrant4)
cv2.waitKey(0)
Results:
input:
output:
PROGRAM 2
Write a program to show rotation, scaling, and translation of an image.
import cv2
import numpy as np
width = 650
height = 450
dim = (width, height)
# resize image
resized = cv2.resize(img, dim, interpolation=cv2.INTER_AREA)
tx = 50
ty = 400
h, w = img.shape[:2]
cv2.waitKey(0)
output:
For rotation :
#cv2.ROTATE_90_CLOCKWISE
#cv2.ROTATE_180
#cv2.ROTATE_90_COUNTERCLOCKWISE
PROGRAM 3
Read an image, first apply erosion to the image and then subtract the result from the original.
Demonstrate the difference in the edge image if you use dilation instead of erosion.
import cv2
import numpy as np
# Load the image
image = cv2.imread(r'C:\Users\DBIT-R&D\Desktop\ip.jpg')
# Define the erosion kernel and apply it to the image
kernel = np.ones((5, 5), np.uint8)
eroded_image = cv2.erode(image, kernel, iterations=1)
# Subtract the eroded image from the original image
edge_image = cv2.absdiff(image, eroded_image)
# Display the original image and edge image
cv2.imshow("Original Image", image)
cv2.imshow("Edge Image (Erosion)", edge_image)
# Apply dilation to the image
dilated_image = cv2.dilate(image, kernel, iterations=1)
# Subtract the dilated image from the original image
edge_image_dilation = cv2.absdiff(image, dilated_image)
# Display the edge image with dilation
cv2.imshow("Edge Image (Dilation)", edge_image_dilation)
# Wait for a key press and then close the windows
cv2.waitKey(0)
cv2.destroyAllWindows()
Output:
PROGRAM 4
Read an image and extract and display low-level features such as edges, textures using
filtering techniques
import cv2
import numpy as np
# Read the original image
img = cv2.imread(r'C:\Users\DBIT-R&D\Desktop\ip.jpg')
# Display original image
cv2.imshow('Original', img)
# Convert to graycsale
img_gray = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Blur the image for better edge detection
img_blur = cv2.GaussianBlur(img_gray, (3, 3), 0)
cv2.waitKey(0)
output:
PROGRAM 5
Demonstrate enhancing and segmenting low contrast 2D images.
import cv2
import numpy as np
# Load the low contrast image
image = cv2.imread(r'C:\Users\DBIT-R&D\Desktop\low.jpg',
cv2.IMREAD_GRAYSCALE)
# Apply adaptive histogram equalization to enhance the contrast
clahe = cv2.createCLAHE(clipLimit=8.0, tileGridSize=(8,8))
enhanced_image = clahe.apply(image)
# Display the original and enhanced images
cv2.imshow('Original', image)
cv2.imshow('Enhanced', enhanced_image)
# Apply Otsu's thresholding to segment the image
_, threshold_image = cv2.threshold(enhanced_image, 0, 255,
cv2.THRESH_BINARY +
cv2.THRESH_OTSU)
# Display the thresholded image
cv2.imshow('segmented image', threshold_image)
# Wait for a key press and then close the windows
cv2.waitKey(0)
output:
PART B
Will be continued as Mini
Project.
DIP Viva Questions :
While cone photoreceptors detect color through bright light, rodphotoreceptors are sensitive
to low-light levels.
Rods aid in night vision and identifying black and white hues.
Both cones and rods contain special proteins that assist in their functionality. The human
eye contains more rod photoreceptors than conephotoreceptors.
or
A pixel (short for picture element) is a single point or a tiny square in a graphic image
stored in an ordered rectangular grid. It is the smallest element in a digital image. The more
pixels used to represent an image, thecloser the result can resemble the analog original.
27. What are the differences between Structural Patterns & Morphological Structural
Element?
Ans: Structuring element is the matrix used to remove irregularities from theimage. (it can
contain 0 or 1) Helps to analyse the noise and texture of image. Structural pattern can be a
general pattern present all over the image
28. The type of Interpolation where for each new location the intensity ofthe immediate
pixel is assigned is
Ans: nearest neighbour interpolation
Its called as Nearest Neighbour Interpolation since for each new location theintensity of the
next neighbouring pixel is assigned.
33. The type of Interpolation where the intensity of the FOUR neighboringpixels is used to
obtain the intensity of a new location is called
Ans: nearest-neighbor interpolation.
Bilinear interpolation is where the FOUR neighboring pixels are used to estimate
intensity for a new location.
34. The transition between continuous values of the image function andits digital
equivalent is called
Ans: quantization.
The number of quantization levels should be high enough for humanperception of ûne
shading details in the image.
39. Dynamic range of the imaging system is a ratio where the upper limitis determined
by Saturation?
Ans: Here, we deûne the dynamic range of an imaging system to be the ratioof the maximum
measurable intensity to the minimum detectable intensity level in the system. As a rule, the
upper limit is determined by saturation andthe lower limit by noise, although noise can be
present also in lighter intensities.
40. What tool is used in tasks such as zooming, shrinking, rotating, etc.? Ans:
Interpolation : It is the process of using known data to estimate valuesat unknown
locations.
41. How to increase the quality of an image?
● Filtering with morphological operators
● Histogram equalization
● Noise removal using a Wiener ûlter
● Linear contrast adjustment
● Median ûltering
● Unsharp mask ûltering
● Contrast-limited adaptive histogram equalization (CLAHE)
● Decorrelation stretch
43. Find the number of bits required to store a 256 X 256 image with 32 gray levels?
Ans: 32 gray levels = 25 = 5 bits 256 * 256 * 5 = 327680 bits.
45. For Dynamic range ratio the lower limit is determined by?
Ans: The dynamic range of the input signal is less straightforward, becausethe lower limit
is determined by the amount of noise in the analog waveform, which could be inüuenced
by environmental conditions or the gain setting of a variable-gain ampliûer that precedes
the ADC.
47. Write the expression to ûnd the number of bits to store a digitalimage?
Ans: The number of bits required to store a digital image is
=>b=M X N X k
When M=N, this equation becomes
=>b=N^2k
49. Images quantized with insufûcient brightness levels will lead to theoccurrence of
.
Ans: Pixillation