コード例 #1
0
def set_convertor(name, ill='D65'):
    """ Binds the conversion functions LCH2RGB() and RGB2LCH() to the choosen colour package
    """
    global LCH2RGB, RGB2LCH, convertor, illuminant
    if name not in ['custom', 'colorspacious', 'colourscience']:
        print("Unknown conversion module")
        return
    convertor = name
    illuminant = ill
    if name == 'custom':
        LCH2RGB = lambda L, C, H: XYZ2RGB(Lab2XYZ(LCH2Lab((L, C, H))))
        RGB2LCH = lambda R, G, B: Lab2LCH(XYZ2Lab(RGB2XYZ((R, G, B))))
    if name == 'colorspacious':
        from colorspacious import cspace_convert
        func_LCH2RGB = lambda L, C, H: cspace_convert([L, C, H], {
            "name": "CIELCh",
            "XYZ100_w": ill
        }, "sRGB1")
        func_RGB2LCH = lambda R, G, B: cspace_convert([R, G, B], "sRGB1", {
            "name": "CIELCh",
            "XYZ100_w": ill
        })
    if name == 'colourscience':
        import colour as cs
        cs_ill = cs.ILLUMINANTS['CIE 1931 2 Degree Standard Observer'][ill]
        func_LCH2RGB = lambda L, C, H: cs.XYZ_to_sRGB(
            cs.Lab_to_XYZ(cs.LCHab_to_Lab([L, C, H]), illuminant=cs_ill))
        func_RGB2LCH = lambda R, G, B: cs.Lab_to_LCHab(
            cs.XYZ_to_Lab(cs.sRGB_to_XYZ([R, G, B]), illuminant=cs_ill))
    if name == 'colorspacious' or name == 'colourscience':

        def LCH2RGB(L, C, H):
            if hasattr(L, '__iter__'):
                RGB = np.array(list(map(func_LCH2RGB, L, C, H)))
                R = RGB[:, 0]
                G = RGB[:, 1]
                B = RGB[:, 2]
            else:
                R, G, B = func_LCH2RGB(L, C, H)
            return R, G, B

        def RGB2LCH(R, G, B):
            if hasattr(R, '__iter__'):
                LCH = np.array(list(map(func_RGB2LCH, R, G, B)))
                L = LCH[:, 0]
                C = LCH[:, 1]
                H = LCH[:, 2]
            else:
                L, C, H = func_RGB2LCH(R, G, B)
            return L, C, H

    print("convertor = '%s' (illuminant = '%s')" % (name, illuminant))
コード例 #2
0
print(colour.Lab_to_XYZ(Lab))

print('\n')

message_box(('Converting to "CIE LCHab" colourspace from given "CIE Lab" '
             'colourspace values:\n'
             '\n\t{0}'.format(Lab)))
print(colour.Lab_to_LCHab(Lab))

print('\n')

LCHab = (100.00000000, 42.41254357, 46.90195532)
message_box(('Converting to "CIE Lab" colourspace from given "CIE LCHab" '
             'colourspace values:\n'
             '\n\t{0}'.format(LCHab)))
print(colour.LCHab_to_Lab(LCHab))

print('\n')

XYZ = (114.17634600, 100.00000000, 49.81520600)
message_box(('Converting to "Hunter L,a,b" colour scale from given "CIE XYZ" '
             'tristimulus values:\n'
             '\n\t{0}'.format(XYZ)))
print(colour.XYZ_to_Hunter_Lab(XYZ))

print('\n')

Lab = (100.00000000, 32.03822364, 23.14715286)
message_box(('Converting to "CIE XYZ" tristimulus values from given '
             '"Hunter L,a,b" colour scale values:\n'
             '\n\t{0}'.format(Lab)))