Example #1
0
    def getNaturalness(self, rgb):
        XYZ = colour.sRGB_to_XYZ(rgb)
        LUV = colour.XYZ_to_Luv(XYZ)

        #彩度と色相の計算(色相は0-2pi-->角度(0-360)に変換)
        sat = np.sqrt(LUV[:, 1]**2 + LUV[:, 2]**2) / 100
        hue = np.arctan2(LUV[:, 2], LUV[:, 1])
        hue[hue < 0] += 2 * np.pi

        LHS = np.c_[LUV[:, 0], np.rad2deg(hue), sat]

        #Thresolding L and S components
        LHS = LHS[np.where((LHS[:, 0] >= 20) & (LHS[:, 0] <= 80)
                           & (LHS[:, 2] >= 0.1))]

        #Calcurate average and pixel num of saturation value
        skin = LHS[np.where((LHS[:, 1] >= 25) & (LHS[:, 1] <= 70)), 2]
        grass = LHS[np.where((LHS[:, 1] >= 95) & (LHS[:, 1] <= 135)), 2]
        sky = LHS[np.where((LHS[:, 1] >= 185) & (LHS[:, 1] <= 260)), 2]

        if (skin.shape[1] == 0):
            n_skin = 0
            S_skin = 0
        else:
            n_skin = skin.shape[1]
            S_skin = np.mean(skin)

        if (grass.shape[1] == 0):
            n_grass = 0
            S_grass = 0
        else:
            n_grass = grass.shape[1]
            S_grass = np.mean(grass)

        if (sky.shape[1] == 0):
            n_sky = 0
            S_sky = 0
        else:
            n_sky = sky.shape[1]
            S_sky = np.mean(sky)

        #Calcurate local CNI value
        N_skin = np.power(np.exp(-0.5 * ((S_skin - 0.76) / 0.52)**2), 4)
        N_grass = np.exp(-0.5 * ((S_grass - 0.81) / 0.53)**2)
        N_sky = np.exp(-0.5 * ((S_sky - 0.43) / 0.22)**2)

        return (n_skin * N_skin + n_grass * N_grass +
                n_sky * N_sky) / (n_skin + n_grass + n_sky)
Example #2
0
def XYZ_xyz_Luv_uv_Tc_lum_Eff_lum_KPD(spd, T_method='Robertson1968'):
    cmfs = colour.STANDARD_OBSERVERS_CMFS[
        'CIE 1931 2 Degree Standard Observer']
    # illuminant = colour.ILLUMINANTS_RELATIVE_SPDS['A']
    XYZ = colour.spectral_to_XYZ(spd, cmfs)
    x, y = colour.XYZ_to_xy(XYZ / 100)
    xyz = [x, y, 1 - x - y]
    Luv = colour.XYZ_to_Luv(XYZ)
    uv = colour.UCS_to_uv(colour.XYZ_to_UCS(XYZ))

    if T_method == 'Robertson1968':
        CCT, _D_uv = colour.uv_to_CCT_Robertson1968(uv)
    elif T_method == 'Ohno2013':
        CCT, _D_uv = colour.uv_to_CCT_Ohno2013(uv)

    Tc = [CCT, _D_uv]
    lum_Eff = colour.luminous_efficacy(spd)
    lum_KPD = colour.luminous_efficiency(spd)
    return (XYZ, xyz, Luv, uv, Tc, lum_Eff, lum_KPD)
             '\n\t{0}'.format(uv)))
print(colour.UCS_uv_to_xy(uv))

print('\n')

message_box(('Converting to "CIE UVW" colourspace from given "CIE XYZ" '
             'tristimulus values:\n'
             '\n\t{0}'.format(XYZ)))
print(colour.XYZ_to_UVW(XYZ))

print('\n')

message_box(('Converting to "CIE Luv" colourspace from given "CIE XYZ" '
             'tristimulus values:\n'
             '\n\t{0}'.format(XYZ)))
print(colour.XYZ_to_Luv(XYZ))

print('\n')

Luv = (100.00000000, 64.73951819, 28.90956141)
message_box(('Converting to "CIE XYZ" tristimulus values from given "CIE Luv" '
             'colourspace values:\n'
             '\n\t{0}'.format(Luv)))
print(colour.Luv_to_XYZ(Luv))

print('\n')

message_box(('Converting to "u"v"" chromaticity coordinates from given '
             '"CIE Luv" colourspace values:\n'
             '\n\t{0}'.format(Luv)))
print(colour.Luv_to_uv(Luv))