def getDistance(self, pixels1, pixels2): lab1 = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(pixels1)) lab2 = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(pixels2)) dist = mean_squared_error(pixels1, pixels2) #dist = np.sqrt((pixels1[:, 0] - pixels2[:, 0])**2 + (pixels1[:, 1] - pixels2[:, 1])**2 + (pixels1[:, 2] - pixels2[:, 2])**2) #dist = np.sum(dist) return dist
def update_CIELAB_3Dplot(fig, tristimulus_XYZ, selected_phi, data): if fig is None or tristimulus_XYZ is None or selected_phi is None: raise PreventUpdate selected_phi = np.array(selected_phi) phiVs = np.array(data['phiVs']) tristimulus_XYZ = np.array(tristimulus_XYZ) figure = go.Figure() if selected_phi.shape[0] == 1: selected_XYZ = tristimulus_XYZ[:, phiVs == selected_phi[0]][:, 0, :] selected_LAB = np.array([ clr.XYZ_to_Lab(selected_XYZ[i] / 100) for i in range(selected_XYZ.shape[0]) ]) figure.add_trace( go.Scatter3d(x=selected_LAB[:, 1], y=selected_LAB[:, 2], z=selected_LAB[:, 0], mode='lines+markers')) elif selected_phi.shape[0] == 2: selected_XYZ_pos = tristimulus_XYZ[:, phiVs == selected_phi[0]][:, 0, :] selected_LAB_pos = np.array([ clr.XYZ_to_Lab(selected_XYZ_pos[i] / 100) for i in range(selected_XYZ_pos.shape[0]) ]) figure.add_trace( go.Scatter3d(x=selected_LAB_pos[:, 1], y=selected_LAB_pos[:, 2], z=selected_LAB_pos[:, 0], mode='lines+markers')) selected_XYZ_neg = tristimulus_XYZ[:, phiVs == selected_phi[1]][:, 0, :] selected_XYZ_neg = np.array([ clr.XYZ_to_Lab(selected_XYZ_neg[i] / 100) for i in range(selected_XYZ_neg.shape[0]) ]) figure.add_trace( go.Scatter3d(x=selected_XYZ_neg[:, 1], y=selected_XYZ_neg[:, 2], z=selected_XYZ_neg[:, 0], mode='lines+markers')) else: raise PreventUpdate figure.update_layout(title="Color travel 3D plot in CIELab space", scene=dict(xaxis_title="a*", yaxis_title="b*", zaxis_title="L*")) return figure
def update_CIELAB_3Dplot(fig, tristimulus_XYZ, selected_phi, data): if fig is None or tristimulus_XYZ is None or selected_phi is None: raise PreventUpdate selected_phi = np.array(selected_phi) phiVs = np.array(data['phiVs']) tristimulus_XYZ = np.array(tristimulus_XYZ) figure = go.Figure() if selected_phi.shape[0] == 1: selected_XYZ = tristimulus_XYZ[:, phiVs == selected_phi[0]][:, 0, :] selected_LAB = np.array([ clr.XYZ_to_Lab(selected_XYZ[i] / 100) for i in range(selected_XYZ.shape[0]) ]) figure.add_trace( go.Scatter(name='projection', x=selected_LAB[:, 1], y=selected_LAB[:, 2], mode='lines+markers')) elif selected_phi.shape[0] == 2: selected_XYZ_pos = tristimulus_XYZ[:, phiVs == selected_phi[0]][:, 0, :] selected_LAB_pos = np.array([ clr.XYZ_to_Lab(selected_XYZ_pos[i] / 100) for i in range(selected_XYZ_pos.shape[0]) ]) figure.add_trace( go.Scatter(name='projection 0 to 90', x=selected_LAB_pos[:, 1], y=selected_LAB_pos[:, 2], mode='lines+markers')) selected_XYZ_neg = tristimulus_XYZ[:, phiVs == selected_phi[1]][:, 0, :] selected_XYZ_neg = np.array([ clr.XYZ_to_Lab(selected_XYZ_neg[i] / 100) for i in range(selected_XYZ_neg.shape[0]) ]) figure.add_trace( go.Scatter(name='projection -90 to 0', x=selected_XYZ_neg[:, 1], y=selected_XYZ_neg[:, 2], mode='lines+markers')) else: raise PreventUpdate figure.update_layout(title="CIELab colorspace projection to a*b* plane", xaxis_title='a*', yaxis_title='b*') return figure
def delta_E_range(): XYZ = colour.volume.XYZ_outer_surface() # print(XYZ, XYZ.shape) combinations = colour.XYZ_to_Lab( np.array(list(itertools.combinations(XYZ, 2)))) # print(combinations) delta_E = colour.delta_E(combinations[:, 0, :], combinations[:, 1, :]) return np.amax(delta_E), np.amin(delta_E)
def convert(dict, illuminant='D65'): """ Converts the set of XYZ colours into other spaces: Lab, LCH, sRGB """ illuminant = colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer'][ illuminant] dict['Lab'] = colour.XYZ_to_Lab(dict['XYZ'] / 100., illuminant) # beware: expects XYZ in [0,1] dict['LCH'] = colour.Lab_to_LCHab(dict['Lab']) dict['RGB'] = colour.XYZ_to_sRGB( dict['XYZ'] / 100., illuminant) # beware: expects XYZ in [0,1]
def calculateColorValues(splineT, splineR, settings): '''Function calculates color values of the Transmission and Refelection side of the stack. Input Arguments are tranmission and reflection spline functions. Returns array of values/tuples of different standards.''' import colour import numpy as np wvl = np.linspace(380, 780, 81) dic_T = {} dic_R = {} dic_test = {} for idx, value in enumerate(wvl): dic_T[value] = splineT(value).item() dic_R[value] = splineR(value).item() #Removes warnings from conversions. colour.filter_warnings() cmfs = colour.STANDARD_OBSERVERS_CMFS[settings.color_cmfs] #1931 etc illuminant = colour.ILLUMINANTS_RELATIVE_SPDS[ settings.color_illuminant] #D65, A, C T_spd = colour.SpectralPowerDistribution('', dic_T) T_XYZ = colour.spectral_to_XYZ(T_spd, cmfs, illuminant) T_xy = colour.XYZ_to_xy(T_XYZ / 100) T_ab = colour.XYZ_to_Lab(T_XYZ / 100, illuminant=colour.ILLUMINANTS[settings.color_cmfs] [settings.color_illuminant]) T_rgb = colour.XYZ_to_sRGB( T_XYZ / 100, illuminant=colour.ILLUMINANTS[settings.color_cmfs][ settings.color_illuminant]) R_spd = colour.SpectralPowerDistribution('', dic_R) R_XYZ = colour.spectral_to_XYZ(R_spd, cmfs, illuminant) R_xy = colour.XYZ_to_xy(R_XYZ / 100) R_ab = colour.XYZ_to_Lab(R_XYZ / 100, illuminant=colour.ILLUMINANTS[settings.color_cmfs] [settings.color_illuminant]) R_rgb = colour.XYZ_to_sRGB( R_XYZ / 100, illuminant=colour.ILLUMINANTS[settings.color_cmfs][ settings.color_illuminant]) return (T_XYZ, T_xy, T_ab, T_rgb, R_XYZ, R_xy, R_ab, R_rgb)
def rgb_to_lab_d65(rgb, name="ITU-R BT.709"): illuminant_XYZ = tpg.D65_WHITE illuminant_RGB = tpg.D65_WHITE chromatic_adaptation_transform = 'CAT02' rgb_to_xyz_matrix = tpg.get_rgb_to_xyz_matrix(name) large_xyz = colour.RGB_to_XYZ(rgb, illuminant_RGB, illuminant_XYZ, rgb_to_xyz_matrix, chromatic_adaptation_transform) lab = colour.XYZ_to_Lab(large_xyz, illuminant_XYZ) return lab
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))
def ColorFidelityMetric(rgbX, rgbY): M = 0 Q = 0 #W * H * 3に変形 rgbX_ = np.reshape(rgbX, (inputImg.shape[0], inputImg.shape[1], 3)) rgbY_ = np.reshape(rgbY, (inputImg.shape[0], inputImg.shape[1], 3)) #RGB-->Lab XYZ_X = colour.sRGB_to_XYZ(rgbX_) XYZ_Y = colour.sRGB_to_XYZ(rgbY_) Lab_X = colour.XYZ_to_Lab(XYZ_X) Lab_Y = colour.XYZ_to_Lab(XYZ_Y) #ウィンドウサイズごとのFidelityMetricを計算 for (cropX, cropY) in SlidingWindow(Lab_X, Lab_Y, 1, 8): # if the window does not meet our desired window size, ignore it if cropX.shape[0] != 8 or cropX.shape[1] != 8: continue #オリジナル画像のクリップ cropL_X = cropX[:, :, 0].flatten() cropa_X = cropX[:, :, 1].flatten() cropb_X = cropX[:, :, 2].flatten() #加工画像のクリップ cropL_Y = cropY[:, :, 0].flatten() cropa_Y = cropY[:, :, 1].flatten() cropb_Y = cropY[:, :, 2].flatten() Ql = FidelityMetric(cropL_X, cropL_Y) Qa = FidelityMetric(cropa_X, cropa_Y) Qb = FidelityMetric(cropb_X, cropb_Y) Q += np.sqrt(Ql**2 + Qa**2 + Qb**2) M += 1 return Q / M
def BGR2LAB(image): """ Converts OpenCV BGR image to CIE Lab image Lab Scale L| 0:100 | a| -100:100 | b| -100:100 | :param image: BGR image :return: Lab image """ image_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB) image_srgb = image_rgb.astype(np.float32) / 255 image_lab = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(image_srgb)) return image_lab
def XYZ2LAB(xyz, illuminant='D65'): return colour.XYZ_to_Lab( xyz, illuminant=colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer'] ['D65']) refwhite = [0.9504, 1.0000, 1.0888] xyzr = np.array(xyz) / np.array(refwhite) e = 0.008856 k = 903.3 ff = [0.0, 0.0, 0.0] for i in range(0, 3): if xyzr[i] > e: ff[i] = xyzr[i]**(1.0 / 3.0) else: ff[i] = (k * xyzr[i] + 16) / 116 lab = [0.0, 0.0, 0.0] lab[0] = ff[1] * 116 - 16 lab[1] = 500 * (ff[0] - ff[1]) lab[2] = 200 * (ff[1] - ff[2]) return lab
def get_main_color(R,G,B): sRGB = [R/255,G/255,B/255] RGB = np.array(sRGB) XYZ = colour.sRGB_to_XYZ(sRGB) Lab = colour.XYZ_to_Lab(XYZ) LCHab = colour.Lab_to_LCHab(Lab) L = int(LCHab[0]);C = int(LCHab[1]);ab = int(LCHab[2]) print([L,C,ab]) if C<40:# 1 if L<10: return 'black' elif L>90: return 'white' else: return 'gray' elif ab<45:# 2 if L<30: return 'brown' elif L>70: return 'pink' else: return 'red' elif ab<75:# 3 if L<30: return 'brown' else: return 'orange' elif ab<105:# 4 return 'yellow' elif ab<210:# 5 return 'green' elif ab<315:# 6 return 'blue' elif ab>330:# 7 if L>50: return 'pink' else: return 'purple' else: return 'purple'
def prepare_cc(): print(colour.COLOURCHECKERS.data.keys()) cc = [] for i in range(0, 24): xyY = colour.COLOURCHECKERS.data['colorchecker 2005'][1].data[i].xyY print(colour.COLOURCHECKERS.data['colorchecker 2005'][1].data[i].name) print(xyY) XYZ = colour.xyY_to_XYZ(xyY) Lab = colour.XYZ_to_Lab(XYZ) print( colour.XYZ_to_sRGB( XYZ, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer'] ['D50'], 'Bradford') * 255) # print(colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D50']) XYZD65 = cam2xyz.XYZD50_XYZD65(XYZ) cc.append(XYZD65) print(XYZD65, ' ', colour.XYZ_to_sRGB(XYZD65) * 255) # print(XYZ, ' ' ,XYZD65) # print(colour.RGB_COLOURSPACES['sRGB'].whitepoint, ' ', ill2) # print(colour.XYZ_to_sRGB(XYZD65) * 255) # print(colour.COLOURCHECKERS.data['cc2005'][1].data[i]) return cc
def HEX_2_LAB(hex): return colour.XYZ_to_Lab( colour.sRGB_to_XYZ(colour.notation.HEX_to_RGB(hex)))
def Distance(xyz, lab): lab1 = colour.XYZ_to_Lab( xyz, colour.ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']) return colour.delta_E(lab, lab1)
def time_4k(self): colour.XYZ_to_Lab(xyz_4k)
def sRGB_to_Lab(r, g, b): XYZ = colour.sRGB_COLOURSPACE.RGB_to_XYZ_matrix.dot(np.array([r, g, b])) L, a, b = colour.XYZ_to_Lab(XYZ) return L, a, b,
from __future__ import division, unicode_literals import numpy as np import colour from colour.utilities.verbose import message_box message_box('Overall "Colour" Examples') message_box('N-Dimensional Arrays Support') XYZ = (0.07049534, 0.10080000, 0.09558313) illuminant = (0.34567, 0.35850) message_box('Using 1d "array_like" parameter:\n' '\n{0}'.format(XYZ)) print(colour.XYZ_to_Lab(XYZ, illuminant=illuminant)) print('\n') XYZ = np.tile(XYZ, (6, 1)) illuminant = np.tile(illuminant, (6, 1)) message_box('Using 2d "array_like" parameter:\n' '\n{0}'.format(XYZ)) print(colour.XYZ_to_Lab(XYZ, illuminant=illuminant)) print('\n') XYZ = np.reshape(XYZ, (2, 3, 3)) illuminant = np.reshape(illuminant, (2, 3, 2)) message_box('Using 3d "array_like" parameter:\n' '\n{0}'.format(XYZ)) print(colour.XYZ_to_Lab(XYZ, illuminant=illuminant))
import colour import numpy import sys targets = {} with open('colors.data') as file: for line in file: code, name = line.strip().split(' ') rgb = colour.notation.HEX_to_RGB(code) targets[name] = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(rgb)) sources = {} for arg in sys.argv[1:]: rgb = colour.notation.HEX_to_RGB(arg) sources[arg] = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(rgb)) mappings = {} for arg, actual in sources.items(): diffs = [] for name, expected in targets.items(): distance = colour.delta_E(actual, expected) diffs.append((distance, name)) mappings[arg] = sorted(diffs) for arg, diffs in mappings.items(): for diff in diffs[:8]: numpy.set_printoptions(precision=2) print('{0} {2} {1:.2f}'.format(arg, *diff))
def update_CIELAB_3Dplot(fig, tristimulus_XYZ, selected_phi, data): if fig is None or tristimulus_XYZ is None or selected_phi is None: raise PreventUpdate selected_phi = np.array(selected_phi) phiVs = np.array(data['phiVs']) thetaVs = np.array(data['thetaVs']) tristimulus_XYZ = np.array(tristimulus_XYZ) figure = go.Figure() if selected_phi.shape[0] == 1: selected_XYZ = tristimulus_XYZ[:, phiVs == selected_phi[0]][:, 0, :] selected_LAB = np.array([ clr.XYZ_to_Lab(selected_XYZ[i] / 100) for i in range(selected_XYZ.shape[0]) ]) figure.add_trace( go.Scatter(name='L*', y=selected_LAB[:, 0], x=thetaVs, mode='lines+markers', marker=dict(color='yellow'), line=dict(color='yellow'))) figure.add_trace( go.Scatter(name='a*', y=selected_LAB[:, 1], x=thetaVs, mode='lines+markers', marker=dict(color='red'), line=dict(color='red'))) figure.add_trace( go.Scatter(name='b*', y=selected_LAB[:, 2], x=thetaVs, mode='lines+markers', marker=dict(color='blue'), line=dict(color='blue'))) elif selected_phi.shape[0] == 2: selected_XYZ_pos = tristimulus_XYZ[:, phiVs == selected_phi[0]][:, 0, :] selected_LAB_pos = np.array([ clr.XYZ_to_Lab(selected_XYZ_pos[i] / 100) for i in range(selected_XYZ_pos.shape[0]) ]) figure.add_trace( go.Scatter(name='L* 0 to 90', y=selected_LAB_pos[:, 0], x=thetaVs, mode='lines+markers', marker=dict(color='yellow'), line=dict(color='yellow'))) figure.add_trace( go.Scatter(name='a* 0 to 90', y=selected_LAB_pos[:, 1], x=thetaVs, mode='lines+markers', marker=dict(color='red'), line=dict(color='red'))) figure.add_trace( go.Scatter(name='b* 0 to 90', y=selected_LAB_pos[:, 2], x=thetaVs, mode='lines+markers', marker=dict(color='blue'), line=dict(color='blue'))) selected_XYZ_neg = tristimulus_XYZ[:, phiVs == selected_phi[1]][:, 0, :] selected_XYZ_neg = np.array([ clr.XYZ_to_Lab(selected_XYZ_neg[i] / 100) for i in range(selected_XYZ_neg.shape[0]) ]) figure.add_trace( go.Scatter(name='L* -90 to 0', y=selected_XYZ_neg[:, 0], x=-thetaVs, mode='lines+markers', marker=dict(color='yellow'), line=dict(color='yellow'))) figure.add_trace( go.Scatter(name='a* -90 to 0', y=selected_XYZ_neg[:, 1], x=-thetaVs, mode='lines+markers', marker=dict(color='red'), line=dict(color='red'))) figure.add_trace( go.Scatter(name='b* -90 to 0', y=selected_XYZ_neg[:, 2], x=-thetaVs, mode='lines+markers', marker=dict(color='blue'), line=dict(color='blue'))) else: raise PreventUpdate figure.update_layout( title="CIELab values dependence on viewing zenith angle", xaxis_title='CIELab units', yaxis_title='Viewing zenith angle Theta (deg)') return figure
extend = np.array([ np.ones(24), CameraXYZ[0], CameraXYZ[1], CameraXYZ[2], CameraXYZ[0, :] * CameraXYZ[1, :], CameraXYZ[1, :] * CameraXYZ[2, :], CameraXYZ[2, :] * CameraXYZ[0, :], CameraXYZ_2[0], CameraXYZ_2[1], CameraXYZ_2[2], CameraXYZ[0, :] * CameraXYZ[1, :] * CameraXYZ[2, :], CameraXYZ_3[0], CameraXYZ_3[1], CameraXYZ_3[2] ]) C = spectrumXYZ @ pinv(extend) CorrectXYZ = C @ extend Lab1 = colour.XYZ_to_Lab(CorrectXYZ.T, illuminant=colour.XYZ_to_xy(d65)) / 100 LabRGB11 = (colour.XYZ_to_sRGB(CameraXYZ.T / 100) * 255).astype(np.uint8) Lab2 = colour.XYZ_to_Lab(spectrumXYZ.T / 100) LabRGB21 = (colour.XYZ_to_sRGB(spectrumXYZ.T / 100) * 255).astype(np.uint8) C_CIE76= np.sqrt(np.sum((Lab1 - Lab2) ** 2, 1)) C_AvgCIE76 = np.mean(C_CIE76) C_CIE2000 = colour.delta_E_CIE2000(Lab1, Lab2).T C_AvgCIE2000 = np.mean(C_CIE2000) i = 24 RMSE_XYZ = np.sqrt(np.sum(CorrectXYZ[:, :i] - spectrumXYZ[:, :i]) ** 2 / 3) RMSE_allXYZ = np.sum(RMSE_XYZ / 24) coeff, scores, latent, explained = pca(color_Rspectrum.T, centered=False) EV = coeff[:, :12]
im_xyz = raw.postprocess( #user_wb = user_wb, use_camera_wb=True, output_bps=16, output_color=rp.ColorSpace.XYZ, gamma=(1, 1)).astype(float) / (2.0**16 - 1) # rgb = raw.postprocess(user_wb = user_wb) # plt.imshow(rgb) # plt.show() fig, axs = plt.subplots() dEs = np.zeros((4, 6), dtype=np.float) for i in range(0, 24): sample = im_xyz[box[i][1]:box[i][3], box[i][0]:box[i][2]] mean_xyz = [np.mean(sample[:, :, x]) for x in range(0, 3)] dE = colour.delta_E( colour.XYZ_to_Lab( mean_xyz, illuminant=colour. ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65']), colour.XYZ_to_Lab( cc[i], illuminant=colour. ILLUMINANTS['CIE 1931 2 Degree Standard Observer']['D65'])) #print(dE) dEs[int(i / 6)][i % 6] = dE # vis = np.tile(mean_xyz, [120, 120, 1]) # vis2 = np.tile(cc[i], [120, 120, 1]) # fig, (ax1, ax2, ax3) = plt.subplots(1, 3) # ax1.imshow(sample) # ax2.imshow(vis) # ax3.imshow(vis2) # plt.show()
print(img.size) # 像素數量 print(img.dtype) # 數據類型 print(img) # 列印圖像的numpy數組,3緯數組 #%% # 網址1:https://colour.readthedocs.io/en/v0.3.13/generated/colour.sRGB_to_XYZ.html # 網址2:https://colour.readthedocs.io/en/v0.3.7/colour.html # 網址3:https://colour.readthedocs.io/en/v0.3.13/generated/colour.Lab_to_LCHab.html?highlight=lch#colour.Lab_to_LCHab # sRGB_to_XYZ #import colormath #from colormath.color_objects import LabColor, XYZColor #from colormath.color_conversions import convert_color import colour import numpy as np sRGB = [200 / 255, 150 / 255, 100 / 255] RGB = np.array(sRGB) XYZ = colour.sRGB_to_XYZ(sRGB) Lab = colour.XYZ_to_Lab(XYZ) LCHab = colour.Lab_to_LCHab(Lab) L = int(LCHab[0]) C = int(LCHab[1]) ab = int(LCHab[2]) #%% LCHab = ['41', '59', '27'] LCHab = np.array(LCHab) L = int(LCHab[0]) C = int(LCHab[1]) ab = int(LCHab[2]) #%% r = 255 g = 89 b = 0 sRGB = [r / 255, g / 255, b / 255]
def RGB_to_Lab(space, pt): XYZ = colour.RGB_to_XYZ(pt, space.whitepoint, D50, space.RGB_to_XYZ_matrix) return colour.XYZ_to_Lab(XYZ)
print(colour.Luv_to_LCHuv(Luv)) print('\n') LCHuv = (100.00000000, 70.90111393, 24.06324597) message_box(('Converting to "CIE Luv" colourspace from given "CIE LCHuv" ' 'colourspace values:\n' '\n\t{0}'.format(LCHuv))) print(colour.LCHuv_to_Luv(LCHuv)) print('\n') message_box(('Converting to "CIE Lab" colourspace from given "CIE XYZ" ' 'tristimulus values:\n' '\n\t{0}'.format(XYZ))) print(colour.XYZ_to_Lab(XYZ)) print('\n') Lab = (100.00000000, 28.97832184, 30.96902832) message_box(('Converting to "CIE XYZ" tristimulus values from given "CIE Lab" ' 'colourspace values:\n' '\n\t{0}'.format(Lab))) 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))
parser.add_argument('--alpha', type=float, default=1.0) parser.add_argument('--gamma', type=float, default=1.0) args = parser.parse_args() print('load training data') with gzip.open(args.training_data_path, 'rb') as f: raw, jpeg = pickle.load(f) raw = np.array(raw, dtype=np.float32) jpeg = np.array(jpeg, dtype=np.float32) raw /= 255 jpeg /= 255 if args.color_space == 'lab': raw = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(raw)) jpeg = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(jpeg)) print('load xgboost models') with open(args.model_file_path, 'rb') as f: models = pickle.load(f) print('lattice regression') print('define A') lattice_size = args.lut_size lattice_points = np.linspace(0.0, 1.0, lattice_size) A = np.array( [p for p in product(lattice_points, lattice_points, lattice_points)],
""" Showcases *Lightness* computations. """ import numpy as np import colour from colour.utilities.verbose import message_box message_box('"Lightness" Computations') xyY = (0.4316, 0.3777, 0.1008) message_box(('Computing "Lightness" "CIE Lab" reference value for given ' '"CIE xyY" colourspace values:\n' '\n\t{0}'.format(xyY))) print(np.ravel(colour.XYZ_to_Lab(colour.xyY_to_XYZ(xyY)))[0]) print('\n') Y = 10.08 message_box(('Computing "Lightness" using ' '"Glasser, Mckinney, Reilly and Schnelle (1958)" method for ' 'given "luminance" value:\n' '\n\t{0}'.format(Y))) print(colour.lightness_Glasser1958(Y)) print(colour.lightness(Y, method='Glasser 1958')) print('\n') message_box(('Computing "Lightness" using "Wyszecki (1963)" method for ' 'given "luminance" value:\n'
def compute(name, hue, lightness, saturation, output="scss"): """ Outputs different conversations of the given CIECAM02 input. Uses CIECAM with the same "signature" as HLC """ xyz = colour.CIECAM02_to_XYZ( lightness, saturation, hue, WHITEPOINT_D65_2, adapting_luminance, background_luminance, surround = surround, discount_illuminant = discount_illuminant ) xyz_trans = [ value / 100 for value in xyz ] #lab_65_10 = colour.XYZ_to_Lab(xyz_trans, illuminant=ILLUMINANT_D65_10) #lch_65_10 = colour.Lab_to_LCHab(lab_65_10) #hlc_65_10 = [lch_65_10[2], lch_65_10[0], lch_65_10[1]] lab_65_2 = colour.XYZ_to_Lab(xyz_trans, illuminant=ILLUMINANT_D65_2) lch_65_2 = colour.Lab_to_LCHab(lab_65_2) hlc_65_2 = [lch_65_2[2], lch_65_2[0], lch_65_2[1]] #lab_50_10 = colour.XYZ_to_Lab(xyz_trans, illuminant=ILLUMINANT_D50_10) #lch_50_10 = colour.Lab_to_LCHab(lab_50_10) #hlc_50_10 = [lch_50_10[2], lch_50_10[0], lch_50_10[1]] lab_50_2 = colour.XYZ_to_Lab(xyz_trans, illuminant=ILLUMINANT_D50_2) lch_50_2 = colour.Lab_to_LCHab(lab_50_2) hlc_50_2 = [lch_50_2[2], lch_50_2[0], lch_50_2[1]] srgb = colour.XYZ_to_sRGB(xyz_trans) validRGB = True for entry in srgb: if entry > 1: validRGB = False srgb_trans = [ value * 255 for value in srgb ] if validRGB else [0,0,0] hex_trans = rgb_to_hex(srgb) if validRGB else "EXCEEDS" if output == "text": print("NAME :", name) print("CAM-65 :", floatlist([hue, lightness, saturation])) print("XYZ :", floatlist(xyz)) print("LAB-50/2° :", floatlist(lab_50_2)) print("HLC-50/2° :", floatlist(hlc_50_2)) print("LAB-65/2° :", floatlist(lab_65_2)) print("HLC-65/2° :", floatlist(hlc_65_2)) print("sRGB :", floatlist(srgb_trans)) print("HEX :", hex_trans) print("") elif output == "scss": print("$%s: %s;" % (name, hex_trans)) elif output == "print": print("%s = %s" % (name, intlist(lab_50_2))) elif output == "affinity": print("%s = %s" % (name, intlist(lab_65_2)))
print(colour.colorimetry.whiteness_Berger1959(XYZ, XYZ_0)) print("\n") message_box( f'Computing "whiteness" using "Taube (1960)" method for given sample and ' f'reference white "CIE XYZ" tristimulus values matrices:\n\n' f"\t{XYZ}\n" f"\t{XYZ_0}" ) print(colour.whiteness(XYZ, XYZ_0, method="Taube 1960")) print(colour.colorimetry.whiteness_Taube1960(XYZ, XYZ_0)) print("\n") Lab = colour.XYZ_to_Lab(XYZ / 100, colour.XYZ_to_xy(XYZ_0 / 100)) message_box( f'Computing "whiteness" using "Stensby (1968)" method for given sample ' f'"CIE L*a*b*" colourspace array:\n\n\t{Lab}' ) print(colour.whiteness(XYZ, XYZ_0, method="Stensby 1968")) print(colour.colorimetry.whiteness_Stensby1968(Lab)) print("\n") message_box( f'Computing "whiteness" using "ASTM E313" method for given sample ' f'"CIE XYZ" tristimulus values:\n\n\t{XYZ}' ) print(colour.whiteness(XYZ, XYZ_0, method="ASTM E313")) print(colour.colorimetry.whiteness_ASTME313(XYZ))
parser.add_argument('--color_space', type=str, default='lab') parser.add_argument('--lut_size', type=int, default=33) args = parser.parse_args() print('load training data') with gzip.open(args.training_data_path, 'rb') as f: raw, jpeg = pickle.load(f) raw = np.array(raw, dtype=np.float32) jpeg = np.array(jpeg, dtype=np.float32) raw /= 255 jpeg /= 255 if args.color_space == 'lab': raw = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(raw)) jpeg = colour.XYZ_to_Lab(colour.sRGB_to_XYZ(jpeg)) learning_rate = 0.1 max_depth = 20 reg_lambda = 0.5 n_estimators = 100 print('train models') models = [] for i in tqdm(range(3)): if i == 0: c = '(1, 0, 0)' elif i == 1: c = '(0, 1, 0)'