Deep Learning for Computer Vision
Question Bank
Module 1
1. Write a Python program to read and display images from the folder
using Open CV.
Ans:
import cv2
import os
folder_path = "images/" # replace with your folder path
for filename in [Link](folder_path):
if [Link](".jpg") or [Link](".png"):
img_path = [Link](folder_path, filename)
img = [Link](img_path)
[Link]("Image", img)
[Link](500) # show each image for 500ms
[Link]()
2. Write a Python program to convert the images from RGB to Gray,
HSV, and CMYK format.
import cv2
import numpy as np
img = [Link]("[Link]")
gray = [Link](img, cv2.COLOR_BGR2GRAY)
hsv = [Link](img, cv2.COLOR_BGR2HSV)
# CMYK conversion (manual because OpenCV does not directly
support it)
bgr = [Link](float) / 255
k = 1 - [Link](bgr, axis=2)
c = (1 - bgr[..., 2] - k) / (1 - k + 1e-8)
m = (1 - bgr[..., 1] - k) / (1 - k + 1e-8)
y = (1 - bgr[..., 0] - k) / (1 - k + 1e-8)
cmyk = (c, m, y, k)
[Link]("Gray", gray)
[Link]("HSV", hsv)
[Link](0)
[Link]()
3. Write a Python program to apply the various filters using Open CV.
import cv2
img = [Link]("[Link]")
# Box Filter (Average)
avg = [Link](img, (5,5))
# Gaussian Filter
gauss = [Link](img, (5,5), 0)
# Median Filter
median = [Link](img, 5)
[Link]("Average", avg)
[Link]("Gaussian", gauss)
[Link]("Median", median)
[Link](0)
[Link]()
4. Write a Python program to add text and border lines to the image.
import cv2
img = [Link]("[Link]")
# Add text
[Link](img, "Hello OpenCV", (50,50),
cv2.FONT_HERSHEY_SIMPLEX, 1, (0,0,255), 2)
# Add border
bordered = [Link](img, 10, 10, 10, 10,
cv2.BORDER_CONSTANT, value=(0,255,0))
[Link]("Image with Text and Border", bordered)
[Link](0)
[Link]()
5. Write a Python program to apply morphological operations using
Open CV.
import cv2
import numpy as np
img = [Link]("[Link]", 0)
_, thresh = [Link](img, 127, 255, cv2.THRESH_BINARY)
kernel = [Link]((5,5), np.uint8)
erosion = [Link](thresh, kernel, iterations=1)
dilation = [Link](thresh, kernel, iterations=1)
opening = [Link](thresh, cv2.MORPH_OPEN, kernel)
closing = [Link](thresh, cv2.MORPH_CLOSE, kernel)
[Link]("Erosion", erosion)
[Link]("Dilation", dilation)
[Link]("Opening", opening)
[Link]("Closing", closing)
[Link](0)
[Link]()
6. Write a Python program to apply functions used for image-
enhancing.
Functions for Image Enhancement
Brightness adjustment
Contrast stretching
Histogram equalization
Sharpening
import cv2
img = [Link]("[Link]")
# Histogram Equalization (on grayscale)
gray = [Link](img, cv2.COLOR_BGR2GRAY)
equ = [Link](gray)
[Link]("Original", gray)
[Link]("Enhanced", equ)
[Link](0)
[Link]()
7. Write a Python program to increase the image's brightness using
Open CV.
import cv2
img = [Link]("[Link]")
bright = [Link](img, alpha=1, beta=50) # beta controls
brightness
[Link]("Original", img)
[Link]("Brightened", bright)
[Link](0)
[Link]()
8. Write a Python program to perform the data augmentation
operations.
import cv2
import numpy as np
img = [Link]("[Link]")
# Flipping
flip_h = [Link](img, 1)
flip_v = [Link](img, 0)
# Rotation
(h, w) = [Link][:2]
M = cv2.getRotationMatrix2D((w//2, h//2), 45, 1.0)
rotated = [Link](img, M, (w,h))
[Link]("Horizontal Flip", flip_h)
[Link]("Vertical Flip", flip_v)
[Link]("Rotated", rotated)
[Link](0)
[Link]()
9. What is Compute Vision? Explain it’s Key Components and it’s
Applications?
From notes
Definition: Computer Vision (CV) is a branch of AI that allows
machines to interpret and understand visual data (images/videos)
similar to how humans use eyes + brain.
Key Components:
1. Image Processing
2. Object Detection & Recognition
3. Image Classification
4. Image Segmentation
5. Object Tracking
6. 3D Vision
7. Scene Understanding
Applications:
Healthcare → Tumor detection in X-rays
Automotive → Self-driving cars
Manufacturing → Quality control
Entertainment → AR/VR
Agriculture → Crop monitoring
Robotics → Object recognition, navigation
10. Write a Python program to:
1. Read and display an image.
2. Print its properties (height, width, and number of channels).
3. Resize the image to 400×400 resolution.
4. Convert the image to grayscale.
import cv2
img = [Link]("[Link]")
# Display
[Link]("Image", img)
# Properties
print("Height:", [Link][0])
print("Width:", [Link][1])
print("Channels:", [Link][2])
# Resize
resized = [Link](img, (400,400))
# Convert to Grayscale
gray = [Link](img, cv2.COLOR_BGR2GRAY)
[Link]("Resized", resized)
[Link]("Grayscale", gray)
[Link](0)
[Link]()
Module 2
1. Explain the pre-processing steps involved in Object Detection.
2. What is the difference between Object Recognition and Object Detection
in computer vision?
3. How do you prepare a dataset for Object Detection? And What are the
key points to consider while creating a dataset for Object Detection?
4. Write a Python program to implement YOLO V8 on the custom dataset.
5. Write a Python program to implement Faster R-CNN and apply NMS.
6. Explain the bounding box concept in object detection and the different
formats used in the bounding box.
7. Explain the IoU evaluation metric with an example.
8. Explain the sliding window concept and illustrate the disadvantages of
the sliding window.
9. Explain the working principle of Faster R-CNN.
10. Describe the loss function used in Faster R-CNN and YOLO.
11. Explain the working mechanism of the YOLO model.
12. What is the Sliding Window concept in object detection? What are its
disadvantages? Explain the Anchor Box concept and how it works.
13. Explain the Sliding Window Method used in object detection,
highlighting its working steps. Further, describe how Non-Maximum
Suppression (NMS) is applied to refine detection results.