Bird
Raised Fist0
Computer Visionml~20 mins

Blurring and smoothing (Gaussian, median, bilateral) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style10 modes available

Start learning this pattern below

Jump into concepts and practice - no test required

or
Recommended
Test this pattern10 questions across easy, medium, and hard to know if this pattern is strong
Challenge - 5 Problems
🎖️
Blur Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of Gaussian Blur on a simple image array
Given the following 3x3 grayscale image array and applying a Gaussian blur with kernel size 3 and sigma 1, what is the center pixel value after blurring?
Computer Vision
import cv2
import numpy as np

image = np.array([[10, 20, 30],
                  [20, 30, 40],
                  [30, 40, 50]], dtype=np.uint8)

blurred = cv2.GaussianBlur(image, (3, 3), 1)
center_pixel = blurred[1, 1]
print(center_pixel)
A30
B28
C29
D31
Attempts:
2 left
💡 Hint
Gaussian blur smooths pixels weighted by a Gaussian kernel; center pixel is a weighted average.
🧠 Conceptual
intermediate
1:30remaining
Effect of median blur on salt-and-pepper noise
Which statement best describes the effect of applying a median blur filter on an image corrupted with salt-and-pepper noise?
AMedian blur replaces each pixel with the average of its neighbors, smoothing the noise.
BMedian blur replaces each pixel with the median of its neighbors, effectively removing salt-and-pepper noise.
CMedian blur sharpens edges while reducing noise.
DMedian blur applies a Gaussian weighted average, which is ineffective against salt-and-pepper noise.
Attempts:
2 left
💡 Hint
Think about how median values handle extreme pixel values.
Model Choice
advanced
1:30remaining
Choosing the best smoothing filter for edge preservation
You want to smooth an image to reduce noise but keep edges sharp and clear. Which filter is the best choice?
ABilateral filter
BMedian blur
CGaussian blur
DAverage blur
Attempts:
2 left
💡 Hint
Consider which filter uses both spatial and intensity information.
Hyperparameter
advanced
1:30remaining
Effect of increasing sigma in Gaussian blur
What happens to the image when you increase the sigma value in a Gaussian blur filter while keeping the kernel size constant?
AThe filter ignores pixels farther from the center.
BThe image noise increases due to less smoothing.
CThe image becomes sharper with more details preserved.
DThe image becomes more blurred with stronger smoothing effect.
Attempts:
2 left
💡 Hint
Sigma controls the spread of the Gaussian kernel.
🔧 Debug
expert
2:00remaining
Identifying error in bilateral filter usage
What error will this code produce when applying bilateral filter with the given parameters? import cv2 import numpy as np image = np.ones((5,5), dtype=np.uint8)*100 blurred = cv2.bilateralFilter(image, d=0, sigmaColor=75, sigmaSpace=75) print(blurred)
Computer Vision
import cv2
import numpy as np

image = np.ones((5,5), dtype=np.uint8)*100
blurred = cv2.bilateralFilter(image, d=0, sigmaColor=75, sigmaSpace=75)
print(blurred)
ANo error, prints the blurred image array
Bcv2.error: d must be positive or -1
CTypeError: unsupported operand type(s) for *: 'int' and 'str'
DValueError: sigmaColor must be less than 50
Attempts:
2 left
💡 Hint
Check the meaning of parameter d in bilateralFilter.

Practice

(1/5)
1. Which filter is best for removing salt-and-pepper noise while preserving edges in an image?
easy
A. Bilateral filter
B. Median filter
C. Gaussian filter
D. Box filter

Solution

  1. Step 1: Understand salt-and-pepper noise characteristics

    Salt-and-pepper noise appears as random black and white pixels, which median filters handle well by replacing each pixel with the median of neighbors.
  2. Step 2: Compare filters for edge preservation

    Median filters remove noise without blurring edges, unlike Gaussian filters which blur edges, and bilateral filters which are more complex but less effective for salt-and-pepper noise.
  3. Final Answer:

    Median filter -> Option B
  4. Quick Check:

    Salt-and-pepper noise = Median filter [OK]
Hint: Median filter excels at salt-and-pepper noise removal [OK]
Common Mistakes:
  • Choosing Gaussian filter which blurs edges
  • Confusing bilateral filter with median filter
  • Using box filter which blurs noise and edges
2. Which of the following is the correct OpenCV function call to apply a Gaussian blur with a 5x5 kernel on an image stored in img?
easy
A. cv2.GaussianBlur(img, (5,5), 0)
B. cv2.medianBlur(img, 5)
C. cv2.blur(img, (5,5))
D. cv2.bilateralFilter(img, 5, 75, 75)

Solution

  1. Step 1: Identify Gaussian blur function syntax

    OpenCV's GaussianBlur requires the image, kernel size as a tuple, and sigma (0 means auto).
  2. Step 2: Match options to syntax

    cv2.GaussianBlur(img, (5,5), 0) matches the correct function and parameters for Gaussian blur with 5x5 kernel.
  3. Final Answer:

    cv2.GaussianBlur(img, (5,5), 0) -> Option A
  4. Quick Check:

    Gaussian blur syntax = cv2.GaussianBlur(img, (5,5), 0) [OK]
Hint: GaussianBlur uses tuple kernel size and sigma parameter [OK]
Common Mistakes:
  • Using medianBlur for Gaussian blur
  • Passing kernel size as single integer instead of tuple
  • Confusing bilateralFilter parameters
3. What will be the effect of applying a bilateral filter with parameters d=9, sigmaColor=75, sigmaSpace=75 on a noisy image?
medium
A. Sharpens edges and increases noise
B. Blurs the entire image uniformly
C. Removes only salt-and-pepper noise
D. Smooths noise while preserving edges

Solution

  1. Step 1: Understand bilateral filter parameters

    d controls neighborhood size; sigmaColor controls color similarity; sigmaSpace controls spatial closeness. Together they smooth noise but keep edges sharp.
  2. Step 2: Analyze filter effect on noisy image

    Bilateral filter smooths noise while preserving edges, unlike Gaussian which blurs edges or median which targets salt-and-pepper noise.
  3. Final Answer:

    Smooths noise while preserving edges -> Option D
  4. Quick Check:

    Bilateral filter = noise smoothing + edge preservation [OK]
Hint: Bilateral filter smooths noise but keeps edges sharp [OK]
Common Mistakes:
  • Thinking bilateral filter blurs edges
  • Confusing bilateral with median filter
  • Assuming it only removes salt-and-pepper noise
4. You applied a median filter with kernel size 3 on an image but the noise is still visible. What is the likely mistake?
medium
A. Median filter does not remove noise
B. Kernel size must be even number
C. Kernel size is too small to remove noise effectively
D. Median filter blurs edges too much

Solution

  1. Step 1: Understand median filter kernel size effect

    Small kernel sizes may not cover enough pixels to remove noise effectively.
  2. Step 2: Identify correct kernel size usage

    Median filter kernels must be odd-sized and larger kernels remove more noise but may blur details.
  3. Final Answer:

    Kernel size is too small to remove noise effectively -> Option C
  4. Quick Check:

    Increase kernel size for better noise removal [OK]
Hint: Use larger odd kernel sizes for stronger noise removal [OK]
Common Mistakes:
  • Using even kernel sizes (invalid)
  • Expecting median filter to blur edges heavily
  • Thinking median filter can't remove noise
5. You want to denoise a photo with both Gaussian noise and preserve sharp edges of objects. Which sequence of filters should you apply for best results?
hard
A. Apply Gaussian blur first, then bilateral filter
B. Apply median filter first, then Gaussian blur
C. Apply bilateral filter first, then median filter
D. Apply median filter only

Solution

  1. Step 1: Understand noise types and filter strengths

    Gaussian noise is best reduced by Gaussian blur; bilateral filter preserves edges while smoothing remaining noise.
  2. Step 2: Determine filter order for best effect

    Applying Gaussian blur first reduces Gaussian noise; then bilateral filter smooths while preserving edges, improving overall quality.
  3. Final Answer:

    Apply Gaussian blur first, then bilateral filter -> Option A
  4. Quick Check:

    Gaussian blur + bilateral filter = noise reduction + edge preservation [OK]
Hint: Use Gaussian blur then bilateral filter for noise + edges [OK]
Common Mistakes:
  • Applying median filter first which doesn't target Gaussian noise well
  • Using only one filter for mixed noise
  • Applying bilateral filter before Gaussian blur