AIR UNIVERSITY
Department of Electrical and Computer Engineering
Digital Image Processing Lab
Lab #4: Sampling and Quantization Variation
Student Name: Umar Mustafa
Roll No: 200365
Instructor: Engr. M. Farooq Khan
Problem 2: Sampling variation </h2>
Let us now observe the variation in image perception, when we change the sampling of the image. In this regard, you are required to do the desired tasks,
1. Load the image ‘droplets.jpg’, and convert it from RGB to gray.
2. Now subsample the image by 2. (Take every alternate pixels in rows as well as column)
3. Do you observe any change in the image outlook or your visual perception? Please discuss
4. Repeat step 5 on iteratively twice and for each subsampling result, discuss the variation in the image perception. Can you explain what is happening?
Do you observe any change in the image outlook or your visual perception? Please discuss
the variation in the image perception. Can you explain what is happening?
Yes, there is a change in the image outlook after subsampling the image by 2. The subsampled image has half the dimensions of the original image, and contains only every other pixel in
both the rows and columns of the original image. This results in a loss of detail and sharpness in the subsampled image compared to the original image. The subsampled image may appear
slightly blurry or pixelated, as some of the fine details in the original image have been lost due to downsampling. However, the overall structure and composition of the image should still be
recognizable, and important features such as edges and shapes should still be preserved to some extent.
Problem 3: Quantization variation
Let us now observe the variation in image perception, when we change the quantization of the image. In this regard, you are required to do the desired tasks,
1. Load the image ‘droplets.jpg’ and convert it from RGB to gray.
2. Now reduce the quantization of the image to 6bit. (the pixel mapping goes from 0-63 instead of 0-255)
3. Do you observe any change in the image outlook or your visual perception? Please discuss
4. Repeat step 5 on for 4-bit, 2-bit and 1-bit quantization, and discuss the variation in the image perception. Can you explain what is happening?
Do you observe any change in the image outlook or your visual perception? and discuss
the variation in the image perception. Can you explain what is happening?
When I performed 6-bit quantization on the image, I reduced the number of possible pixel values from 256 (8-bit) to 64 (6-bit). The result is a loss of detail and a more 'blocky' appearance, as
the image is now represented by a smaller set of discrete values. When I repeated the quantization process with lower bit depths (4-bit, 2-bit, and 1-bit), I further reduced the number of
possible pixel values and introduce more quantization artifacts. So I observed low visual quality as I decreased the number of bits used to represent this image.
Conclusion
Subsampling an image by 2 means reducing the dimensions of the image to half in both the rows and columns, resulting in a smaller image with fewer pixels. It can be done using
formulae or libraries in Python.
Subsampling an image can result in a loss of detail and sharpness, and the degree of loss depends on the degree of subsampling.
Libraries such as NumPy and OpenCV make subsampling simpler and more convenient. Overall, subsampling preserves the overall structure and composition of the image, while
sacrificing some fine details in the process.
Quantization is the process of reducing the number of bits used to represent an image's pixel values. This process reduces the image's file size and computational complexity. However, it
also results in a loss of information and visual quality. Higher quantization levels result in greater loss of detail and more significant visual distortions.
In [28]: import matplotlib.pyplot as plt
import numpy as np
import cv2
from IPython import display
from PIL import Image
# Load an image using cv2.imread
img = cv2.imread('F:/imagelab/droplets.jpg')
plt.subplot(331)
plt.imshow(img,cmap = 'gray')
plt.title('Original Image')
# Gray (Gray_Scale color space):
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Save the image to a file using cv2.imwrite
cv2.imwrite('F:/imagelab/gray.jpg', gray_image)
plt.subplot(332)
plt.imshow(gray_image,cmap = 'gray')
plt.title('Gray Image')
gray_image = np.array(gray_image)
#With Formula
# Subsample the image by a factor of 2
plt.subplot(333)
subsampled2 = gray_image[::2, ::2]
subsampled2 = Image.fromarray(subsampled2)
plt.imshow(subsampled2,cmap = 'gray')
plt.title('Sub Sampled')
# Subsample the image by a factor of 4
plt.subplot(334)
subsampled4 = gray_image[::4, ::4]
subsampled4 = Image.fromarray(subsampled4)
plt.imshow(subsampled4,cmap = 'gray')
plt.title('Sub Sampled4')
# Subsample the image by a factor of 6
plt.subplot(335)
subsampled6 = gray_image[::6, ::6]
subsampled6 = Image.fromarray(subsampled6)
plt.imshow(subsampled6,cmap = 'gray')
plt.title('Sub Sampled6')
#Now without using direct formula
plt.subplot(336)
subsample2 = cv2.resize(gray_image, (gray_image.shape[1]//2, gray_image.shape[0]//2))
plt.imshow(subsample2,cmap = 'gray')
plt.title('Sub Sampled2')
plt.subplot(337)
subsample4 = cv2.resize(gray_image, (gray_image.shape[1]//4, gray_image.shape[0]//4))
plt.imshow(subsample4,cmap = 'gray')
plt.title('Sub Sampled4')
plt.subplot(338)
subsample6 = cv2.resize(gray_image, (gray_image.shape[1]//6, gray_image.shape[0]//6))
plt.imshow(subsample6,cmap = 'gray')
plt.title('Sub Sampled6')
plt.show()
In [29]: # Load an image using cv2.imread
img = cv2.imread('F:/imagelab/droplets.jpg')
plt.subplot(331)
plt.imshow(img,cmap = 'gray')
plt.title('Original Image')
# Gray (Gray_Scale color space):
gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY)
# Save the image to a file using cv2.imwrite
cv2.imwrite('F:/imagelab/gray.jpg', gray_image)
plt.subplot(332)
plt.imshow(gray_image,cmap = 'gray')
plt.title('Gray Image')
# 6bit Quantization
r_6bit = (np.asarray(gray_image) >> 2) << 2
r_6bit = Image.fromarray(r_6bit)
plt.subplot(333)
plt.imshow(r_6bit,cmap = 'gray')
plt.title('quantized 6 bit')
# 4bit Quantization
r_4bit = (np.asarray(gray_image) >> 4) << 4
r_4bit = Image.fromarray(r_4bit)
plt.subplot(334)
plt.imshow(r_4bit,cmap = 'gray')
plt.title('quantized 4bit')
# 2bit Quantization
r_2bit = (np.asarray(gray_image) >> 6) << 6
r_2bit = Image.fromarray(r_2bit)
plt.subplot(335)
plt.imshow(r_2bit,cmap = 'gray')
plt.title('quantized 2bit')
# 1bit Quantization
r_1bit = (np.asarray(gray_image) >> 7) << 7
r_1bit = Image.fromarray(r_1bit)
plt.subplot(336)
plt.imshow(r_1bit,cmap = 'gray')
plt.title('quantized 1bit')
plt.show()

More Related Content

PPTX
Topic 1_PPT.pptx
PPTX
Image Enhancement Techniques using OpenCV – Python.pptx
PPTX
Image Enhancement Techniques using OpenCV – Python.pptx
PDF
Digital Image Processing
DOCX
Laureate Online Education Internet and Multimedia Technolog.docx
PPT
IJ-M&M08.ppt
PDF
aip basic open cv example
PPTX
OpenCV presentation series- part 1
Topic 1_PPT.pptx
Image Enhancement Techniques using OpenCV – Python.pptx
Image Enhancement Techniques using OpenCV – Python.pptx
Digital Image Processing
Laureate Online Education Internet and Multimedia Technolog.docx
IJ-M&M08.ppt
aip basic open cv example
OpenCV presentation series- part 1

Similar to CE344L-200365-Lab4.pdf (20)

PPSX
Introduction To Digital image Processing
PDF
Lossless Huffman coding image compression implementation in spatial domain by...
PDF
Portfolio for CS 6475 Computational Photography
PDF
Can you please separate the code into imagespy sharpenpy.pdf
PDF
An Approach for Image Deblurring: Based on Sparse Representation and Regulari...
PDF
An Approach for Image Deblurring: Based on Sparse Representation and Regulari...
PDF
IRJET- Coloring Greyscale Images using Deep Learning
PPTX
Image proccessing and its applications.
PPTX
Image processing sw & hw
PDF
An introduction to super resolution using deep learning
PDF
Comparative between global threshold and adaptative threshold concepts in ima...
PPTX
AI Unit-5 Image Processing for all ML problems
PPTX
Image enhancement lecture
PDF
Paper id 25201490
PDF
Information search using text and image query
PDF
IRJET- Low Light Image Enhancement using Convolutional Neural Network
PDF
Information search using text and image query
PDF
A modified symmetric local binary pattern for image features extraction
PDF
[IJET-V1I6P16] Authors : Indraja Mali , Saumya Saxena ,Padmaja Desai , Ajay G...
PPTX
A Closed-form Solution to Photorealistic Image Stylization
Introduction To Digital image Processing
Lossless Huffman coding image compression implementation in spatial domain by...
Portfolio for CS 6475 Computational Photography
Can you please separate the code into imagespy sharpenpy.pdf
An Approach for Image Deblurring: Based on Sparse Representation and Regulari...
An Approach for Image Deblurring: Based on Sparse Representation and Regulari...
IRJET- Coloring Greyscale Images using Deep Learning
Image proccessing and its applications.
Image processing sw & hw
An introduction to super resolution using deep learning
Comparative between global threshold and adaptative threshold concepts in ima...
AI Unit-5 Image Processing for all ML problems
Image enhancement lecture
Paper id 25201490
Information search using text and image query
IRJET- Low Light Image Enhancement using Convolutional Neural Network
Information search using text and image query
A modified symmetric local binary pattern for image features extraction
[IJET-V1I6P16] Authors : Indraja Mali , Saumya Saxena ,Padmaja Desai , Ajay G...
A Closed-form Solution to Photorealistic Image Stylization
Ad

More from UmarMustafa13 (8)

PPTX
CEA Technical English.pptx
PPTX
CEA-3-Activity.pptx
PDF
CE344L-200365-Lab2.pdf
PDF
CE344L-200365-Lab7.pdf
PDF
CE344L-200365-Lab5.pdf
PDF
CE344L-200365-Lab6.pdf
PDF
CE344L-200365-Lab3.pdf
PDF
CE344L-200365-Lab8.pdf
CEA Technical English.pptx
CEA-3-Activity.pptx
CE344L-200365-Lab2.pdf
CE344L-200365-Lab7.pdf
CE344L-200365-Lab5.pdf
CE344L-200365-Lab6.pdf
CE344L-200365-Lab3.pdf
CE344L-200365-Lab8.pdf
Ad

Recently uploaded (20)

PDF
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
PPT
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
PDF
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
PDF
Beginners-Guide-to-Artificial-Intelligence.pdf
PDF
Present and Future of Systems Engineering: Air Combat Systems
PDF
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
PPTX
Management Information system : MIS-e-Business Systems.pptx
PDF
First part_B-Image Processing - 1 of 2).pdf
PDF
Java Basics-Introduction and program control
PDF
20250617 - IR - Global Guide for HR - 51 pages.pdf
PPTX
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
PPTX
ai_satellite_crop_management_20250815030350.pptx
PDF
Cryptography and Network Security-Module-I.pdf
PPTX
mechattonicsand iotwith sensor and actuator
PPTX
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
PPTX
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
PPTX
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
PPTX
Micro1New.ppt.pptx the mai themes of micfrobiology
PDF
August -2025_Top10 Read_Articles_ijait.pdf
PDF
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf
Influence of Green Infrastructure on Residents’ Endorsement of the New Ecolog...
Chapter 1 - Introduction to Manufacturing Technology_2.ppt
LOW POWER CLASS AB SI POWER AMPLIFIER FOR WIRELESS MEDICAL SENSOR NETWORK
Beginners-Guide-to-Artificial-Intelligence.pdf
Present and Future of Systems Engineering: Air Combat Systems
UEFA_Carbon_Footprint_Calculator_Methology_2.0.pdf
Management Information system : MIS-e-Business Systems.pptx
First part_B-Image Processing - 1 of 2).pdf
Java Basics-Introduction and program control
20250617 - IR - Global Guide for HR - 51 pages.pdf
Sorting and Hashing in Data Structures with Algorithms, Techniques, Implement...
ai_satellite_crop_management_20250815030350.pptx
Cryptography and Network Security-Module-I.pdf
mechattonicsand iotwith sensor and actuator
CN_Unite_1 AI&DS ENGGERING SPPU PUNE UNIVERSITY
ASME PCC-02 TRAINING -DESKTOP-NLE5HNP.pptx
AUTOMOTIVE ENGINE MANAGEMENT (MECHATRONICS).pptx
Micro1New.ppt.pptx the mai themes of micfrobiology
August -2025_Top10 Read_Articles_ijait.pdf
UEFA_Embodied_Carbon_Emissions_Football_Infrastructure.pdf

CE344L-200365-Lab4.pdf

  • 1. AIR UNIVERSITY Department of Electrical and Computer Engineering Digital Image Processing Lab Lab #4: Sampling and Quantization Variation Student Name: Umar Mustafa Roll No: 200365 Instructor: Engr. M. Farooq Khan Problem 2: Sampling variation </h2> Let us now observe the variation in image perception, when we change the sampling of the image. In this regard, you are required to do the desired tasks, 1. Load the image ‘droplets.jpg’, and convert it from RGB to gray. 2. Now subsample the image by 2. (Take every alternate pixels in rows as well as column) 3. Do you observe any change in the image outlook or your visual perception? Please discuss 4. Repeat step 5 on iteratively twice and for each subsampling result, discuss the variation in the image perception. Can you explain what is happening? Do you observe any change in the image outlook or your visual perception? Please discuss the variation in the image perception. Can you explain what is happening? Yes, there is a change in the image outlook after subsampling the image by 2. The subsampled image has half the dimensions of the original image, and contains only every other pixel in both the rows and columns of the original image. This results in a loss of detail and sharpness in the subsampled image compared to the original image. The subsampled image may appear slightly blurry or pixelated, as some of the fine details in the original image have been lost due to downsampling. However, the overall structure and composition of the image should still be recognizable, and important features such as edges and shapes should still be preserved to some extent. Problem 3: Quantization variation Let us now observe the variation in image perception, when we change the quantization of the image. In this regard, you are required to do the desired tasks, 1. Load the image ‘droplets.jpg’ and convert it from RGB to gray. 2. Now reduce the quantization of the image to 6bit. (the pixel mapping goes from 0-63 instead of 0-255) 3. Do you observe any change in the image outlook or your visual perception? Please discuss 4. Repeat step 5 on for 4-bit, 2-bit and 1-bit quantization, and discuss the variation in the image perception. Can you explain what is happening? Do you observe any change in the image outlook or your visual perception? and discuss the variation in the image perception. Can you explain what is happening? When I performed 6-bit quantization on the image, I reduced the number of possible pixel values from 256 (8-bit) to 64 (6-bit). The result is a loss of detail and a more 'blocky' appearance, as the image is now represented by a smaller set of discrete values. When I repeated the quantization process with lower bit depths (4-bit, 2-bit, and 1-bit), I further reduced the number of possible pixel values and introduce more quantization artifacts. So I observed low visual quality as I decreased the number of bits used to represent this image. Conclusion Subsampling an image by 2 means reducing the dimensions of the image to half in both the rows and columns, resulting in a smaller image with fewer pixels. It can be done using formulae or libraries in Python. Subsampling an image can result in a loss of detail and sharpness, and the degree of loss depends on the degree of subsampling. Libraries such as NumPy and OpenCV make subsampling simpler and more convenient. Overall, subsampling preserves the overall structure and composition of the image, while sacrificing some fine details in the process. Quantization is the process of reducing the number of bits used to represent an image's pixel values. This process reduces the image's file size and computational complexity. However, it also results in a loss of information and visual quality. Higher quantization levels result in greater loss of detail and more significant visual distortions. In [28]: import matplotlib.pyplot as plt import numpy as np import cv2 from IPython import display from PIL import Image # Load an image using cv2.imread img = cv2.imread('F:/imagelab/droplets.jpg') plt.subplot(331) plt.imshow(img,cmap = 'gray') plt.title('Original Image') # Gray (Gray_Scale color space): gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Save the image to a file using cv2.imwrite cv2.imwrite('F:/imagelab/gray.jpg', gray_image) plt.subplot(332) plt.imshow(gray_image,cmap = 'gray') plt.title('Gray Image') gray_image = np.array(gray_image) #With Formula # Subsample the image by a factor of 2 plt.subplot(333) subsampled2 = gray_image[::2, ::2] subsampled2 = Image.fromarray(subsampled2) plt.imshow(subsampled2,cmap = 'gray') plt.title('Sub Sampled') # Subsample the image by a factor of 4 plt.subplot(334) subsampled4 = gray_image[::4, ::4] subsampled4 = Image.fromarray(subsampled4) plt.imshow(subsampled4,cmap = 'gray') plt.title('Sub Sampled4') # Subsample the image by a factor of 6 plt.subplot(335) subsampled6 = gray_image[::6, ::6] subsampled6 = Image.fromarray(subsampled6) plt.imshow(subsampled6,cmap = 'gray') plt.title('Sub Sampled6') #Now without using direct formula plt.subplot(336) subsample2 = cv2.resize(gray_image, (gray_image.shape[1]//2, gray_image.shape[0]//2)) plt.imshow(subsample2,cmap = 'gray') plt.title('Sub Sampled2') plt.subplot(337) subsample4 = cv2.resize(gray_image, (gray_image.shape[1]//4, gray_image.shape[0]//4)) plt.imshow(subsample4,cmap = 'gray') plt.title('Sub Sampled4') plt.subplot(338) subsample6 = cv2.resize(gray_image, (gray_image.shape[1]//6, gray_image.shape[0]//6)) plt.imshow(subsample6,cmap = 'gray') plt.title('Sub Sampled6') plt.show() In [29]: # Load an image using cv2.imread img = cv2.imread('F:/imagelab/droplets.jpg') plt.subplot(331) plt.imshow(img,cmap = 'gray') plt.title('Original Image') # Gray (Gray_Scale color space): gray_image = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # Save the image to a file using cv2.imwrite cv2.imwrite('F:/imagelab/gray.jpg', gray_image) plt.subplot(332) plt.imshow(gray_image,cmap = 'gray') plt.title('Gray Image') # 6bit Quantization r_6bit = (np.asarray(gray_image) >> 2) << 2 r_6bit = Image.fromarray(r_6bit) plt.subplot(333) plt.imshow(r_6bit,cmap = 'gray') plt.title('quantized 6 bit') # 4bit Quantization r_4bit = (np.asarray(gray_image) >> 4) << 4 r_4bit = Image.fromarray(r_4bit) plt.subplot(334) plt.imshow(r_4bit,cmap = 'gray') plt.title('quantized 4bit') # 2bit Quantization r_2bit = (np.asarray(gray_image) >> 6) << 6 r_2bit = Image.fromarray(r_2bit) plt.subplot(335) plt.imshow(r_2bit,cmap = 'gray') plt.title('quantized 2bit') # 1bit Quantization r_1bit = (np.asarray(gray_image) >> 7) << 7 r_1bit = Image.fromarray(r_1bit) plt.subplot(336) plt.imshow(r_1bit,cmap = 'gray') plt.title('quantized 1bit') plt.show()