Bird
0
0

Which of the following is the correct way to extract the green channel from a 3D image array named img in matplotlib?

easy📝 Syntax Q12 of 15
Matplotlib - Image Display
Which of the following is the correct way to extract the green channel from a 3D image array named img in matplotlib?
Agreen = img[2, :, :]
Bgreen = img[1, :, :]
Cgreen = img[:, 1, :]
Dgreen = img[:, :, 1]
Step-by-Step Solution
Solution:
  1. Step 1: Recall channel indexing in image arrays

    Color channels are stored in the last dimension, with red=0, green=1, blue=2.
  2. Step 2: Extract green channel correctly

    To get green, select all rows and columns, but only index 1 in the last dimension: img[:, :, 1].
  3. Final Answer:

    green = img[:, :, 1] -> Option D
  4. Quick Check:

    Green channel index = 1 [OK]
Quick Trick: Use img[:, :, 1] to get green channel [OK]
Common Mistakes:
  • Mixing up axis order and indexing rows or columns
  • Using wrong channel index for green
  • Selecting wrong dimensions

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes