问题
This seems like such a simple problem, exactly what colormath
was designed for. But calling convert_color
appears to return the same object that was passed in. According to the documentation a failed conversion should raise a UndefinedConversionError
, not return an object.
>>> from colormath.color_objects import sRGBColor, AdobeRGBColor
>>> from colormath.color_conversions import convert_color
>>> srgb = sRGBColor(0.0, 1.0, 0.0)
>>> srgb
sRGBColor(rgb_r=0.0,rgb_g=1.0,rgb_b=0.0)
>>> argb = convert_color(srgb, AdobeRGBColor)
>>> argb
sRGBColor(rgb_r=0.0,rgb_g=1.0,rgb_b=0.0)
>>> argb is srgb
True
It does work to convert to Lab
so I'm unsure what the problem could be.
>>> from colormath.color_objects import LabColor
>>> convert_color(srgb, LabColor)
LabColor(lab_l=87.73500278716472,lab_a=-86.1829494051608,lab_b=83.1795364492565)
回答1:
The content of the conversion
variable in the convert_color definition using your example is an empty list, meaning that there is no conversion to perform, thus the definition is not failing and returns new_color
which is initialised with your original sRGB colour. I'm not exactly sure why this is the case though.
Alternatively, I'm the maintainer of another Python Colour Science API that would work for your case, it is however probably more involved than colormath
because not abstracting conversions:
import colour
colour.RGB_to_RGB(
(0, 1, 0),
colour.models.sRGB_COLOURSPACE,
colour.models.ADOBE_RGB_1998_COLOURSPACE)
# array([ 0.28488056, 1. , 0.04116936])
来源:https://stackoverflow.com/questions/37849901/why-cant-python-colormath-convert-srgb-to-adobe-rgb