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.
[Link](figsize=(10, 10))
[Link](image_gray, cmap='gray')
[Link]()
Q-01: What does cmap='gray' signify when using [Link]()?
Task 2: Split Color Channels (BGR)
Instructions: Use the OpenCV library to split the color channels (BGR) of the image.
[Link](figsize=(5,5))
[Link](baboon[:, :, 0])
[Link]()
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 = [Link]()
baboon_red[:, :, 0] = 0
baboon_red[:, :, 1] = 0
[Link](figsize=(10, 10))
[Link]([Link](baboon_red, cv2.COLOR_BGR2RGB))
[Link]()
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
[Link](B)
[Link]()
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.
[Link](figsize=(10,10))
[Link](121)
[Link]([Link](baboon, cv2.COLOR_BGR2RGB))
[Link]("RGB image")
[Link](122)
[Link](im_bgr,cmap='gray')
[Link]("Different color channels")
[Link]()
Q-05: What does the subplot(121) in the code represent?
Task 6: Image Flipping
1. Read an image '[Link]' 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 '[Link]' 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 '[Link]' 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 [Link] with cv2.COLOR_BGR2GRAY on the cropped
image?