Complete the code to convert an image from BGR to grayscale using OpenCV.
gray_image = cv2.cvtColor(image, [1])OpenCV loads images in BGR format by default. To convert to grayscale, use cv2.COLOR_BGR2GRAY.
Complete the code to convert an image from RGB to HSV color space.
hsv_image = cv2.cvtColor(image, [1])To convert from RGB to HSV, use cv2.COLOR_RGB2HSV. This changes the color space to HSV.
Fix the error in the code to convert a grayscale image back to BGR color space.
bgr_image = cv2.cvtColor(gray_image, [1])To convert a grayscale image to BGR, use cv2.COLOR_GRAY2BGR. This adds color channels.
Fill both blanks to create a dictionary that maps color space names to their OpenCV conversion codes.
color_conversions = {
'RGB_to_HSV': [1],
'BGR_to_Gray': [2]
}The dictionary maps 'RGB_to_HSV' to cv2.COLOR_RGB2HSV and 'BGR_to_Gray' to cv2.COLOR_BGR2GRAY.
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.
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}The dictionary comprehension filters conversion codes that are exactly equal to grayscale conversion codes using ==.