Colour-space conversion
Re-express pixels in a different channel order or colour representation.
Colours depend on both channel order and the range assigned to each channel.
Rows show the first three input colours; columns show their red, green and blue values.
This example demonstrates RGB to grayscale. A BGR source needs the matching conversion code.
Weighted luminance converts three values into one. Other colour conversions preserve different properties.
Write the output channel order and representation.
Illustrative example. The stages explain the method; they are not a live OpenCV execution.
Try it on an image
Experiment at pixel level
Inspect a colour space channel. Preview normalizes that channel; native values use OpenCV units (8-bit HSV hue is 0..179).
The engine loads on your first run. Your images stay in this browser.
Scroll over either image to zoom at the pointer. Use the scrollbars to pan both views over the same relative area. Zoom is relative to the input; pixel coordinates belong to each image. Warps can change scene correspondence.
Pixel inspector RGBA · native values · matched scale · 9 × 9 output pixels
Select a pixel
Select a pixel
When to use it
Convert camera frames to grayscale, select colours in HSV, or adapt data for codecs and models.
How it works
- 01Interpret the input channels and their expected numeric range.
- 02Apply the selected colour transform.
- 03Write the output channel order and representation.
channel meaning + numeric range + transform → new representation
What to tune
The COLOR_* code defines the conversion. Canvas helpers use RGBA; native decoded images use BGR or BGRA.
Where it breaks down
BGR, RGB and RGBA are different conventions. Floating-point conversions may expect normalized ranges; a type change alone does not rescale values.
TypeScript API
Open an entry for its exact overloads, parameter descriptions, result ownership and pinned upstream source.
All of these calls execute on the CPU. Native objects need explicit disposal. See matrices and ownership and build compatibility.
Related methods
Histogram equalization
Redistribute grayscale intensities using their cumulative histogram.
CLAHE local contrast
Equalize local histograms while limiting how much a concentrated bin can amplify contrast.
Colour range masks
Keep pixels whose channel values all lie within specified lower and upper bounds.
White balance
Estimate channel gains or mappings that reduce an image’s illumination colour cast.