0% found this document useful (0 votes)
55 views9 pages

IP Prog 1

The document outlines an assignment that involves modifying a 1024x1024 image to various smaller sizes (512x512, 256x256, 128x128, 64x64, and 32x32) using subsampling techniques. It also describes the process of resampling these smaller images back to the original size. The code provided demonstrates the use of OpenCV for image resizing and displaying the results.

Uploaded by

srushtis1314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
55 views9 pages

IP Prog 1

The document outlines an assignment that involves modifying a 1024x1024 image to various smaller sizes (512x512, 256x256, 128x128, 64x64, and 32x32) using subsampling techniques. It also describes the process of resampling these smaller images back to the original size. The code provided demonstrates the use of OpenCV for image resizing and displaying the results.

Uploaded by

srushtis1314
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 9

3/13/23, 3:26 PM Assignment_2

Problem Statement:
Consider any image with size 1024x1024. Modify the image to the
sizes 512x512, 256x256, 128x128, 64x64 and 32x32 using
subsampling technique. Create the original image from all the
above subsampled images using resampling technique.
In [2]: %cd ..

In [3]: import cv2


from google.colab.patches import cv2_imshow

In [13]: # Load the image


image = cv2.imread("tiger_large_image.jpeg")
cv2_imshow(image)

localhost:8888/lab 1/9
3/13/23, 3:26 PM Assignment_2

In [14]: height, width = image.shape[:2]

print(width)
print(height)

1024
1024

Sub-sampling the original image (1024x1024) to size: 512x512.


In [22]: # Calculate the new dimensions of the image
new_height = 512
new_width = 512

# Resize the image using subsampling


resized_image1 = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LIN
cv2_imshow(resized_image1)

localhost:8888/lab 2/9
3/13/23, 3:26 PM Assignment_2

Sub-sampling the original image (1024x1024) to size: 256x256.


In [23]: # Calculate the new dimensions of the image
new_height = 256
new_width = 256

# Resize the image using subsampling


resized_image2 = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LIN
cv2_imshow(resized_image2)

localhost:8888/lab 3/9
3/13/23, 3:26 PM Assignment_2

Sub-sampling the original image (1024x1024) to size: 128x128.


In [24]: # Calculate the new dimensions of the image
new_height = 128
new_width = 128

# Resize the image using subsampling


resized_image3 = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LIN
cv2_imshow(resized_image3)

Sub-sampling the original image (1024x1024) to size: 64x64.


In [25]: # Calculate the new dimensions of the image
new_height = 64
new_width = 64

# Resize the image using subsampling


resized_image4 = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LIN
cv2_imshow(resized_image4)

Sub-sampling the original image (1024x1024) to size: 32x32.


In [26]: # Calculate the new dimensions of the image
new_height = 32
new_width = 32

# Resize the image using subsampling


resized_image5 = cv2.resize(image, (new_width, new_height), interpolation=cv2.INTER_LIN
cv2_imshow(resized_image5)

Re-sampling the image of size 512x512 to the original size


(1024x1024):
In [27]: # Calculate the new dimensions of the image
new_height = 1024
new_width = 1024

# Resize the image resampling to original size


new_original_image1 = cv2.resize(resized_image1, (new_width, new_height), interpolation
cv2_imshow(new_original_image1)

localhost:8888/lab 4/9
3/13/23, 3:26 PM Assignment_2

Re-sampling the image of size 256x256 to the original size


(1024x1024):
In [28]: # Resize the image resampling to original size
new_original_image2 = cv2.resize(resized_image2, (new_width, new_height), interpolation
cv2_imshow(new_original_image2)

localhost:8888/lab 5/9
3/13/23, 3:26 PM Assignment_2

Re-sampling the image of size 128x128 to the original size


(1024x1024):
In [29]: # Resize the image resampling to original size
new_original_image3 = cv2.resize(resized_image3, (new_width, new_height), interpolation
cv2_imshow(new_original_image3)

localhost:8888/lab 6/9
3/13/23, 3:26 PM Assignment_2

Re-sampling the image of size 64x64 to the original size


(1024x1024):
In [30]: # Resize the image resampling to original size
new_original_image4 = cv2.resize(resized_image4, (new_width, new_height), interpolation
cv2_imshow(new_original_image4)

localhost:8888/lab 7/9
3/13/23, 3:26 PM Assignment_2

Re-sampling the image of size 32x32 to the original size


(1024x1024):
In [31]: # Resize the image resampling to original size
new_original_image5 = cv2.resize(resized_image5, (new_width, new_height), interpolation
cv2_imshow(new_original_image5)

localhost:8888/lab 8/9
3/13/23, 3:26 PM Assignment_2

In [ ]:

localhost:8888/lab 9/9

You might also like