Bird
0
0

Which of the following is the correct syntax to extract the blue channel from a 3D numpy image array named img?

easy📝 Syntax Q3 of 15
Matplotlib - Image Display
Which of the following is the correct syntax to extract the blue channel from a 3D numpy image array named img?
Ablue_channel = img[:, :, 2]
Bblue_channel = img[2, :, :]
Cblue_channel = img[:, 2, :]
Dblue_channel = img[0, :, 2]
Step-by-Step Solution
Solution:
  1. Step 1: Understand image array dimensions

    Image arrays have shape (height, width, channels). The last dimension is color channels.
  2. Step 2: Extract blue channel

    Blue channel is index 2 in the last dimension, so use img[:, :, 2].
  3. Final Answer:

    blue_channel = img[:, :, 2] -> Option A
  4. Quick Check:

    Blue channel extraction = img[:, :, 2] [OK]
Quick Trick: Use img[:, :, 2] to get blue channel from RGB image [OK]
Common Mistakes:
  • Mixing axis order
  • Using wrong index for blue
  • Slicing rows or columns incorrectly

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More Matplotlib Quizzes