0
0
Computer Visionml~20 mins

Image thresholding (binary, adaptive, Otsu) in Computer Vision - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Image Thresholding Master
Get all challenges correct to earn this badge!
Test your skills under time pressure!
Predict Output
intermediate
2:00remaining
Output of binary thresholding with OpenCV
What is the shape and unique values of the output image after applying binary thresholding with threshold=127 on a grayscale image of shape (100, 100) with pixel values ranging from 0 to 255?
Computer Vision
import cv2
import numpy as np
img = np.random.randint(0, 256, (100, 100), dtype=np.uint8)
_, thresh_img = cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)
unique_vals = np.unique(thresh_img)
output_shape = thresh_img.shape
print(output_shape, unique_vals)
A(100, 100, 3) and [0 255]
B(100, 100) and [0 255]
C(100, 100) and [0 127]
D(100, 100) and [127 255]
Attempts:
2 left
💡 Hint
Binary thresholding converts pixels to either 0 or max value based on threshold.
🧠 Conceptual
intermediate
1:30remaining
Understanding adaptive thresholding
Which statement best describes adaptive thresholding compared to global binary thresholding?
AAdaptive thresholding requires the image to be color, not grayscale.
BAdaptive thresholding uses a fixed threshold for the entire image.
CAdaptive thresholding calculates threshold for small regions, handling varying lighting.
DAdaptive thresholding always produces a binary image with only zeros.
Attempts:
2 left
💡 Hint
Think about how lighting changes across an image.
Metrics
advanced
2:00remaining
Evaluating Otsu's thresholding output
After applying Otsu's thresholding on a bimodal grayscale image, what metric best indicates the quality of the threshold?
AMaximizing inter-class variance between foreground and background
BMinimizing mean squared error of pixel intensities
CMaximizing the number of pixels set to zero
DMinimizing the image histogram entropy
Attempts:
2 left
💡 Hint
Otsu's method tries to separate two classes clearly.
🔧 Debug
advanced
2:00remaining
Identifying error in adaptive thresholding code
What error will this code raise? import cv2 import numpy as np img = np.random.randint(0, 256, (50, 50), dtype=np.uint8) thresh = cv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, 2, 5)
Acv2.error: blockSize must be odd and greater than 1
BTypeError: unsupported operand type(s) for +: 'int' and 'str'
CNo error, code runs successfully
DValueError: image must be 3-channel color
Attempts:
2 left
💡 Hint
Check the blockSize parameter requirements in adaptiveThreshold.
Model Choice
expert
2:30remaining
Choosing thresholding method for uneven lighting
You have a grayscale image with strong shadows and bright spots. Which thresholding method is best to segment the foreground accurately?
AGlobal binary thresholding with a fixed threshold
BOtsu's thresholding
CNo thresholding, use raw pixel values
DAdaptive thresholding with Gaussian weighting
Attempts:
2 left
💡 Hint
Consider how local lighting variations affect thresholding.