thephpleague / color-extractor

Extract colors from an image like a human would do.
thephpleague.com
MIT License
1.3k stars 159 forks source link

Is this a minor error of lightness normalization into colors' sort? #80

Open nzamulov opened 5 months ago

nzamulov commented 5 months ago

Hello,

according to the article about CIELAB color space from your code: https://github.com/thephpleague/color-extractor/blob/master/src/ColorExtractor.php#L275 https://en.wikipedia.org/wiki/CIELAB_color_space

area of definition of lightness param (L*/Lstar) is [0:100], where 0 - black, 100 - white. But in colors' sorting algorithm https://github.com/thephpleague/color-extractor/blob/master/src/ColorExtractor.php#L58

you have follow lightness normalization: (1 - $labColor['L'] / 200)

If we follow strict classical mathematical rules about any kind of normalization, lightness normalization in your code must be looks like: (1 - $labColor['L'] / 100)

It turns out that you have an extra 1/2 constant for lightness normalization. I understand that it is not cause any problem with correctness of sort algorithm itself, because you multiply EACH lightness value by this constant and this is why it is still correct. But I do not understand why do you divide L param by 200, not by 100?