Complete the code to apply a simple binary threshold to the grayscale image.
_, binary_img = cv2.threshold(gray_img, [1], 255, cv2.THRESH_BINARY)
The threshold value for binary thresholding is typically set around 127 for 8-bit images. Pixels above 127 become white (255), below become black (0).
Complete the code to apply adaptive mean thresholding with a block size of 11.
adaptive_img = cv2.adaptiveThreshold(gray_img, 255, cv2.ADAPTIVE_THRESH_MEAN_C, cv2.THRESH_BINARY, [1], 2)
The block size defines the size of the neighborhood area used to calculate the threshold for adaptive thresholding. It must be an odd number, here 11.
Fix the error in the code to correctly compute Otsu's threshold value.
otsu_thresh_val, otsu_img = cv2.threshold(gray_img, 0, 255, [1] + cv2.THRESH_OTSU)
Otsu's method is combined with a binary threshold type, so cv2.THRESH_BINARY + cv2.THRESH_OTSU is correct.
Fill both blanks to create a dictionary with threshold types and their OpenCV constants.
threshold_types = {'binary': [1], 'adaptive_mean': [2]Binary threshold uses cv2.THRESH_BINARY, adaptive mean threshold uses cv2.ADAPTIVE_THRESH_MEAN_C.
Fill all three blanks to create a dictionary comprehension that maps image names to their thresholded images if mean pixel value is above 100.
result = {name: img for name, img in images.items() if img[1]mean() [2] [3]The code accesses the mean method with '.', then checks if mean is greater than 100.