0
0
Computer Visionml~10 mins

Image thresholding (binary, adaptive, Otsu) in Computer Vision - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to apply a simple binary threshold to the grayscale image.

Computer Vision
_, binary_img = cv2.threshold(gray_img, [1], 255, cv2.THRESH_BINARY)
Drag options to blanks, or click blank then click option'
A1
B255
C0
D127
Attempts:
3 left
💡 Hint
Common Mistakes
Using 255 as threshold makes all pixels white.
Using 0 as threshold makes all pixels white.
2fill in blank
medium

Complete the code to apply adaptive mean thresholding with a block size of 11.

Computer Vision
adaptive_img = cv2.adaptiveThreshold(gray_img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, [1], 2)
Drag options to blanks, or click blank then click option'
A5
B11
C3
D7
Attempts:
3 left
💡 Hint
Common Mistakes
Using even numbers for block size causes errors.
Using too small block size may cause noisy results.
3fill in blank
hard

Fix the error in the code to correctly compute Otsu's threshold value.

Computer Vision
otsu_thresh_val, otsu_img = cv2.threshold(gray_img, 0, 255, [1] + cv2.THRESH_OTSU)
Drag options to blanks, or click blank then click option'
Acv2.THRESH_BINARY
Bcv2.THRESH_TRUNC
Ccv2.THRESH_TOZERO
Dcv2.THRESH_BINARY_INV
Attempts:
3 left
💡 Hint
Common Mistakes
Using non-binary threshold types with Otsu causes incorrect results.
Using THRESH_BINARY_INV changes foreground/background.
4fill in blank
hard

Fill both blanks to create a dictionary with threshold types and their OpenCV constants.

Computer Vision
threshold_types = {'binary': [1], 'adaptive_mean': [2]
Drag options to blanks, or click blank then click option'
Acv2.THRESH_BINARY
Bcv2.ADAPTIVE_THRESH_MEAN_C
Ccv2.THRESH_BINARY_INV
Dcv2.ADAPTIVE_THRESH_GAUSSIAN_C
Attempts:
3 left
💡 Hint
Common Mistakes
Mixing adaptive mean and Gaussian constants.
Using inverted binary threshold for 'binary' key.
5fill in blank
hard

Fill all three blanks to create a dictionary comprehension that maps image names to their thresholded images if mean pixel value is above 100.

Computer Vision
result = {name: img for name, img in images.items() if img[1]mean() [2] [3]
Drag options to blanks, or click blank then click option'
A.
B>
C100
D==
Attempts:
3 left
💡 Hint
Common Mistakes
Using '==' instead of '>' for comparison.
Missing the '.' before mean().