コード例 #1
0
def rgb_to_k(r, g, b):
    RGB = np.array([r, g, b])
    # Conversion to tristimulus values.
    XYZ = colour.sRGB_to_XYZ(RGB / 255)
    # Conversion to chromaticity coordinates.
    xy = colour.XYZ_to_xy(XYZ)
    # Conversion to correlated colour temperature in K.
    CCT = colour.xy_to_CCT(xy, 'hernandez1999')

    #print(f"{r}{g}{b}")

    return CCT
コード例 #2
0
ファイル: metrics.py プロジェクト: Dusmar6/491-Proj
def image_color_temperature(path):
    #convert image to array of pixels
    array = np.array(image_dominant_color_rgb(path))
    
    #conver to xyz https://www.colourphil.co.uk/xyz_colour_space.shtml
    XYZ = colour.sRGB_to_XYZ(array / 255)
    
    #dont need the z value
    xy = colour.XYZ_to_xy(XYZ)
    
    #convert to its kelvin temperature
    CCT = colour.xy_to_CCT(xy, 'hernandez1999')
    return CCT
コード例 #3
0
    def get_cct(self, methods="Hernandez 1999"):
        '''
        approximate CCT using CIE 1931 xy values
        '''
        x, y, z = self.get_xyz()

        if 0 in [x, y, z]:
            return 0.0

        logs.logger.debug(f"x = {x}, y = {y}, z = {z}")

        if isinstance(methods, str):
            methods = [methods]

        ccts = list()

        for curr_method in methods:
            if curr_method == 'me_mccamy':
                # McCamy's Approx
                small_x = x / (x + y + z)
                small_y = y / (x + y + z)

                n = (small_x - 0.3320) / (0.1858 - small_y)
                cct = 437 * (n**3) + 3601 * (n**2) + 6861 * n + 5517

                if DEBUG:
                    logs.logger.debug(
                        f"[me_mccamy] calc x = {small_x}, calc y = {small_y} | Calc CCT = {cct} K"
                    )
            elif curr_method in XY_TO_CCT_METHODS:
                xyz_arr = np_array([x, y, z])
                xy_arr = XYZ_to_xy(xyz_arr)
                cct = xy_to_CCT(xy_arr, curr_method)
                if DEBUG:
                    logs.logger.debug(
                        f"[{curr_method}] calc x,y = {xy_arr} | CCT = {cct}")
            else:
                options = ["me_mccamy"] + list(XY_TO_CCT_METHODS)

                logs.logger.error(
                    f"{curr_method} Not found!\nCCT calculation methods: \n {options}"
                )

                return

            ccts.append(int(cct))

        if len(ccts) == 1:
            return ccts[0]
        else:
            return ccts
コード例 #4
0
def main():
    while True:
        time.sleep(1)
        img = get_cap()
        avg_color_rgb = bgr_to_rgb(avg_image_colors(img))
        avg_color_xyz = colour.sRGB_to_XYZ(avg_color_rgb)
        avg_color_xy = colour.XYZ_to_xy(avg_color_xyz)
        avg_color_cct = colour.xy_to_CCT(avg_color_xy, 'hernandez1999')
        avg_img_color_cct_xy = colour.temperature.CCT_to_xy(avg_color_cct)

        print("Average RGB Value: {}, Rounded CCT: {}, Sent xy: {}".format(
            avg_color_rgb, avg_color_cct, avg_img_color_cct_xy))

        set_acs_sample(avg_img_color_cct_xy[0], avg_img_color_cct_xy[1])
コード例 #5
0
def calculate_input_temp(frame) -> float:
    array_RGB = numpy.array(list(cv2.mean(frame)[0:3][::-1]))

    array_tristimulus = colour.sRGB_to_XYZ(array_RGB / 255)

    array_chromaticity = colour.XYZ_to_xy(array_tristimulus)

    temporary = colour.xy_to_CCT(array_chromaticity, 'hernandez1999')

    if temporary < 1000:
        # print('Warm bound')
        return 1000
    elif temporary > 12000:
        # print('Cold bound')
        return 12000
    return temporary
コード例 #6
0
ファイル: examples_cct.py プロジェクト: yeekzhang/colour
print('\n')

message_box(('Converting to "CIE UCS" colourspace "uv" chromaticity '
             'coordinates from given "CCT" using "Krystek (1985)" method:\n'
             '\n\t({0})'.format(CCT)))
print(colour.CCT_to_uv_Krystek1985(CCT))
print(colour.CCT_to_uv(CCT, method='Krystek 1985'))

print('\n')

xy = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
message_box(('Converting to "CCT" from given "xy" chromaticity coordinates '
             'using "McCamy (1992)" method:\n'
             '\n\t{0}'.format(xy)))
print(colour.xy_to_CCT_McCamy1992(xy))
print(colour.xy_to_CCT(xy, method='McCamy 1992'))

print('\n')

message_box(('Converting to "CCT" from given "xy" chromaticity coordinates '
             'using "Hernandez-Andres, Lee and Romero (1999)" method:\n'
             '\n\t{0}'.format(xy)))
print(colour.xy_to_CCT_Hernandez1999(xy))
print(colour.xy_to_CCT(xy, method='Hernandez 1999'))

print('\n')

CCT = 6503.49254150
message_box(('Converting to "xy" chromaticity coordinates from given "CCT" '
             'using "Kang, Moon, Hong, Lee, Cho and Kim (2002)" method:\n'
             '\n\t{0}'.format(CCT)))
コード例 #7
0
ファイル: examples_cct.py プロジェクト: KevinJW/colour
message_box(('Converting to "CIE UCS" colourspace "uv" chromaticity '
             'coordinates from given "CCT" and "Duv" using "Robertson (1968)" '
             'method:\n'
             '\n\t({0}, {1})'.format(CCT, Duv)))
print(colour.CCT_to_uv_robertson1968(CCT, Duv))
print(colour.CCT_to_uv(CCT, Duv, method='Robertson 1968'))

print('\n')

xy = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']
message_box(('Converting to "CCT" from given "xy" chromaticity coordinates '
             'using "McCamy (1992)" method:\n'
             '\n\t{0}'.format(xy)))
print(colour.xy_to_CCT_mccamy1992(xy))
print(colour.xy_to_CCT(xy, method='McCamy 1992'))

print('\n')

message_box(('Converting to "CCT" from given "xy" chromaticity coordinates '
             'using "Hernandez-Andres, Lee & Romero (1999)" method:\n'
             '\n\t{0}'.format(xy)))
print(colour.xy_to_CCT_hernandez1999(xy))
print(colour.xy_to_CCT(xy, method='Hernandez 1999'))

print('\n')

CCT = 6503.4925414981535
message_box(('Converting to "xy" chromaticity coordinates from given "CCT" '
             'using "Kang, Moon, Hong, Lee, Cho and Kim (2002)" method:\n'
             '\n\t{0}'.format(CCT)))
コード例 #8
0
ファイル: examples_colour.py プロジェクト: zachlewis/colour
print(colour.XYZ_to_Lab(XYZ, illuminant=illuminant))

print('\n')

XYZ = np.reshape(XYZ, (3, 2, 1, 3))
illuminant = np.reshape(illuminant, (3, 2, 1, 2))
message_box('Using 4d "array_like" parameter:\n' '\n{0}'.format(XYZ))
print(colour.XYZ_to_Lab(XYZ, illuminant=illuminant))

print('\n')

xy = np.tile((0.31270, 0.32900), (6, 1))
message_box(('Definitions return value may lose a dimension with respect to '
             'the parameter(s):\n'
             '\n{0}'.format(xy)))
print(colour.xy_to_CCT(xy))

print('\n')

CCT = np.tile(6504.38938305, 6)
message_box(('Definitions return value may gain a dimension with respect to '
             'the parameter(s):\n'
             '\n{0}'.format(CCT)))
print(colour.CCT_to_xy(CCT))

print('\n')

message_box(('Definitions mixing "array_like" and "numeric" parameters '
             'expect the "numeric" parameters to have a dimension less than '
             'the "array_like" parameters.'))
XYZ_1 = np.array([28.00, 21.26, 5.27])
コード例 #9
0
def color_to_temperature(color):
    xyz = colour.sRGB_to_XYZ(
        numpy.array([color.red, color.green, color.blue]) / 255)
    return colour.xy_to_CCT(colour.XYZ_to_xy(xyz), 'hernandez1999')
コード例 #10
0
def index():
    cmfs = CMFS['CIE 1931 2 Degree Standard Observer']
    with open('test.txt') as f:
        data = pd.read_csv(f, sep="\t" or ' ' or ',', header=None)
        f.close()
    w = [i[0] for i in data.values]
    s = [i[1] for i in data.values]
    data_formated = dict(zip(w, s))
    spd = SpectralPowerDistribution('Sample', data_formated)
    b = single_spd_plot(spd,
                        standalone=False,
                        figure_size=(5, 5),
                        title='Spectrum')
    figfile_b = StringIO()
    b.savefig(figfile_b, format='svg')
    figfile_b.seek(0)
    figdata_svg_b = '<svg' + figfile_b.getvalue().split('<svg')[1]
    b.clf()
    plot.close(b)
    illuminant = ILLUMINANTS_RELATIVE_SPDS['D50']
    XYZ = spectral_to_XYZ(spd, cmfs, illuminant)
    xy = XYZ_to_xy(XYZ)
    print(xy)
    cct = xy_to_CCT(xy)
    print(cct)
    cri = colour_rendering_index(spd, additional_data=True)
    print(cri.Q_a)
    Q_as = cri.Q_as
    y = [s[1].Q_a for s in sorted(Q_as.items(), key=lambda s: s[0])]
    print(y)
    single_spd_colour_rendering_index_bars_plot(spd,
                                                standalone=False,
                                                figure_size=(7, 7),
                                                title='Colour rendering index')
    c = plot.gcf()
    figfile_c = StringIO()
    c.savefig(figfile_c, format='svg')
    figfile_c.seek(0)
    figdata_svg_c = '<svg' + figfile_c.getvalue().split('<svg')[1]
    c.clf()
    plot.close(c)

    CIE_1931_chromaticity_diagram_plot(standalone=False,
                                       figure_size=(6, 5),
                                       grid=False,
                                       title='CIE 1931 Chromaticity Diagram',
                                       bounding_box=(-0.1, 0.9, -0.05, 0.95))
    x, y = xy
    pylab.plot(x, y, 'o-', color='white')
    pylab.annotate((("%.4f" % x), ("%.4f" % y)),
                   xy=xy,
                   xytext=(-50, 30),
                   textcoords='offset points',
                   arrowprops=dict(arrowstyle='->',
                                   connectionstyle='arc3, rad=-0.2'))

    a = plot.gcf()
    figfile = StringIO()
    a.savefig(figfile, format='svg')
    figfile.seek(0)
    figdata_svg = '<svg' + figfile.getvalue().split('<svg')[1]
    a.clf()
    plot.close(a)
    del a, b, c
    # pprint.pprint(figdata_svg)
    return render_template('index.html',
                           spd=figdata_svg_b,
                           result=figdata_svg,
                           colour_rendering_index=figdata_svg_c)
コード例 #11
0
ファイル: examples_cct.py プロジェクト: colour-science/colour
print("\n")

CCT = 6503.49254150
message_box(
    f'Converting to "CIE UCS" colourspace "uv" chromaticity coordinates from '
    f'given "CCT" using "Krystek (1985)" method:\n\n\t({CCT})')
print(colour.CCT_to_uv(CCT, method="Krystek 1985"))
print(colour.temperature.CCT_to_uv_Krystek1985(CCT))

print("\n")

xy = colour.CCS_ILLUMINANTS["CIE 1931 2 Degree Standard Observer"]["D65"]
message_box(
    f'Converting to "CCT" from given "CIE xy" chromaticity coordinates using '
    f'"McCamy (1992)" method:\n\n\t{xy}')
print(colour.xy_to_CCT(xy, method="McCamy 1992"))
print(colour.temperature.xy_to_CCT_McCamy1992(xy))

print("\n")

message_box(
    f'Converting to "CCT" from given "CIE xy" chromaticity coordinates using '
    f'"Hernandez-Andres, Lee and Romero (1999)" method:\n\n\t{xy}')
print(colour.xy_to_CCT(xy, method="Hernandez 1999"))
print(colour.temperature.xy_to_CCT_Hernandez1999(xy))

print("\n")

CCT = 6503.49254150
message_box(
    f'Converting to "CIE xy" chromaticity coordinates from given "CCT" using '
コード例 #12
0
def RGB_to_CCT(rgb):
    RGB = np.array(rgb)
    XYZ = sRGB_to_XYZ(RGB / 255)
    xy = XYZ_to_xy(XYZ)
    CCT = xy_to_CCT(xy, "hernandez1999")
    return CCT