예제 #1
0
파일: plot.py 프로젝트: cwi-dis/lissabon
def plot_colors(values, parameters, ylabels):
    #fig, ax = colour.plotting.plot_chromaticity_diagram_CIE1931(standalone=False)
    fig, ax = colour.plotting.plot_planckian_locus_in_chromaticity_diagram_CIE1931([], standalone=False)
    mincct = values[0]['requested']
    maxcct = values[-1]['requested']
    ax.set_title(f'CCT measured for RGB LED, {int(mincct)} to {int(maxcct)}')

    sRGB = colour.RGB_COLOURSPACES['sRGB']

    plotcoloridx = 0
    for value in values:
        plotcolor = f'C{plotcoloridx}'
        plotcoloridx += 1
        cct_requested = value['requested']
#       for ylabel in ylabels:
        x_req, y_req = colour.CCT_to_xy(cct_requested)
        rgb_xvalues = []
        rgb_yvalues = []
        cct_xvalues = []
        cct_yvalues = []
        for ylabel in ylabels:
            r = value[f'rgb_r_{ylabel}']
            g = value[f'rgb_g_{ylabel}']
            b = value[f'rgb_b_{ylabel}']
            RGB = np.array([r, g, b])
            XYZ = colour.RGB_to_XYZ(RGB, sRGB.whitepoint, sRGB.whitepoint, sRGB.RGB_to_XYZ_matrix)
            xy = colour.XYZ_to_xy(XYZ)
            x, y = xy
            rgb_xvalues.append(x)
            rgb_yvalues.append(y)
            cct_measured = value[f'rgb_cct_{ylabel}']
            x, y = colour.CCT_to_xy(cct_measured)
            cct_xvalues.append(x)
            cct_yvalues.append(y)
        matplotlib.pyplot.plot(rgb_xvalues, rgb_yvalues, color=plotcolor, marker='o', linestyle='', label=str(cct_requested))
        matplotlib.pyplot.plot(cct_xvalues, cct_yvalues, color=plotcolor, marker='.', linestyle='')
        matplotlib.pyplot.plot([x_req], [y_req], color=plotcolor, marker='X')
    p_text = []
    for k, v in parameters.items():
        if k in  ('measurement', 'interval'): continue
        p_text.append(f'{k} = {v}')
    ax.text(0.95, 0.05, '\n'.join(p_text), transform=ax.transAxes, bbox=dict(boxstyle='round'), multialignment='left', horizontalalignment='right', verticalalignment='bottom')
    ax.legend()
#        matplotlib.pyplot.annotate(str(cct_requested), 
#            xy=(x, y),
#            xytext=(-50, 30),
#            textcoords='offset points',
#            arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=-0.2'))
    matplotlib.pyplot.show()
예제 #2
0
파일: plot.py 프로젝트: cwi-dis/lissabon
def plot_colors_bycct(values, parameters, ylabels):
    fig, ax = colour.plotting.plot_chromaticity_diagram_CIE1931(standalone=False)
    mincct = values[0]['requested']
    maxcct = values[-1]['requested']
    ax.set_title(f'CCT measured for RGB LED, {int(mincct)} to {int(maxcct)}')
    for ylabel in ylabels:
        xvalues = []
        yvalues = []
        for value in values:
            cct_requested = value['requested']
            cct_measured = value[f'rgb_cct_{ylabel}']
            x, y = colour.CCT_to_xy(cct_measured)
            xvalues.append(x)
            yvalues.append(y)
        matplotlib.pyplot.plot(xvalues, yvalues, '.', label=ylabel)
    p_text = []
    for k, v in parameters.items():
        if k in  ('measurement', 'interval'): continue
        p_text.append(f'{k} = {v}')
    ax.text(0.95, 0.05, '\n'.join(p_text), transform=ax.transAxes, bbox=dict(boxstyle='round'), multialignment='left', horizontalalignment='right', verticalalignment='bottom')
    ax.legend()
#        matplotlib.pyplot.annotate(str(cct_requested), 
#            xy=(x, y),
#            xytext=(-50, 30),
#            textcoords='offset points',
#            arrowprops=dict(arrowstyle='->', connectionstyle='arc3, rad=-0.2'))
    matplotlib.pyplot.show()
예제 #3
0
def cs_convert_K_to_RGB(colour_temperature):
    xy = colour.CCT_to_xy(colour_temperature)
    xyY = np.array([xy[0], xy[1], 1])
    XYZ = colour.xyY_to_XYZ(xyY)
    sRGB = colour.RGB_COLOURSPACES['sRGB']
    RGB = colour.XYZ_to_RGB(XYZ, sRGB.whitepoint, sRGB.whitepoint,
                            sRGB.XYZ_to_RGB_matrix)
    return RGB[0], RGB[1], RGB[2]
예제 #4
0
	def temperatureChange(self):	
		value = self.temperatureSlider.value() +1
		#range is 1100K to 11 000K
		K = int(1000+ (value*120))
		print("Kelvins: ", K)
		xy = colour.CCT_to_xy(K)
		#print("xy", xy)
		xyz = colour.xy_to_XYZ(xy)
		#print("xyz", xyz)
		rgb = colour.XYZ_to_sRGB(xyz)
		r = int(min(1,max(0,rgb[0]))*255)
		g = int(min(1,max(0,rgb[1]))*255)
		b = int(min(1,max(0,rgb[2]))*255)
		self.color = [r, g, b]
		print("rgb", self.color)
		self.updateColorLabel()
예제 #5
0
def temperature_to_rgb(cct):
    """ Convert temperature in Kelvin to sRGB.
    First, we convert CCT (Kelvin) to chromaticity coordinates.
    Second, we convert to tristimulus values.
    Third, we convert to rgb

    Parameters
    ----------
    cct : Correlated color temperature in kelvin

    Returns
    -------
    array : List/tuple of rgb values, e.g. [255.0, 235.0, 12.0]
    """
    xy = colour.CCT_to_xy(cct)
    xyz = colour.xy_to_XYZ(xy)
    rgb = colour.XYZ_to_sRGB(xyz)
    return rgb
예제 #6
0
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)))
print(colour.CCT_to_xy_Kang2002(CCT))
print(colour.CCT_to_xy(CCT, method="Kang 2002"))

print('\n')

message_box(('Converting to "xy" chromaticity coordinates from given "CCT" '
             'using "CIE Illuminant D Series" method:\n'
             '\n\t{0}'.format(CCT)))
print(colour.CCT_to_xy_CIE_D(CCT))
print(colour.CCT_to_xy(CCT, method="CIE Illuminant D Series"))
예제 #7
0
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])
xy_o1 = np.array([0.4476, 0.4074])
xy_o2 = np.array([0.3127, 0.3290])
Y_o = 20
E_o1 = 1000
E_o2 = 1000
message_box(('Parameters:\n\n'
             'XYZ_1:\n\n{0}\n\n'
             '\nxy_o1:\n\n{1}\n\n'
예제 #8
0
             '\n\t{0}'.format(xy)))
print(colour.xy_to_CCT(xy, method='McCamy 1992'))
print(colour.temperature.xy_to_CCT_McCamy1992(xy))

print('\n')

message_box(('Converting to "CCT" from given "CIE xy" chromaticity '
             'coordinates using "Hernandez-Andres, Lee and Romero (1999)" '
             'method:\n'
             '\n\t{0}'.format(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(('Converting to "CIE xy" chromaticity coordinates from given '
             '"CCT" using "Kang, Moon, Hong, Lee, Cho and Kim (2002)" '
             'method:\n'
             '\n\t{0}'.format(CCT)))
print(colour.CCT_to_xy(CCT, method='Kang 2002'))
print(colour.temperature.CCT_to_xy_Kang2002(CCT))

print('\n')

message_box(('Converting to "CIE xy" chromaticity coordinates from given '
             '"CCT" using "CIE Illuminant D Series" method:\n'
             '\n\t{0}'.format(CCT)))
print(colour.CCT_to_xy(CCT, method='CIE Illuminant D Series'))
print(colour.temperature.CCT_to_xy_CIE_D(CCT))
예제 #9
0
    #Attempt to find the color temp of the image and move it from the default
    temp = find_temp(img)
    if temp:
        print(f"found photo temp: {temp}K")
        Temperature = temp

    #Resize the image to something more workable
    r, c = img.size
    img = img.resize(map(int, [r * scale, c * scale]))
    #RGB   = np.asarray(img)

    #Convert to XYZ->xyY colorspace
    XYZ = convert_to_XYZ(img)  #colour.sRGB_to_XYZ(RGB / 255)
    xy = colour.XYZ_to_xy(XYZ)
    xy_n = colour.CCT_to_xy(Temperature)

    #Calculate the dominant wavelength of the color
    spectra_dom, spectra_com = domcom_spectra(xy, xy_n)

    #Plot the CIExyY colorpsace and our pixels on it
    CIExyY = plt.figure("CIExyY colorspace")

    cmfs = colour.CMFS['CIE 1931 2 Degree Standard Observer']
    i, j = colour.XYZ_to_xy(cmfs.values).T
    RGB = d.chromaticity_diagram_colours_CIE1931()
    x, y = xy.T

    scatter = plt.scatter(i, j, marker='o', label='Wavelengths (nm))')
    pixels = plt.plot(x.flatten(),
                      y.flatten(),