gtaylor / python-colormath

A python module that abstracts common color math operations. For example, converting from CIE L*a*b to XYZ, or from RGB to CMYK
python-colormath.readthedocs.org
BSD 3-Clause "New" or "Revised" License
456 stars 82 forks source link

Converting RGB to LAB #69

Closed mobcdi closed 7 years ago

mobcdi commented 7 years ago

Hi,

I'm having trouble converting rgb to lab and getting the same output as online color converters when I validate it

from colormath.color_objects import XYZColor, sRGBColor,LabColor
from colormath.color_conversions import convert_color

rgb = sRGBColor(82, 103, 20)
xyz = convert_color(rgb, XYZColor)
lab = convert_color(xyz,LabColor)

These are the outputs I get when I run the code

sRGBColor(rgb_r=82.0,rgb_g=103.0,rgb_b=20.0)
XYZColor(xyz_x=35774.970599858236,xyz_y=50079.394305847025,xyz_z=8891.813639311802)
LabColor(lab_l=4259.737273603557,lab_a=-1673.389793872623,lab_b=3344.4187345102782)

But when i use color converter I get a Lab value of CIE-L*ab L
40.48337507852484 A
-20.25190041462896 B
40.96416270077111

Where am I going wrong?

hemavakade commented 7 years ago

Consider normalizing the values before feeding it inside sRGBColor or pass an additional argument is_upscaled=True and it is internally scaled down between 0-1.

 rgb = sRGBColor(color[0], color[1], color[2])

or simply,

 rgb = sRGBColor(rgb_r = color[0], rgb_g =color[1], rgb_b = color[2], is_upscaled=True)
gtaylor commented 7 years ago

Good suggestion, @hemavakade. Going to take the lack of response from @mobcdi as "This worked for me, woohoo!" and close this.

mfeif commented 7 years ago

So this means one can't make (s)rgb colors with integer values?!?

ochavezwilfredc commented 5 years ago

Considere la posibilidad de normalizar los valores antes de introducirlos dentro sRGBColoro pase un argumento adicional is_upscaled=Truey se reduce internamente entre 0-1.

 rgb = sRGBColor(color[0], color[1], color[2])

o simplemente,

 rgb = sRGBColor(rgb_r = color[0], rgb_g =color[1], rgb_b = color[2], is_upscaled=True)

Muchas gracias