0
0
Computer Visionml~10 mins

Color spaces (RGB, BGR, grayscale, HSV) 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(image, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_BGR2RGB
Bcv2.COLOR_RGB2GRAY
Ccv2.COLOR_GRAY2BGR
Dcv2.COLOR_BGR2GRAY
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.COLOR_RGB2GRAY instead of cv2.COLOR_BGR2GRAY
Using a conversion code that changes color order instead of converting to grayscale
2fill in blank
medium

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

Computer Vision
hsv_image = cv2.cvtColor(image, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_BGR2HSV
Bcv2.COLOR_RGB2HSV
Ccv2.COLOR_HSV2RGB
Dcv2.COLOR_GRAY2HSV
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.COLOR_BGR2HSV when the image is RGB
Using a conversion code that converts HSV back to RGB
3fill in blank
hard

Fix the error in the code to convert a grayscale image back to BGR color space.

Computer Vision
bgr_image = cv2.cvtColor(gray_image, [1])
Drag options to blanks, or click blank then click option'
Acv2.COLOR_RGB2GRAY
Bcv2.COLOR_BGR2GRAY
Ccv2.COLOR_GRAY2BGR
Dcv2.COLOR_BGR2RGB
Attempts:
3 left
💡 Hint
Common Mistakes
Using cv2.COLOR_BGR2GRAY which converts color to grayscale
Using color order conversions instead of grayscale to BGR
4fill in blank
hard

Fill both blanks to create a dictionary that maps color space names to their OpenCV conversion codes.

Computer Vision
color_conversions = {
    'RGB_to_HSV': [1],
    'BGR_to_Gray': [2]
}
Drag options to blanks, or click blank then click option'
Acv2.COLOR_RGB2HSV
Bcv2.COLOR_BGR2GRAY
Ccv2.COLOR_HSV2RGB
Dcv2.COLOR_GRAY2BGR
Attempts:
3 left
💡 Hint
Common Mistakes
Swapping the conversion codes for the keys
Using HSV to RGB instead of RGB to HSV
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps each color space name to its conversion code if the code converts to grayscale.

Computer Vision
gray_conversions = {name: code for name, code in color_conversions.items() if code [1] cv2.COLOR_BGR2GRAY or code [2] cv2.COLOR_RGB2GRAY or code [3] cv2.COLOR_HSV2GRAY}
Drag options to blanks, or click blank then click option'
A==
B!=
Cis
D>
Attempts:
3 left
💡 Hint
Common Mistakes
Using != or > instead of ==
Using 'is' which is not reliable for value comparison