def test_conversion_to_rgb_zero_div(self): """ The formula I grabbed for LCHuv to XYZ had a zero division error in it if the L coord was 0. Check against that here. Issue #13 in the Google Code tracker. """ lchuv = LCHuvColor(0.0, 0.0, 0.0) rgb = convert_color(lchuv, sRGBColor) self.assertColorMatch(rgb, sRGBColor(0.0, 0.0, 0.0))
def Luv_to_LCHuv(cobj, *args, **kwargs): """ Convert from CIE Luv to LCH(uv). """ lch_l = cobj.luv_l lch_c = math.sqrt(math.pow(cobj.luv_u, 2.0) + math.pow(cobj.luv_v, 2.0)) lch_h = math.atan2(float(cobj.luv_v), float(cobj.luv_u)) if lch_h > 0: lch_h = (lch_h / math.pi) * 180 else: lch_h = 360 - (math.fabs(lch_h) / math.pi) * 180 return LCHuvColor( lch_l, lch_c, lch_h, observer=cobj.observer, illuminant=cobj.illuminant)
def lchuv(l, c, h): return convert_color(LCHuvColor(l, c, h), sRGBColor, target_illuminant="d65")
# Plot the colormap for the whole graph if plot_colormap: plt.figure(Ntotal + 1, figsize=(5, 10)) # Define colormap as uniformly distributed colors in CIELch color space Lumas = Lumas_init.copy() while len(Lumas) < Ntotal: Lumas = np.hstack((Lumas, Lumas_init)) hues = np.arange(init_angle, init_angle + nangles * color_angle, color_angle) if repeat_hues: hues = np.hstack((hues * np.ones((nLumas, 1))).transpose()) for iN in range(Ntotal): ax = plt.subplot(Ntotal, 1, iN + 1) plt.axis("off") lch = LCHuvColor(Lumas[iN], chroma, hues[iN]) #print(lch) #rgb = lch.convert_to('rgb', debug=False) rgb = convert_color(lch, sRGBColor) plt.barh(0, 50, 1, 0, color=[rgb.rgb_r / 255., rgb.rgb_g / 255., rgb.rgb_b / 255.]) if save_plots: plt.savefig(out_images + "colormap.png") # Plot graph if plot_graph: plt.figure(Ntotal + 2) labels = {} for i in range(Ntotal):
LabColor(Lumas[permutation[i2]],chroma,hues[permutation[i2]]) ) if use_input_weights: DE = np.sum((delta_matrix * neighbor_matrix)) else: DE = np.sum(delta_matrix) # Store the color permutation with the maximum adjacency cost if DE > DEmax: DEmax = DE permutation_max = permutation if verbose: print count count += 1 # Color subgraphs if plot_graph_color: plt.figure(Ntotal+2) for iN in range(N): ic = np.int(permutation_max[iN]) lch = LCHuvColor(Lumas[ic],chroma,hues[ic]) rgb = convert_color(lch,sRGBColor) coloring = np.array([rgb.rgb_r, rgb.rgb_g, rgb.rgb_b]) coloring[coloring > 1] = 1 nx.draw_networkx_nodes(g,pos,node_size=graph_node_size,nodelist=[g.node.keys()[iN]],node_color=coloring) f.write(str(coloring[0]) + ', ' + str(coloring[1]) + ', ' + str(coloring[2]) + '\n') plt.savefig(out_images + "graph_" + vers + ".png") f.close()
def setUp(self): self.color = LCHuvColor(1.807, 2.715, 199.228)
def test_conversion_to_lchuv(self): lch = convert_color(self.color, LCHuvColor) self.assertColorMatch(lch, LCHuvColor(1.807, 2.715, 199.222))
# Plot the colormap for the whole graph if plot_colormap: plt.figure(Ntotal + 1, figsize=(5, 10)) # Define colormap as uniformly distributed colors in CIELch color space Lumas = Lumas_init.copy() while len(Lumas) < Ntotal: Lumas = np.hstack((Lumas, Lumas_init)) hues = np.arange(init_angle, init_angle + nangles * color_angle, color_angle) if repeat_hues: hues = np.hstack((hues * np.ones((nLumas, 1))).transpose()) for iN in range(Ntotal): ax = plt.subplot(Ntotal, 1, iN + 1) plt.axis("off") lch = LCHuvColor(Lumas[iN], chroma, hues[iN]) #print(lch) rgb = lch.convert_to('rgb', debug=False) plt.barh(0, 50, 1, 0, color=[rgb.rgb_r / 255., rgb.rgb_g / 255., rgb.rgb_b / 255.]) if save_plots: plt.savefig(out_images + "colormap.png") # Plot graph if plot_graph: plt.figure(Ntotal + 2) labels = {} for i in range(Ntotal): labels[i] = G.node[i]['abbr']
nangles = Ntotal # Plot the colormap for the whole graph if plot_colormap: plt.figure(Ntotal+1,figsize=(5,10)) # Define colormap as uniformly distributed colors in CIELch color space Lumas = Lumas_init.copy() while len(Lumas) < Ntotal: Lumas = np.hstack((Lumas,Lumas_init)) hues = np.arange(init_angle, init_angle + nangles*color_angle, color_angle) if repeat_hues: hues = np.hstack((hues * np.ones((nLumas,1))).transpose()) for iN in range(Ntotal): ax = plt.subplot(Ntotal, 1, iN+1) plt.axis("off") lch = LCHuvColor(Lumas[iN], chroma, hues[iN]) #print(lch) rgb = lch.convert_to('rgb', debug=False) plt.barh(0,50,1,0, color=[rgb.rgb_r/255.,rgb.rgb_g/255.,rgb.rgb_b/255.]) if save_plots: plt.savefig(out_images + "colormap.png") # Plot graph if plot_graph: plt.figure(Ntotal+2) labels={} for i in range(Ntotal): labels[i] = G.node[i]['abbr'] pos = nx.graphviz_layout(G,prog="neato") nx.draw(G,pos,node_color='cyan',node_size=graph_node_size,width=graph_edge_width,with_labels=False) nx.draw_networkx_labels(G, pos, labels, font_size=graph_font_size, font_color='black') plt.axis('off')