(Replying to PARENT post)

There is an improvement that can be made here. There is no attempt to find the brightest colour. If you look at the dark image, the brightest colours (red) stand out over and above the dark colours. Using this knowledge is an illustration technique. Notice how the red stands out on one image, a small blue line on the other?

This particular algorythm and others that I've seen don't take this into account. Depending on the image, you could also take into account the lightness and darkness to find the dominant colour however small amounts in the image.

๐Ÿ‘คbootload๐Ÿ•‘10y๐Ÿ”ผ0๐Ÿ—จ๏ธ0

(Replying to PARENT post)

Converting to LAB would give you access to the Delta E formulas.

I wrote an introduction to dE here, if you're curious: http://zschuessler.github.io/DeltaE/learn/

Check out the demo page as well, if you're on desktop: http://zschuessler.github.io/DeltaE/demos/de76-chroma-key/

The repo is public domain. Hack around with the library if you'd like!

๐Ÿ‘คzschuessler๐Ÿ•‘10y๐Ÿ”ผ0๐Ÿ—จ๏ธ0

(Replying to PARENT post)

Hmm. I wonder if converting to HSV first would change the results.
๐Ÿ‘คminikomi๐Ÿ•‘10y๐Ÿ”ผ0๐Ÿ—จ๏ธ0