0
0
Computer Visionml~10 mins

Color space conversion in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to convert an image from BGR to grayscale using OpenCV.

Computer Vision
gray_image = cv2.cvtColor(color_image, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_BGR2GRAY
Bcv2.COLOR_RGB2GRAY
Ccv2.COLOR_GRAY2BGR
Dcv2.COLOR_BGR2RGB
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.COLOR_RGB2GRAY which assumes the image is in RGB format.
Using cv2.COLOR_GRAY2BGR which converts grayscale to color, not the other way.
2fill in blank
medium

Complete the code to convert an image from BGR to HSV color space.

Computer Vision
hsv_image = cv2.cvtColor(input_image, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_RGB2HSV
Bcv2.COLOR_BGR2HSV
Ccv2.COLOR_HSV2BGR
Dcv2.COLOR_BGR2GRAY
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.COLOR_RGB2HSV which is incorrect for BGR images.
Using cv2.COLOR_HSV2BGR which converts back from HSV to BGR.
3fill in blank
hard

Fix the error in the code to convert an image from HSV back to BGR.

Computer Vision
bgr_image = cv2.cvtColor(hsv_image, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_BGR2HSV
Bcv2.COLOR_RGB2HSV
Ccv2.COLOR_HSV2BGR
Dcv2.COLOR_BGR2GRAY
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.COLOR_BGR2HSV which converts in the wrong direction.
Using cv2.COLOR_BGR2GRAY which changes color space incorrectly.
4fill in blank
hard

Fill both blanks to create a dictionary comprehension that maps color names to their HSV ranges.

Computer Vision
hsv_ranges = {color: ([1], [2]) for color in colors}
Drag options to blanks, or click blank then click option'
Alower_bounds
Bupper_bounds
Ccolor
Drange
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'color' or 'range' instead of the HSV bound variables.
Swapping lower and upper bounds.
5fill in blank
hard

Fill all three blanks to create a mask for a color range and apply it to the image.

Computer Vision
mask = cv2.inRange(hsv_image, [1], [2])
result = cv2.bitwise_and(original_image, original_image, mask=[3])
Drag options to blanks, or click blank then click option'
Alower_hsv
Bupper_hsv
Cmask
Dhsv_image
Attempts:
3 left
💡 Hint
Common Mistakes
Using the image instead of mask in the bitwise_and function.
Swapping lower and upper HSV bounds.