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

convert RGB to lab, the result looks very strange, it seems wrong. #71

Closed lx1054331851 closed 7 years ago

lx1054331851 commented 7 years ago

below is my code and the results, I don't no whether I write the wrong code, help!

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

rgb = sRGBColor(244, 55, 66)

xyz = convert_color(rgb, XYZColor, through_rgb_type=sRGBColor)

print(xyz.xyz_x, xyz.xyz_y, xyz.xyz_z)
# result: (203201.9917460821 111379.08009724967 30202.181100844653)

lab = convert_color(xyz, LabColor, through_rgb_type=sRGBColor)

print(lab.lab_l, lab.lab_a, lab.lab_b) 
# result: (5565.1778859096485 5840.582567869284 3568.530135463184)
MichaelMauderer commented 7 years ago

By default sRGBColor takes arguments in the range 0...1. If you need it to take arguments in the range 0...255 you need to set the optional argument is_upscaled=True.