Why can't python-colormath convert sRGB to Adobe RGB?

↘锁芯ラ 提交于 2020-01-04 05:39:10

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!