← Image Processing for EveryoneToolsInVisionLearning Center
Structure and Segmentation · Lesson 10

Thresholding: Turn Intensities into a Mask

A dark screw lies on a bright table.

Watch the lesson

Thresholding: Turn Intensities into a Mask explained visually

1:22

A dark screw lies on a bright table. English captions are optional and start off. The complete transcript follows the written lesson.

Lesson overview

What you will learn

A dark screw lies on a bright table.

  1. Make the decision explicit
  2. Global versus local thresholds
  3. Check failure cases
  4. A worked example
01

Make the decision explicit

A dark screw lies on a bright inspection table. We can make a simple candidate mask by marking every pixel darker than a chosen cutoff. That binary result is easy to interpret, provided light and object intensities stay sufficiently separate.

02

Global versus local thresholds

Try a cutoff of one hundred. Values forty and ninety are marked as foreground; one hundred and ten and two hundred and twenty remain background. Now cast a shadow that brings the table from two hundred and twenty down to eighty. The same rule mistakenly calls it part of the screw. There isn't a single threshold that can fix all overlap in intensity values.

03

Check failure cases

Otsu's method chooses a global cutoff from the intensity distribution using a separation criterion. It still doesn't understand the screw. An adaptive method calculates a local cutoff and can help under uneven light, but its neighborhood size affects edges and noise. Test both on lit and shadowed examples with the original beside each mask.

04

A worked example

Keep the rule and its failure cases visible. Next, we'll clean small mask artifacts while checking that we haven't changed real object shapes.

Worked example

With a rule that marks values below 100 as foreground, the values 40, 90, 110, and 220 become foreground, foreground, background, and background. If a shadow changes the background from 220 to 80, the same rule now incorrectly includes it.

Knowledge check

Quick check: test your understanding

Try it yourself: For a document with a bright center and dark corners, explain one reason to compare global and adaptive thresholding.

Check the reasoning

A single global cutoff may lose faint central text or include dark corner backgrounds. Local thresholds may handle the illumination variation more consistently.

Does an automatically chosen threshold eliminate the need to inspect results?

No. Automatic threshold selection still depends on assumptions about the intensity distribution.

How would you solve the practice case?

A single global cutoff may lose faint central text or include dark corner backgrounds. Local thresholds may handle the illumination variation more consistently.

What does the worked example show?

With a rule that marks values below 100 as foreground, the values 40, 90, 110, and 220 become foreground, foreground, background, and background. If a shadow changes the background from 220 to 80, the same rule now incorrectly includes it.

Further reading

Digital Image Processing, 4th edition — Rafael C. Gonzalez and Richard E. Woods.

Original ToolsInVision teaching examples. Editorial approach · Suggest a correction

Accessible referenceLesson 10 transcript181 words · Video transcript · Matches the published narration and captionsOpen transcript

A dark screw lies on a bright inspection table. We can make a simple candidate mask by marking every pixel darker than a chosen cutoff. That binary result is easy to interpret, provided light and object intensities stay sufficiently separate.

Try a cutoff of one hundred. Values forty and ninety are marked as foreground; one hundred and ten and two hundred and twenty remain background. Now cast a shadow that brings the table from two hundred and twenty down to eighty. The same rule mistakenly calls it part of the screw. There isn't a single threshold that can fix all overlap in intensity values.

Otsu's method chooses a global cutoff from the intensity distribution using a separation criterion. It still doesn't understand the screw. An adaptive method calculates a local cutoff and can help under uneven light, but its neighborhood size affects edges and noise. Test both on lit and shadowed examples with the original beside each mask.

Keep the rule and its failure cases visible. Next, we'll clean small mask artifacts while checking that we haven't changed real object shapes.