Bird
0
0

You want to apply a Gaussian filter to each color channel of an RGB image separately. Which code correctly does this?

hard📝 Application Q9 of 15
SciPy - Image Processing (scipy.ndimage)
You want to apply a Gaussian filter to each color channel of an RGB image separately. Which code correctly does this?
Aresult = gaussian_filter(img, sigma=[2,2,2])
Bresult = gaussian_filter(img, sigma=2)
Cresult = gaussian_filter(img, sigma=2, axis=2)
Dresult = np.stack([gaussian_filter(img[:,:,i], sigma=2) for i in range(3)], axis=2)
Step-by-Step Solution
Solution:
  1. Step 1: Understand filtering per channel

    Applying gaussian_filter directly to 3D image blurs across channels, which is usually undesired.
  2. Step 2: Check each option

    result = np.stack([gaussian_filter(img[:,:,i], sigma=2) for i in range(3)], axis=2) applies filter separately to each channel and stacks results, preserving channel info. result = gaussian_filter(img, sigma=2) filters all channels together. result = gaussian_filter(img, sigma=[2,2,2]) sets sigma per dimension including channels, blurring across color channels. result = gaussian_filter(img, sigma=2, axis=2) uses non-existent axis parameter.
  3. Final Answer:

    result = np.stack([gaussian_filter(img[:,:,i], sigma=2) for i in range(3)], axis=2) -> Option D
  4. Quick Check:

    Filter channels separately = C [OK]
Quick Trick: Filter each channel separately, then stack [OK]
Common Mistakes:
  • Filtering all channels together
  • Passing sigma as list
  • Using invalid parameters

Want More Practice?

15+ quiz questions · All difficulty levels · Free

Free Signup - Practice All Questions
More SciPy Quizzes