Bird
0
0

You have a color image loaded as a NumPy array in BGR format. How do you correctly display it in matplotlib?

hard📝 Application Q8 of 15
Matplotlib - Image Display
You have a color image loaded as a NumPy array in BGR format. How do you correctly display it in matplotlib?
AConvert BGR to RGB using array slicing, then use <code>plt.imshow()</code>
BDisplay directly with <code>plt.imshow()</code> without conversion
CConvert BGR to grayscale before displaying
DUse <code>plt.plot()</code> to show the image
Step-by-Step Solution
Solution:
  1. Step 1: Understand color format difference

    OpenCV loads images in BGR, but matplotlib expects RGB for correct colors.
  2. Step 2: Convert BGR to RGB

    Swap the first and third channels using slicing: img_rgb = img[:,:,::-1].
  3. Step 3: Display with plt.imshow()

    Use plt.imshow(img_rgb) to show the image with correct colors.
  4. Final Answer:

    Convert BGR to RGB using array slicing, then use plt.imshow() -> Option A
  5. Quick Check:

    BGR to RGB conversion = Correct color display [OK]
Quick Trick: Swap BGR channels to RGB before displaying [OK]
Common Mistakes:
  • Displaying BGR image directly causing wrong colors
  • Converting to grayscale unnecessarily
  • Using plt.plot() for images

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes