Binarization is the process of converting a multi-level grayscale image to a binary image where each pixel is assigned one of two values—typically 0 (black) for the background and 1 (white) for the foreground—based on a defined intensity threshold value. This transformation simplifies the image data structure, eliminating intensity variations to create a stark contrast that makes objects of interest immediately distinguishable from their surroundings for subsequent blob analysis.
Glossary
Binarization

What is Binarization?
Binarization is the foundational preprocessing step that converts a grayscale image into a binary black-and-white image, enabling precise separation of foreground defects from the background for quantitative analysis.
The critical parameter is the threshold selection method. Global thresholding applies a single, fixed intensity cutoff across the entire image, which is computationally efficient but fails under non-uniform lighting. Adaptive thresholding calculates a local threshold for each pixel based on the statistics of its surrounding neighborhood, making it robust against shadows and illumination gradients common on factory floors. Otsu's method automatically determines the optimal global threshold by minimizing intra-class intensity variance, a crucial capability for automating high-speed automated optical inspection systems without manual calibration.
Key Characteristics of Binarization
Binarization is the critical thresholding operation that converts a grayscale image into a binary black-and-white representation, separating foreground defects from the background for downstream analysis.
Global Thresholding
A single, fixed intensity value is applied to every pixel in the image. If a pixel's intensity is above the threshold, it is set to white (foreground); otherwise, it is set to black (background). This method is computationally fast and ideal for scenes with uniform, controlled illumination. The optimal threshold is often determined by analyzing the image's histogram to find the valley between the background and foreground peaks.
Adaptive Thresholding
The threshold value is calculated dynamically for each pixel based on the intensity statistics of its local neighborhood. This is essential for images with non-uniform lighting or varying backgrounds. Common methods include:
- Mean: Threshold is the mean of the local block.
- Gaussian: Threshold is a weighted sum of the local block, giving more importance to central pixels. This prevents over-segmentation in shadowed regions and under-segmentation in brightly lit areas.
Otsu's Method
An automatic, unsupervised algorithm that determines the optimal global threshold by minimizing the intra-class intensity variance between the foreground and background pixels. It exhaustively searches for the threshold that creates a bimodal histogram with the tightest clusters. This is the standard first-pass approach when the defect-to-background contrast is high and the lighting is stable, removing the need for manual threshold tuning.
Binary Morphology
Post-processing operations applied to the binary image to clean up noise and refine defect shapes before measurement. Key operations include:
- Erosion: Removes pixels at object boundaries, useful for eliminating small, spurious white noise.
- Dilation: Adds pixels to object boundaries, useful for filling small holes within a detected defect.
- Opening: Erosion followed by dilation, which smooths contours and breaks narrow isthmuses.
- Closing: Dilation followed by erosion, which fuses narrow breaks and fills gaps.
Blob Analysis Input
The binary image serves as the direct input for Connected Component Analysis and Blob Analysis. Once the image is binarized, the system identifies contiguous groups of white pixels (blobs) and extracts quantitative features such as area, perimeter, centroid, bounding box, and circularity. The accuracy of these downstream measurements is entirely dependent on the quality of the binarization step; a poor threshold directly corrupts defect size and shape metrics.
Inverse Binary Thresholding
A variation where pixels above the threshold are set to black and pixels below are set to white. This is used when the objects of interest (defects) are darker than the background. For example, a black carbon inclusion on a bright metal surface would require inverse binary thresholding to represent the defect as the white foreground for standard blob analysis tools.
Frequently Asked Questions
Clear, technical answers to the most common questions about image binarization, thresholding algorithms, and their critical role in automated quality inspection pipelines.
Binarization is the process of converting a grayscale or color image into a binary image where each pixel is assigned one of exactly two values—typically black (0) for the background and white (1 or 255) for the foreground. This transformation is achieved by applying a threshold value to the pixel intensities: every pixel with an intensity above the threshold becomes white, and every pixel below becomes black. The fundamental operation is if pixel > threshold then 1 else 0. Binarization is a critical preprocessing step in computer vision pipelines because it dramatically simplifies subsequent analysis by separating objects of interest from their background, enabling efficient blob analysis, contour detection, and morphological operations. In manufacturing quality inspection, binarization isolates surface defects, scratches, or contaminants from the product surface, allowing algorithms to measure defect area, perimeter, and circularity without the computational overhead of processing full grayscale information.
Enabling Efficiency, Speed & Accuracy
Intelligent Analysis, Decision & Execution
We build AI systems for teams that need search across company data, workflow automation across tools, or AI features inside products and internal software.
Talk to Us
Search across company data
Give teams answers from docs, tickets, runbooks, and product data with sources and permissions.
Useful when people spend too long searching or get different answers from different systems.

Automate internal workflows
Use AI to route work, draft outputs, trigger actions, and keep approvals and logs in place.
Useful when repetitive work moves across multiple tools and teams.

Add AI to products and internal tools
Build assistants, guided actions, or decision support into the software your team or customers already use.
Useful when AI needs to be part of the product, not a separate tool.
Related Terms
Binarization is a foundational step in the computer vision pipeline. The following concepts are critical for understanding how binary images are generated, optimized, and utilized for defect detection.
Otsu's Method
An automatic clustering-based image thresholding algorithm that assumes the image contains two classes of pixels (foreground and background). It calculates the optimum threshold separating these two classes so that their intra-class variance is minimal. This is a non-parametric, unsupervised method, meaning it requires no prior knowledge of the image. It is highly effective for images with bimodal histograms but can fail if the defect is extremely small relative to the background or if illumination is non-uniform.
Adaptive Thresholding
Unlike global methods that apply a single threshold to the entire image, adaptive thresholding calculates a local threshold for each pixel based on a small neighborhood region around it. This is essential for correcting non-uniform illumination, such as vignetting or shadows on a curved metallic surface.
- Mean Thresholding: Uses the mean of the neighborhood area.
- Gaussian Thresholding: Uses a weighted sum of neighborhood values where weights are a Gaussian window. This method prevents a single bright pixel from skewing the local threshold.
Morphological Operations
A set of non-linear operations applied to binary images to remove noise, isolate individual elements, and join disparate elements. They operate by probing an image with a small shape called a structuring element.
- Erosion: Removes pixels on object boundaries, useful for eliminating small white noise spots.
- Dilation: Adds pixels to object boundaries, useful for filling small holes within a defect.
- Opening: Erosion followed by dilation; removes small objects without significantly changing the area of larger objects.
- Closing: Dilation followed by erosion; fills small holes and gaps without significantly changing the area.
Histogram Analysis
The pixel intensity histogram is the primary tool for determining a binarization threshold. It plots the number of pixels for each tonal value (0-255). A bimodal histogram features two distinct peaks representing the dark background and the bright foreground (or vice versa), with the ideal global threshold located in the valley between them. If the histogram is unimodal or multimodal, global thresholding will fail, necessitating adaptive or multi-level techniques.
Connected Components Labeling
An algorithmic application of graph theory that scans a binary image and groups its pixels into components based on pixel connectivity. Once binarization separates the foreground from the background, this operation assigns a unique integer label to each distinct blob (connected group of white pixels). This is the direct bridge between a raw binary image and blob analysis, enabling the extraction of discrete defect measurements like area, perimeter, and centroid coordinates.
Sauvola Thresholding
A specific local thresholding technique designed for text and document binarization, but highly effective for detecting fine scratches or text on manufactured parts. It calculates the threshold using the local mean and standard deviation: T = m * (1 + k * (s/R - 1)), where m is the local mean, s is the local standard deviation, R is the dynamic range of the standard deviation, and k is a user-defined sensitivity parameter. It excels at preserving fine details against a varying background.

About the author
Prasad Kumkar
CEO & MD, Inference Systems
Prasad Kumkar is the CEO & MD of Inference Systems and writes about AI systems architecture, LLM infrastructure, model serving, evaluation, and production deployment. Over 5+ years, he has worked across computer vision models, L5 autonomous vehicle systems, and LLM research, with a focus on taking complex AI ideas into real-world engineering systems.
His work and writing cover AI systems, large language models, AI agents, multimodal systems, autonomous systems, inference optimization, RAG, evaluation, and production AI engineering.
Partnered with leading AI, data, and software stack.
How We Work
Custom AI workflows for your Business
One-fit-all AI don't work for modern businesses. At Inferensys, we aim to understand your business & custom requirements; which we use to define most efficient agentic workflows, the data, and the tools for your business.
01
Review the use case
We understand the task, the users, and where AI can actually help.
Read more02
Pick the right approach
We define what needs search, automation, or product integration.
Read more03
Build the first useful version
We implement the part that proves the value first.
Read more04
Improve from there
We add the checks and visibility needed to keep it useful.
Read moreThe first call is a practical review of your use case and the right next step.
Talk to Us