Skip to content

Convert RGB colours to HSI and find the distance between two colours in the HSI colour space

License

Notifications You must be signed in to change notification settings

DrNickRedfern/RGB2HSI

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

12 Commits
 
 
 
 
 
 
 
 
 
 

Repository files navigation

RGB2HSI

This repository contains two Python functions:

  • RGB2HSI: convert RGB colour values to HSI
  • deltaHSI: find the distance between two colours in HSI colour space

These functions are based on Koschan and Abidi (2008: 58-60, 63-64).

HSI colourspace

The HSI colour model represents colour as hue (H), saturation (S), and intensity (I).

(Cao, Zhu, Zhao, Liu, & Gao (2019) CC-BY 4.0)

The hue describes the dominant colour represented as an angle in the range [0, 360], where red is 0°, yellow is 60°, green is 120° cyan is 180°, blue is 240°, and magenta is 300°.

The saturation is the realtive purity of the colour and depends on the amount of white light present, and has the range [0, 100].

The intensity ranges from black (0) to White (100).

RGB2HSI

RGB2HSI converts RGB colour values to HSI using the following equations:

  if    and    if  , where

 .

RGB2HSI expects as input a tuple of RGB colour values. For example, to convert the RGB colour to HSI:

RGB2HSI((100, 150, 200))

returns the tuple (210, 33.3, 150).

deltaHSI

For two colours and in HSI colour space, the distance between them is given by

,

where

and , with

  if    and    if  .

deltaHSI calculates this distance for two HSI colours entered as tuples. For example, where and we can determine the distance betwen them using

deltaHSI((210, 33.3, 150), (139, 57.1, 117))

which returns the result 81.45.

References

Cao, P., Zhu, Y., Zhao, W., Liu, S., & Gao, H. (2019) Chromaticity measurement based on the image method and its application in water quality detection, Water 11 (11): 2339. https://doi.org/10.3390/w11112339.

Koschan, A., and Abidi, M. (2008) Digital Color Image Processing. Hoboken, NJ: John Wiley & Sons.

About

Convert RGB colours to HSI and find the distance between two colours in the HSI colour space

Topics

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages