0% found this document useful (0 votes)
35 views

Computer Vison Lab Task

The document outlines a series of tasks related to image processing using OpenCV and Matplotlib, including loading images, manipulating color channels, cropping, and visualizing images. Each task includes specific instructions and questions to assess understanding of the concepts. The tasks cover fundamental operations such as image flipping, rotation, and channel manipulation.

Uploaded by

nzangi824
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)
35 views

Computer Vison Lab Task

The document outlines a series of tasks related to image processing using OpenCV and Matplotlib, including loading images, manipulating color channels, cropping, and visualizing images. Each task includes specific instructions and questions to assess understanding of the concepts. The tasks cover fundamental operations such as image flipping, rotation, and channel manipulation.

Uploaded by

nzangi824
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/ 3

Computer Vision Lab Tasks

Task 1: Load and Display an Image in Grayscale


Instructions: Load a sample image using OpenCV and display it in grayscale using
Matplotlib.

plt.figure(figsize=(10, 10))
plt.imshow(image_gray, cmap='gray')
plt.show()

Q-01: What does cmap='gray' signify when using plt.imshow()?

Task 2: Split Color Channels (BGR)


Instructions: Use the OpenCV library to split the color channels (BGR) of the image.

plt.figure(figsize=(5,5))
plt.imshow(baboon[:, :, 0])
plt.show()

Q-02: What will happen if you modify the code to baboon[:, :, 1]?

Task 3: Color Manipulation (Remove a Channel)


Instructions: Remove the Blue and Green channels and only keep the Red channel of the
image.

baboon_red = baboon.copy()
baboon_red[:, :, 0] = 0
baboon_red[:, :, 1] = 0
plt.figure(figsize=(10, 10))
plt.imshow(cv2.cvtColor(baboon_red, cv2.COLOR_BGR2RGB))
plt.show()

Q-03: Which color channel was retained in the above code?


Task 4: Image Cropping and Manipulation
Instructions: Crop a part of the image and display only the cropped region using Matplotlib.

new_image = image[0:rows,:,:]
B = new_image.copy()
new_image[:,:,:] = 0
plt.imshow(B)
plt.show()

Q-04: What will the resulting image display?

Task 5: Subplot Visualization


Instructions: Create a subplot to display the original image and a modified grayscale image
side by side.

plt.figure(figsize=(10,10))
plt.subplot(121)
plt.imshow(cv2.cvtColor(baboon, cv2.COLOR_BGR2RGB))
plt.title("RGB image")
plt.subplot(122)
plt.imshow(im_bgr,cmap='gray')
plt.title("Different color channels")
plt.show()

Q-05: What does the subplot(121) in the code represent?

Task 6: Image Flipping


1. Read an image 'parrot.jpg' using OpenCV.
2. Perform image flipping using the following flipcodes: 0 (vertical flip), 1 (horizontal flip), -
1 (both vertical and horizontal flip).
3. Display the flipped images using matplotlib.
4. Answer the following questions based on the task.

Q-06: What does a flipcode of -1 do to the image?

Q-07: Which function is used to flip an image in OpenCV?


Task 7: Image Rotation
1. Rotate the image 'parrot.jpg' using the following rotation codes:
cv2.ROTATE_90_CLOCKWISE, cv2.ROTATE_90_COUNTERCLOCKWISE, cv2.ROTATE_180.
2. Display the rotated images using matplotlib.
3. Answer the following MCQs based on the task.

Q-08: What does cv2.ROTATE_90_CLOCKWISE do?

Q-09: Which function is used to rotate an image in OpenCV?

Task 8: Image Cropping


1. Crop the image 'parrot.jpg' by selecting a region from row 150 to 400 and column 150 to
400.
2. Display the cropped image using matplotlib.
3. Answer the following MCQs based on the task.

Q-10 : What does the code image[upper:lower, left:right, :] do?

Q-11: What will happen if you use cv2.cvtColor with cv2.COLOR_BGR2GRAY on the cropped
image?

You might also like