0% found this document useful (0 votes)
79 views7 pages

LAB1

The document outlines a lab experiment on computer vision and image processing using OpenCV, including loading, displaying, and saving images; resizing images to specific dimensions; blending two images; and implementing a color filter chatbot that performs operations like hue, saturation, doubling an image, and more. The document provides code snippets for completing the tasks in the lab and answering the pre-lab and post-lab questions.

Uploaded by

Veera phanindra
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)
79 views7 pages

LAB1

The document outlines a lab experiment on computer vision and image processing using OpenCV, including loading, displaying, and saving images; resizing images to specific dimensions; blending two images; and implementing a color filter chatbot that performs operations like hue, saturation, doubling an image, and more. The document provides code snippets for completing the tasks in the lab and answering the pre-lab and post-lab questions.

Uploaded by

Veera phanindra
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/ 7

LAB-1

PRE-LAB:
1. What is computer vision?
2. Give some industrial applications of computer vision?
3. Why should we deal with images in computer vision?
4. What is Bayer color filter array?
IN LAB​:
1. Perform a program for loading an image in an unchanged, color,
gray mode and display them until you press ‘a’ using OPENCV.
Also Write a code to save the three images using OPENCV?
2. Harry is applying to university so in that process he needs to
upload three types of certificates conditions given below. So, help
harry to do his task.
● Resize to specific width (450) and height (550)
● Resize only height (450)
● Downscale with resize ()
3. Implement a code to perform blending operation on two images
in which have 60% of image1 and 40% of image2.
POST LAB:
1. Danil wants to create an interactive Chatbot of color filter in
which it must perform the following operations and ask him to
save the produced image or not.
1 Hue
2 Saturation
3 HSV Image
4 Value
5 Green Channel
6 Doubled image
IN LAB ANSWERS:
1)​import cv2
img = cv2.imread("lena.jpg",0)#grayscale
img1 = cv2.imread("lena.jpg",-1)#unchanged
img2= cv2.imread("lena.jpg",1)#color
print("press ​A ​to close the windows")
cv2.imshow("Hello World1",img)
cv2.imshow("Hello World2",img1)
cv2.imshow("Hello World3",img2)
cv2.waitKey(0)
cv2.destroyAllWindows()

a=input("enter how to save the input")


cv2.imwrite(a+"1"+".jpg",img)
cv2.imwrite(a+"2"+".png",img1)
cv2.imwrite(a+"3"+".png",img2)

2.1)
width = 550
height = 450
dim = (width, height)
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
cv2.imshow("Resized image", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

2.2​)
import​ c​ v2
width = img.shape[1] # keep original width
height = 450
dim = (width, height)
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
cv2.imshow("Resized image", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

2.3)
import cv2
scale_percent = 60
width = int(img.shape[1] * scale_percent / 100)
height = int(img.shape[0] * scale_percent / 100)
dim = (width, height)
resized = cv2.resize(img, dim, interpolation = cv2.INTER_AREA)
cv2.imshow("Resized image", resized)
cv2.waitKey(0)
cv2.destroyAllWindows()

3)
img1 = cv2.imread('ml.png') img2 = cv2.imread('opencv_logo.jpg')
dst = cv2.addWeighted(img1,0.6,img2,0.4,0)
cv2.imshow('dst',dst) cv2.waitKey(0) cv2.destroyAllWindows()

POST LAB:
1)
#Color Filter, Color Space
# Hue : 0 - 180, Saturation : 0 - 255, Value : 0 - 255
import cv2

img = cv2.imread('lena.jpg')
B,G,R = cv2.split(img)
img_HSV = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
print("1","Hue")
print("2","Saturation")
print("3","HSV Image")
print("4","Value")
print("5","Green Channel")
print("6","Doubled image")
while(True):
print('enter the value')
b=int(input())
if(b==1):
cv2.imshow('Hue Channel ', img_HSV[:, :, 0])
cv2.waitKey(0)
cv2.destroyAllWindows()
elif(b==2):
cv2.imshow('Saturation ', img_HSV[:, :, 1])
cv2.waitKey(0)
cv2.destroyAllWindows()
elif(b==3):
cv2.imshow('HSV Image', img_HSV)
cv2.waitKey(0)
cv2.destroyAllWindows()
elif(b==4):
cv2.imshow('value ', img_HSV[:, :, 2])
cv2.waitKey(0)
cv2.destroyAllWindows()
elif(b==5):
cv2.imshow('Green Channel ', G)
cv2.waitKey(0)
cv2.destroyAllWindows()
elif(b==6):
larger = cv2.pyrUp(img)
cv2.imshow("doubled image",larger)
cv2.waitKey(0)
cv2.destroyAllWindows()
print("Do you want to continue")
q=input()
if(q=='N' or q=='n'):
break

**********************************************************
2.3
import cv2
img1 = cv2.imread('C:\\Users\\SATISH VARMA\\Desktop\\m1.jpg')
img2 = cv2.imread('C:\\Users\\SATISH VARMA\\Desktop\\m2.jpg')
dst = cv2.addWeighted(img1,0.3,img2,0.4,0)
cv2.imshow('dst',dst)
cv2.waitKey(0)
cv2.destroyAllWindows()

You might also like