2016-06-16 11 views
1

Das scheint so ein einfaches Problem, genau das, was für colormath entwickelt wurde. Aber das Aufrufen von convert_color scheint das gleiche Objekt zurückzugeben, das übergeben wurde. Nach the documentation sollte eine fehlgeschlagene Konvertierung ein UndefinedConversionError auslösen, ein Objekt nicht zurückgeben.Warum kann Python-Colormath nicht sRGB in Adobe RGB konvertieren?

>>> 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 

Es macht Arbeit Lab zu konvertieren, so bin ich nicht sicher, was das Problem sein könnte.

>>> from colormath.color_objects import LabColor 
>>> convert_color(srgb, LabColor) 
LabColor(lab_l=87.73500278716472,lab_a=-86.1829494051608,lab_b=83.1795364492565) 

Antwort

1

Der Inhalt des conversion Variable in der convert_color Definition Ihres Beispiel verwendet, ist eine leere Liste, was bedeutet, dass es keine Umwandlung ist, also die Definition andernfalls nicht durchführen und gibt new_color, die mit Ihrem ursprünglichen initialisiert sRGB Farbe. Ich bin mir nicht ganz sicher, warum das der Fall ist.

Alternativ bin ich der Betreuer eines anderen Python Colour Science API, die für Ihren Fall funktionieren würde, es als colormath aber wohl mehr beteiligt ist, weil nicht Konvertierungen abstrahiert:

import colour 

colour.RGB_to_RGB(
    (0, 1, 0), 
    colour.sRGB_COLOURSPACE, 
    colour.ADOBE_RGB_1998_COLOURSPACE) 


# array([ 0.28488056, 1.  , 0.04116936])