Color distance🔗

Transforms input image into a gray-level image. The intensity of each pixel in the output image reflects the distance between a reference color and the color of the pixel in the RGB color space. The lower the intensity, the closer the pixel matches the reference color. If the invert flag is true, higher intensity means closer match. If the input is a gray-level image, all color channels are assumed to be identical and equal to the intensity of each pixel.


  • image: Input image.

  • referenceColor: The color to which differences are calculated.

  • invert: Inversion flag. If this value is true, smaller intensity in the output image indicates greater color distance. If invert is true, 255 indicates a perfect match.

  • normalize: Color intensity normalization flag. If this value is true, intensities of the RGB components of both the reference color and colors of the pixels in the input image are normalized before distance calculation. The removes the effect of varying brightness due to e.g. uneven lighting or light drop-off towards the edge of the field of view. This flag has no effect if the input is a gray-level image.


  • image: Absolute color distances. If invert is false, lower intensity means shorter distance to referenceColor. If invert is true, brighter intensity means a better match.