Skip to content

VisionFrom Pixels to Steering

Color Thresholding

Keep the pixels whose color passes a test, such as red − (green + blue)/2 > T; the rest are background.

Not started Jump to practice

The simplest way to find a red ball: keep the pixels that look red and ignore the rest.

Key idea

Thresholding tests every pixel and keeps those that pass, making a black-and-white mask. A simple redness test: keep pixels where $r - \dfrac{g + b}{2} > T$ for some threshold $T$.
Slide the threshold. Too low, and the background sneaks in; too high, and the ball disappears.

Why it works

A pure red has a big red number and small green and blue. White is bright in all three, so plain "red > 150" would wrongly keep white. Subtracting the other channels asks how much more red there is, which is closer to what our eyes call red.

Worked example: Test a pixel

Pixel (200, 80, 60), $T = 60$.
  1. $(80 + 60)/2 = 70$.
  2. $200 - 70 = 130 > 60$.

Answer: It passes.

Common mistake

Setting one threshold in a bright room and being surprised when it fails in a dim one. Light changes all the numbers; many robots use color spaces such as HSV that separate color from brightness.

Practice

Pass with 3 right answers, the last 2 in a row. Each right answer earns 2 XP.

Loading practice…

Builds on

Leads to

Sources and further reading