Threshold
A boundary value used in image processing to classify pixel intensities into binary (black/white) or multiple classes, forming the basis of binarization and segmentation.
A threshold is a boundary value that classifies pixel intensities into discrete categories. A typical application is binarization, where each grayscale pixel is compared against the threshold and assigned white or black. Thresholding is essential in OCR preprocessing, object detection, and medical image analysis.
Common threshold determination methods:
- Fixed threshold: A manually specified value, effective under controlled lighting
- Otsu's method: Maximizes inter-class variance in the histogram to find the split point automatically. Widely used, but it assumes a roughly bimodal histogram and tends to underperform on unimodal images or when foreground and background areas are highly unbalanced
- Adaptive threshold: Computes a local threshold for each pixel from its surrounding neighborhood, handling uneven illumination
- Triangle method: Uses the maximum distance from the histogram peak-to-endpoint line, suited for unimodal distributions
OpenCV examples:
cv2.threshold(img, 127, 255, cv2.THRESH_BINARY)- Fixed at 127cv2.threshold(img, 0, 255, cv2.THRESH_BINARY + cv2.THRESH_OTSU)- Otsu's automaticcv2.adaptiveThreshold(img, 255, cv2.ADAPTIVE_THRESH_GAUSSIAN_C, cv2.THRESH_BINARY, 11, 2)
Preprocessing with Gaussian blur and histogram equalization often improves thresholding accuracy. Multi-level thresholding partitions images into three or more regions for complex scenes.