ScientiaLux
strataquest Glossary Threshold & Compare
BOM Group

Threshold & Compare

Pixel-level thresholding and comparison operations

View
Definition
Operations for converting grayscale images into binary masks — the fundamental segmentation step that separates foreground from background. Global thresholding applies a single intensity cutoff across the entire image; adaptive thresholding computes local cutoffs to handle uneven illumination. Compare operations enable pixel-by-pixel relational tests and Boolean logic for combining binary masks within BOM pipelines.
Global Thresholding
Single intensity cutoff — fast but fails with uneven illumination
Otsu's Between-Class Variance
Automatically finds the optimal separation threshold
Adaptive Thresholding
Local thresholds handle illumination gradients
Compare Operations for Mask Logic
Boolean algebra combines multiple binary masks

Operations Reference

OperationInputsOutput
Global thresholdGrayscale image + threshold valueBinary mask: pixels ≥ threshold → 1, else → 0
Adaptive thresholdGrayscale image + local statistics image + offsetBinary mask: pixels > (local_stat + offset) → 1, else → 0
Compare: A > BImage A, Image BBinary mask: 1 where A > B, 0 elsewhere
Compare: A < BImage A, Image BBinary mask: 1 where A < B, 0 elsewhere
Compare: A == BImage A, Image BBinary mask: 1 where A equals B, 0 elsewhere
Compare: A != BImage A, Image BBinary mask: 1 where A differs from B, 0 elsewhere

Note: The existing Otsu Threshold engine provides automatic optimal threshold selection. Within the BOM, manual threshold and comparison operations provide fine-grained control for custom pipeline construction.

Simplified

Global threshold: pick a brightness cutoff — everything above becomes white, below becomes black. Adaptive threshold: the cutoff varies across the image to handle uneven lighting. Compare operations check two images pixel by pixel: 'is A brighter than B here?' The output is always a binary mask.

Image Processing Foundation

Thresholding is the most fundamental segmentation operation in image processing — the point where a continuous grayscale image becomes a discrete binary decision: foreground or background. Despite its simplicity, the choice of threshold method and value profoundly affects every downstream result (Gonzalez & Woods, §10.3).

Global Thresholding & Otsu's Method

Global thresholding applies a single value T to the entire image: g(x,y) = 1 if f(x,y) ≥ T, else 0. The core assumption is histogram bimodality — foreground and background pixels form two separable peaks. Otsu's method formalizes this by finding the threshold that maximizes the between-class variance σ2B = ω0ω10 − μ1)2, where ω0, ω1 are the class probabilities and μ0, μ1 are the class means. This is equivalent to minimizing within-class variance. Otsu's method is optimal when classes have equal variances and the histogram is truly bimodal, but degrades when: (1) one class is much smaller than the other, (2) class variances differ greatly, or (3) noise fills the valley between peaks.

Adaptive Thresholding

When illumination varies across the image — common in large whole-slide scans — no single global threshold works everywhere. Adaptive thresholding computes a local threshold at each pixel from its neighborhood: T(x,y) = mean(neighborhood) + offset. The mean can be unweighted (box filter) or Gaussian-weighted (giving more influence to nearby pixels). Solomon & Breckon describe this as "the workhorse operator" of practical machine vision — a different threshold at each pixel location. The window size is a critical trade-off: too small and the threshold is noisy (responds to individual pixels rather than illumination trends); too large and it loses the ability to adapt to local conditions, approaching global behavior.

Multi-Level & Hysteresis Thresholding

Multi-level Otsu extends the method to more than two classes by maximizing the total between-class variance across multiple thresholds — useful when the histogram has three or more modes (e.g., background, cytoplasm, nuclei). Hysteresis thresholding uses two thresholds (Tlow, Thigh): pixels above Thigh are definitely foreground, pixels below Tlow are definitely background, and pixels between the two are foreground only if connected to a definite foreground pixel. This dual-threshold approach is the basis of the Canny edge detector's final stage and is available in StrataQuest's BOM through chained threshold-then-compare operations.

Compare Operations as Boolean Algebra

Binary masks are sets of pixels, and compare operations implement set operations: A > B produces the set where A exceeds B; combining masks with AND computes the intersection, OR computes the union, and XOR computes the symmetric difference. This enables construction of complex ROIs from simple threshold results — for example, (channel_A > T1) AND (channel_B < T2) selects pixels that are bright in one marker and dim in another, a common operation in multiplex immunofluorescence analysis.

Simplified

Thresholding is the simplest segmentation: pick a brightness cutoff, and everything above it becomes 'object.' Otsu's method finds this cutoff automatically by looking at the histogram's shape. When lighting is uneven across a slide, adaptive thresholding adjusts the cutoff at each location based on the local brightness — Solomon & Breckon call it 'the workhorse operator' of machine vision. Compare operations let you combine multiple binary masks using AND/OR logic to build complex regions of interest.

When to Use Which

Global Threshold

Use when illumination is uniform across the image and a single intensity value cleanly separates foreground from background. Check the histogram — if it shows two well-separated peaks with a clear valley, a global threshold at the valley works well. This is essentially manual Otsu: you pick the threshold instead of the algorithm computing it.

Adaptive Threshold

Use when illumination varies across the image (common in large whole-slide scans). The workflow: (1) Compute local mean using Statistical Operations with a large window. (2) Apply adaptive threshold: original > (local_mean + offset). The offset controls sensitivity — larger offset requires objects to be further above local background. Solomon & Breckon describe adaptive thresholding as using "a different threshold at each pixel location."

Comparison Operations

Use for relative intensity analysis between channels or between an image and a reference. Examples:

  • Channel ratio masking: A > B creates a mask where channel A is dominant
  • Difference masking: (A − B) > threshold detects significant differences between two conditions
  • Multi-threshold: chain comparisons with logical operations: (image > T_low) AND (image < T_high) creates a band-pass mask

Three Limitations (Solomon & Breckon)

Global thresholding has three fundamental limitations: (1) no guarantee that thresholded pixels are contiguous, (2) sensitivity to illumination variation, and (3) only works when foreground and background have distinct intensities. Adaptive thresholding addresses limitation 2; connected-component labeling addresses limitation 1.

Simplified

Use Global threshold when lighting is even and the histogram shows two clear peaks. Use Adaptive threshold when lighting varies — it automatically adjusts the cutoff across the image. Use Compare operations when you need to compare two channels or images pixel by pixel. For automatic threshold selection, use the Otsu Threshold engine instead.

Connected Terms

Share This Term
Term Connections