Skip to content
FoundationSource checked

Thresholding

Separates pixels into groups based on whether they cross a chosen value.

Quick Facts

Compact metadata for implementation and discovery.

Category
Image Processing
Difficulty
Beginner
Family
Segmentation
Tier
Foundation
Status
Verified
Review
Source Checked
Sources
1
Formulas
1
Relationships
3
Code example
Ready
Visualization
Ready

Overview

Thresholding turns grayscale or measured pixel values into binary or labeled regions using one or more cutoff values.

Core Concepts

intensity thresholdbinary outputpixel classificationsegmentation maskpixel operationregion separationsegmentationpixel neighborhood

Quick facts

Complexity

Runtime and memory behavior at a glance.

Best

O(w h)

Average

O(w h)

Worst

O(w h)

Space

O(w h)

When to Use

  • Use it when pixel values separate cleanly around one or more cutoffs.
  • Use it for simple masks, document cleanup, or preprocessing before component labeling.
  • Use adaptive thresholding when lighting varies across the image.

When Not to Use

  • Avoid a fixed global threshold when illumination varies strongly.
  • Avoid it when texture, shape, or context is needed to separate objects.
  • Avoid thresholding without choosing the color space or channel intentionally.

What It Does

  • Compares each pixel with a threshold
  • Creates a binary or segmented image

Use Cases

  • Object masks
  • Document cleanup
  • Simple segmentation

Inputs

  • Image
  • Threshold value

Outputs

  • Binary or labeled image

Key Formulas (1)

Threshold rule

output = value ≥ threshold ? high : low
output = value >= threshold ? high : low

Classifies each pixel based on a cutoff value.

Pseudocode

  1. 1.Choose a threshold value
  2. 2.For each pixel:
  3. 3.Compare the pixel value to the threshold
  4. 4.Assign it to the low or high group
  5. 5.Write the result to the output

Canonical Example

Input
pixel values = [20, 120, 240], threshold = 100
Output
[0, 1, 1]
Explanation
Values above the threshold are assigned to the foreground group.

Implementation Notes

  • Choose the intensity channel or feature to threshold before processing.
  • Apply the same comparison rule to every pixel.
  • Test on small images where expected mask values are easy to inspect.

Common Pitfalls

  • Choosing a threshold that works only on one lighting condition.
  • Ignoring noise before thresholding.
  • Treating alpha, color, and grayscale values inconsistently.

Interactive Mechanism Walkthrough

Spatial Primitive & Sweep-Line Canvas

Show grayscale values becoming black or white based on a cutoff.

Thresholding mechanism walkthrough step 1 of 5
Step 1 of 5: Choose a threshold value
image-threshold

Notes

Thresholding is often a preprocessing step rather than a complete segmentation method.

Sources (1)

What each reference supports for this entry.

Digital Image Processing

Book

Image-processing textbook support for Thresholding's pixel-neighborhood operations, filtering rules, and image-analysis role.

Explore Next

Good next jumps from the relationship graph, ranked for useful discovery.

Alternative toCanny Edge Detection

Thresholding segments by intensity, while Canny detects edges from gradients.

Connected component labeling often runs on thresholded binary images.

Tags

Image ProcessingSegmentationClassic