A color mask for a robot camera can miss visually similar red pixels on opposite sides of the hue scale. Increasing one ordinary interval until it covers both ends can create the opposite mistake: admitting nearly the entire hue circle.

The issue is the shape of the selection region. A short arc that crosses a circular coordinate's seam appears as two intervals when the circle is printed as a straight numeric range. A conventional channel-by-channel interval comparison does not join those ends automatically.

OpenCV's 4.12.0 colorspace tutorial documents ordinary eight-bit HSV ranges, while its inRange reference defines inclusive channel bounds. The masks and pixel tuples below are original analytic examples. They are not captured camera data, an executed OpenCV test, or thresholds validated for a real inspection task.

State the encoding first

Use ordinary eight-bit HSV associated with COLOR_BGR2HSV: hue H runs from 0 through 179, while saturation S and value V run from 0 through 255. Treat hue as a 180-step circle, with neighboring codes 179 and 0 adjacent across its seam.

This convention must travel with the numbers. Hue printed in degrees, floating-point HSV, and conversion modes using another range cannot inherit these bounds unchanged. The incoming color-channel order also matters: interpreting an RGB buffer as BGR changes what the conversion represents.

The example starts from already-declared HSV tuples. It does not predict the exact quantized output for unspecified RGB pixels, lighting, camera processing, or conversion implementations.

Build a circular hue selection

Invent a desired hue center of code zero and a circular tolerance of six codes. For a code h, define circular distance from zero as d = min(h, 180 − h).

The condition d ≤ 6 selects codes 0 through 6 and 174 through 179. The lower group contains seven codes; the upper group contains six. Together they select 13 hue codes, including the center and six steps on either side.

The count is deliberately discrete. Code 180 is not an additional distinct hue code in this representation. Counting both zero and a fictitious terminal 180 as separate centers would count the seam twice.

In an ideal angle interpretation with two degrees per hue step, this is a circular neighborhood extending approximately 12 degrees to either side of zero. The mask is still defined in codes, not as a statement about a material's measured spectral response.

Why one ordinary range fails

Suppose a developer supplies lower hue 174 and upper hue 6 to an ordinary interval comparison. That comparison asks for h ≥ 174 and h ≤ 6 simultaneously. No code can satisfy both inequalities.

The function has not been asked to interpret a circular interval. Its documented operation is a box comparison in channel coordinates. Reversing the bounds therefore cannot express wrapping.

Swapping the values to lower hue 6 and upper hue 174 creates a valid but different interval. It selects 169 codes and rejects most of the small neighborhood originally intended near the seam. A numerically ordered range can still express the wrong region.

The two intended intervals should instead become two masks combined by logical union. In OpenCV's binary-mask convention, a bitwise OR performs that union when each input mask contains zero or 255.

Include saturation and value deliberately

For this invented example, also require S from 80 through 255 and V from 60 through 255. Define mask A with lower tuple (0, 80, 60) and upper tuple (6, 255, 255).

Define mask B with lower tuple (174, 80, 60) and upper tuple (179, 255, 255). The final mask is A OR B. A pixel passes if every channel satisfies one complete box or every channel satisfies the other.

These S and V limits are hypothetical values used to expose the logic. They are not recommended settings for red parts or a guarantee of robustness under changing illumination.

Keeping those limits identical in both boxes is intentional. If the second box accidentally admitted all saturation values, low-saturation pixels at that end of the hue range could pass under a different rule.

Check concrete tuples

Pixel P = (178, 150, 200) passes B. Pixel Q = (3, 150, 200) passes A. Their circular hue separation is five codes even though subtracting their displayed H values gives 175.

Pixel R = (90, 150, 200) fails both hue intervals. Pixel U = (2, 20, 200) has an accepted hue but fails the saturation requirement. Pixel W = (178, 150, 40) fails the value requirement.

Boundary pixels (6, 80, 60) and (174, 80, 60) both pass because the reference defines inclusive lower and upper bounds. A comparison using strictly greater or strictly less would give a different mask at those edges.

An AND between masks A and B would reject every pixel in this construction because their hue intervals are disjoint. The OR is part of the region definition, not a cosmetic implementation choice.

A selected color is not an identified object

Even a logically correct hue mask can include multiple separate objects and scattered pixels. It identifies a set of pixel codes satisfying a rule. It does not, by itself, establish which connected region belongs to a robot target.

Likewise, a selected region does not establish physical dimensions, distance, material identity, or whether the visible part is acceptable. Those conclusions require additional models and evidence beyond the color predicate.

Near zero saturation, hue has little chromatic meaning; for exactly equal color channels, a conversion must still produce some encoded hue value. Saturation gating can reject part of that ambiguity, but its numerical choice needs evidence from the intended images.

Retain the transformation and the predicate

A reproducible mask description includes input channel order, conversion mode and data type, both hue intervals, saturation and value conditions, bound inclusivity, and the union rule. Retaining the resulting mask alone loses those choices.

The seam is a property of the coordinate encoding. Expressing a wrapping neighborhood as two numeric boxes lets ordinary comparisons represent it correctly, while keeping object interpretation as a separate question.

Sources checked October 23, 2026: OpenCV 4.12.0, Changing Colorspaces, ordinary HSV channel ranges: https://docs.opencv.org/4.12.0/df/d9d/tutorial_py_colorspaces.html

OpenCV 4.12.0, Operations on Arrays, inRange inclusive bounds: https://docs.opencv.org/4.12.0/d2/de8/group__core__array.html

Illustration note: A generic robot vision image may accompany this explanation. It does not show the invented HSV tuples, a measured color mask, or a validated detection installation.