Adaptive thresholding 2026-11-05
Adaptive thresholding uses an image threshold that varies with position, often calculated from a neighborhood around each pixel. It can help separate marks from background when illumination changes across an image. A global image thresholding rule instead uses the same threshold everywhere.[ref]
For a simple real-arithmetic local-mean model, put
where is the neighborhood mean and a fixed offset. OpenCV documents local-mean and Gaussian-weighted alternatives, with a declared neighborhood size. Its binary comparison assigns the high output value only above the threshold.[ref]
Consider a three-by-three patch with eight values of and a central value of . For ,
so the centre receives binary value zero. Adding to every intensity gives eight values of and a centre of . Now , so the centre still receives zero. A fixed threshold of would classify the two centre values differently, despite their identical contrast with their local backgrounds.
The invariance follows algebraically. If every intensity in a neighborhood increases by the same , its mean and threshold also increase by . Hence exactly when . This proves an additive-shift property of the stated model, assuming no clipping or rounding; it is not a claim about arbitrary spatial gradients or multiplicative brightness changes.
Neighborhood size and offset affect the result. A very small neighborhood can follow noise or include too little background, while a large one can span changing illumination. Integer rounding and image-edge handling must also be specified for an exact implementation comparison. The resulting binary image remains an intensity-based selection; connected-component labeling and semantic interpretation are further steps.
Binary image 2026-11-05
A binary image assigns one of two values to every pixel, commonly and or false and true. It can represent a selected region, such as marks separated from a page background, without retaining all the original brightness values. The two values express a chosen classification of pixels, not necessarily two physical colors in the original scene.
For example, define image thresholding by selecting intensities at least :
The output preserves which side of the threshold each value occupied but loses the distinction between and . Changing the threshold changes the selected region, so interpreting the result requires the selection rule as well as the image.
A binary image is useful as input to connected-component labeling. There, pixel connectivity determines whether diagonally touching selected pixels belong to the same region. SciPy's labeling operation accepts zero as background and all nonzero values as foreground; an input with several nonzero intensities is consequently treated as a foreground mask by that particular API.[ref]
Two possibilities require one bit of information per pixel in a direct packed representation. An actual array or image file can use more storage, or compression can exploit repeated patterns. Also distinguish a binary image from a label image containing several region identifiers: a label value of three need not mean brighter foreground than a label value of one.
Character segmentation 2026-11-05
Character segmentation separates an image of text into regions or hypotheses associated with individual characters. It is a specialized image segmentation problem within optical character recognition. The useful boundaries depend on the writing and imaging process: visible connected ink regions need not correspond one-to-one with characters.[ref]
For example, the dot and stem of a lowercase i can be disconnected regions belonging to one character. Two touching characters can instead form a single connected region. Connected-component labeling can locate connected regions, but counting those regions alone therefore cannot reliably count the characters.
A recognizer can compare alternative splits and merges. A degraded image of rn may admit one merged-region interpretation as m and a two-character interpretation as r followed by n. The choice depends on shape evidence, spacing and recognition context. Incorrectly committing to one region per character too early can make the correct word unavailable to later stages.
The historical Tesseract engine described by Ray Smith tests cuts when word recognition is unsatisfactory and can also associate broken pieces. Recognition thus supplies feedback about segmentation hypotheses, rather than merely accepting a fixed partition.[ref]
Character segmentation should be evaluated separately from simply matching the final text. A boundary error can cause several character edits, while a correct boundary can still receive the wrong label. Character error rate measures the resulting transcription disagreement; it does not by itself identify which stage caused it.
Connected-component labeling assigns an identifying number to each separate connected region of an image after choosing which pixels belong to the foreground and which neighboring pixels count as connected. In a binary image, interpret each foreground pixel as a vertex of a graph, with an edge for each allowed neighboring pair. Each component receives one label; background pixels receive a separate background value. The choice of pixel connectivity is part of the problem definition, not an incidental display setting.
For example, consider the binary image
If a foreground pixel connects only to foreground pixels immediately above, below, left or right, the two ones form two regions. One valid label image is . If diagonal neighbors also connect, the same input has one region, with label image . SciPy's ndimage.label treats zero as background and nonzero entries as foreground; its default two-dimensional neighborhood uses the four axial neighbors. Its neighborhood mask must be symmetric about its centre so that a connection works in both directions.[ref]
One direct algorithm scans for an unlabelled foreground pixel, starts a flood fill there and assigns a fresh label to every reachable foreground pixel. It then resumes scanning for another unlabelled region. For a fixed-size neighborhood, every pixel and a bounded number of neighbors need be inspected, giving time complexity for image pixels, with storage for labels and the pending search. Another approach records provisional labels and merges equivalent ones using a disjoint-set data structure.
The numerical labels are identifiers: swapping labels and does not change the segmentation. A single printed character can have several disconnected regions, while touching characters can share one region. Connected-component labeling therefore supplies geometric grouping for image segmentation and optical character recognition; it does not itself determine what an object means.
Flood fill 2026-11-05
Flood fill finds the region reachable from a seed pixel through allowed neighboring pixels that satisfy a membership rule, often replacing the values in that region. A paint program's fill operation is a familiar application. The seed, membership rule and pixel connectivity together specify what will be filled.
Consider the image
Start at the upper-left pixel, select values equal to one, and allow only horizontal or vertical steps. Exactly three pixels are reachable, giving replacement by nine as
With diagonal steps also allowed, all six ones are reachable and replaced. The fill is a connectivity computation, not a rule to replace every matching value everywhere.
An iterative implementation keeps pending positions in a stack, takes one position and adds eligible unvisited neighbors. Marking a position when it enters the pending collection prevents repeated insertion. This is a depth-first search of the implicit graph. For a fixed neighborhood, visiting a region of pixels takes time complexity, excluding initialization or copying of a whole image. Explicit pending and visited storage avoids relying on a deeply nested recursive call for a large region.
Membership need not require exact equality. The scikit-image flood_fill API can accept values within a specified tolerance of the original seed value, with connectivity or a supplied neighborhood footprint controlling adjacency. Comparing each candidate to the seed is different from allowing a chain of small local changes to drift arbitrarily far from the seed value.[ref]
Record visited positions independently when necessary: replacing a value by itself must not make the algorithm revisit it forever. Repeated flood fills with fresh region labels can implement connected-component labeling.
Image thresholding 2026-11-05
Image thresholding classifies pixels by comparing their intensities with a threshold, often producing a binary image. A global threshold uses the same value throughout the image; adaptive thresholding permits the threshold to depend on position and nearby intensities.[ref]
For example, define
Intensities then become . The comparison at equality matters: a rule using would instead give . OpenCV's THRESH_BINARY uses the strict greater-than rule, assigning its chosen maximum output value only above the threshold.[ref]
Threshold choice affects which distinctions survive. Two different bright intensities can become the same foreground value, while a small change near the boundary can change a pixel's classification. The resulting mask can then feed connected-component labeling, where pixel connectivity separately decides which selected pixels form a region.
A useful motivating experiment keeps one image of dark marks fixed while adding or recording a gradual illumination variation across the background. Compare a global threshold with a declared local-neighborhood rule, inspecting lost strokes and falsely selected background. OpenCV documents local mean and Gaussian-weighted rules with an offset; this addresses varying illumination rather than proving that every resulting region is a meaningful object.[ref]
A histogram can guide global selection, but intensity statistics alone do not determine semantic identity. Noise and overlapping foreground/background intensities can make every threshold imperfect. Report the input representation, comparison convention and any filtering or local-window settings so that a thresholded result can be reproduced.
Pixel connectivity 2026-11-05
Pixel connectivity specifies which neighboring pixels may be joined directly when forming paths through an image. A region is connected when its pixels can be reached through such allowed steps while remaining in the region. This makes the region a component of an implicitly defined graph.
For a two-dimensional square grid and pixel position , four-neighbor connectivity uses
restricted to positions inside the image. Eight-neighbor connectivity adds the four diagonals:
Thus four-neighbor steps cross an edge between pixel cells, while eight-neighbor steps can also pass through a corner.
The diagonal binary image
has three foreground regions under four-neighbor connectivity and one under eight-neighbor connectivity. SciPy's default two-dimensional connected-component labeling uses the four axial neighbors; a full three-by-three neighborhood also connects diagonals. Its neighborhood must encode connections in both directions.[ref]
Connectivity also affects how a boundary separates foreground from background. In a two-by-two checkerboard, allowing diagonal links for both values makes each value connected across its own diagonal. A convention that treats foreground and background differently can avoid interpreting both diagonal paths as uninterrupted planar crossings. The chosen convention should therefore accompany any claim about separate objects or enclosed regions.
A flood fill and connected-component labeling can give different answers on the same stored array solely because their pixel connectivity differs. Check the neighborhood before interpreting that disagreement as a bug or a physical change in the imaged object.