User Rating 0.0
Total Usage 0 times
Drop an image here or click to upload PNG, JPG, BMP, WebP — max 50 MB
Is this tool helpful?

Your feedback helps us improve.

About

Image binarization converts a continuous-tone photograph into a strict two-level (black and white) representation. The process hinges on mapping each pixel's luminance L to either 0 or 255 based on a decision boundary T. Getting that boundary wrong destroys information: set T too low and fine detail drowns in white; set it too high and shadow regions collapse into solid black. This tool implements four production-grade methods. Global thresholding applies a single user-defined T. Otsu's method computes the statistically optimal T by maximizing inter-class variance across the full histogram. Adaptive mean thresholding calculates a local T per pixel using a sliding window, critical for unevenly lit documents. Floyd-Steinberg dithering diffuses quantization error to neighboring pixels, preserving perceived tonal gradation without halftone screens.

Luminance is derived via the ITU-R BT.601 standard: L = 0.299R + 0.587G + 0.114B. This weighting reflects human photopic sensitivity, not a naive average. The tool approximates ideal results under uniform illumination. For documents with strong lighting gradients (e.g., phone-captured receipts), adaptive thresholding will outperform global methods. Note: processing occurs entirely in-browser via the Canvas API. No image data leaves your device.

binarize image image thresholding otsu method floyd-steinberg dithering black and white converter adaptive threshold image processing

Formulas

The luminance of each pixel is computed using ITU-R BT.601 luma coefficients:

L = 0.299 R + 0.587 G + 0.114 B

For global thresholding, the output pixel P′ is:

P= {
255 if L T0 otherwise

Otsu's method selects T by maximizing inter-class variance σB2:

σB2(T) = ω0(T) ω1(T) [μ0(T) μ1(T)]2

where ω0, ω1 are the class probabilities (fraction of pixels below/above T) and μ0, μ1 are the class means.

For adaptive mean thresholding, the local threshold at pixel (x, y) is:

T(x, y) = 1W2 (i,j) ∈ N L(i, j) C

where N is the W × W neighborhood and C is a constant offset (typically 2 - 15). The sum is computed in O(1) per pixel using an integral image (summed-area table).

Floyd-Steinberg dithering distributes quantization error e = L P′ to four neighbors:

eright = 716 e,   ebelow-left = 316 e,   ebelow = 516 e,   ebelow-right = 116 e

where R is the red channel, G green, B blue, L is computed luminance, T is the threshold value, P′ is the binarized output pixel, e is quantization error, W is the adaptive window size (odd integer), and C is the adaptive offset constant.

Reference Data

MethodTypeBest ForParametersTime ComplexityEdge Handling
Global ThresholdFixedHigh-contrast images, logosT ∈ [0, 255]O(n)None
Otsu's MethodAutomaticBimodal histograms, scanned docsNone (auto)O(n + 256)None
Adaptive MeanLocalUneven lighting, photos of textWindow W, Offset CO(n)Mirror padding
Floyd-SteinbergDitheringPhotographs, gradients, artT ∈ [0, 255]O(n)Boundary clamp
NiblackLocalDegraded documentsW, kO(n)Mirror padding
SauvolaLocalStained/aged paperW, k, RO(n)Mirror padding
BernsenLocalVariable contrast regionsWO(nW2)Zero padding
Mean (Simple)FixedQuick previewNone (auto)O(n)None
MedianFixedSymmetric histogramsNone (auto)O(n)None
TriangleAutomaticUnimodal histogramsNone (auto)O(n + 256)None
Ordered Dither (Bayer)DitheringRetro/pixel artMatrix sizeO(n)Tile wrap
AtkinsonDitheringClassic Mac aestheticsTO(n)Boundary clamp
StuckiDitheringSmoother gradientsTO(n)Boundary clamp

Frequently Asked Questions

Use Adaptive Mean thresholding. Global and Otsu methods assume uniform illumination. When a camera flash or window light creates a gradient across the page, a single threshold will bleach one side and darken the other. Adaptive Mean computes a local threshold per pixel using a surrounding window. Set the window size to roughly 1/8 of the image width (e.g., W = 51 for a 400px-wide image) and start with an offset C of 10. Increase C if background noise appears as black speckles.
Otsu's algorithm assumes the histogram is bimodal - two distinct peaks representing foreground and background. When the histogram has a single dominant peak (e.g., a mostly white page with thin black text occupying less than 5% of pixels), the inter-class variance has no clear maximum. The selected threshold becomes unstable and often clips too aggressively. In such cases, use global thresholding with manual T adjustment or switch to adaptive methods.
Simple thresholding discards all sub-threshold luminance information. A pixel at L = 124 with T = 128 becomes pure black, identical to L = 0. Floyd-Steinberg dithering carries the quantization error (128 − 124 = 4) forward to adjacent pixels, slightly brightening them. Over a region, the average density of black vs. white dots approximates the original grayscale gradient. This creates the illusion of continuous tone at normal viewing distance, which is critical for photographic content.
A naive implementation of adaptive mean thresholding with window size W requires O(n × W²) operations, which becomes prohibitive for large images (e.g., a 4000×3000 image with W = 101 would require ~1.2 trillion operations). This tool uses an integral image (summed-area table), which precomputes cumulative sums in a single O(n) pass. Each window sum then requires exactly 4 lookups regardless of W, reducing total complexity to O(n). A 12-megapixel image processes in under 200ms on modern hardware.
The tool composites transparent regions against a white background before binarization. A pixel with alpha = 0 will be treated as white (L = 255). Semi-transparent pixels are blended: effective R = α × R + (1 − α) × 255. This matches the visual appearance in most viewers. If you need to preserve transparency, pre-process the alpha channel separately. The downloaded output is always an opaque PNG with no alpha channel.
The window size W must be odd to ensure symmetric neighborhood around the center pixel. If you enter an even number, the tool automatically increments it by 1. For example, W = 50 becomes W = 51. Using an even window would offset the neighborhood center by half a pixel, introducing directional bias in the thresholding that manifests as subtle edge shifts.