Public Lab Research note

computer vision color detection

by MaggPi |

Read more:


Several digital camera applications such as spectroscopy or Normalized Difference Vegetation Index (NDVI) measurements benefit from being able to automatically detect image color patterns. This research note describes computer vision software (OpenCV/python) that can measure color characteristics of an image. Two different examples illustrate how color detection can be used. The first application is a spectrum generated by a crossed grating/white light LED. The second application uses a NDVI image obtained from .

Computer vision color detection: Color detection using computer vision techniques is described in and in

A video walk thru is available at:

Python/OpenCV software ( ) developed to implement these techniques is described below:

--1: Color input image is loaded into the program

--2a. Image is scaled and converted to Hue, Saturation, Value (HSV) colorspace. See for more info on HSV.

--2b. Trackbars are created with lower/ upper colorspace options,

--2c. Image, image mask and trackbars are displayed.

--2d. Mask is overlayed with imaged showing color selection. User selects color range with H,S,V trackbars.

--3a. H,S,V values indicate selected color. Note OpenCV HSV colorspace range is H: 0 - 180, S: 0 - 255, V: 0 – 255.

A video demonstartion of sorting the color red is posted at:

image description!

Spectroscopy Example:

A crossed grating arrangement was used to observe multiple diffraction orders across a wide range of signal levels. A crossed grating was made by combining two transmission gratings at right angles.

image description

The picture below demonstrates red/green/yellow/blue color detection for a white light LED /crossed grating spectrum.

image description

The picture below is a close up of the red color pattern described above. Note color contours around saturated pixels that are difficult to observe in the multicolor input image.

image description

NDVI example:

The picture below shows color detection applied to a NDVI image. Red indicates healthy plant life.

image description


Two examples demonstrate how color detection can be used to isolate HSV patterns/ranges. The ability to detect and isolate colors can be used to guide image analysis and establish colorspace values for automated computer vision identification.

Software code posted at:

@warren, @icarito, @amirberAgain

ndvi raspberry-pi color computer-vision opencv gsoc-2018 color-detection



You must be logged in to comment.