def showAffectation(color_center, centre): max_color = max_reading(color_center) fig = plt.figure() for i in range(0,len(color_center) ): if i < 6: plt.scatter(i, 0, s=800, marker='o', c= t255to01(centre[i],max_color) ) for j in range (0 , len(color_center[i])): plt.scatter(i, 10 + j* 5, s=800, marker='o', c= t255to01(color_center[i][j], max_color) ) plt.show()
def test_rgb_3D(data): x, y, color, c, max_color = donnees(data) Fig = plt.figure() ax = plt.axes(projection='3d') for s, side in enumerate(data): for f, (r,g,b) in enumerate(side): ax.scatter3D(data[s][f][0], data[s][f][1], data[s][f][2], c=t255to01(data[s][f],max_color), cmap=data) plt.show()
def draw_rgb_debut(data): x, y, color, c, max_color = donnees(data) n = 9 m = 6 #color_center = [[] * 54] * 6 color_center = [] for k in range(0,6): color_center.append([]) cccc = [] compteur = 0 print " JESUIS CENTRE ", c for s, side in enumerate(data): for f, (r,g,b) in enumerate(side): indice = 0 min_color = max_color size = len(c) for i in range(0,size): rr = abs(r - c[i][0]) gg = abs(g - c[i][1]) bb = abs(b - c[i][2]) if (min_color > ((rr +gg+bb)/3) ): min_color = (rr +gg+bb)/3 indice = i #print indice color_center[indice].append( [r,g,b] ) #print ' JESUIS FACE ' , s , ' EN FACET ', f , ' JAJOUTE DANS ' , indice , ' COMPTEUR ' , compteur #print color_center[indice] nb_erreur = 0 for i in range(0, len(color_center)): for j in range (0, len(color_center[i])): dedans = False for k in range(0, len(data[i])): if sameColor( color_center[i][j], data[i][k]): dedans = True if dedans == False: nb_erreur += 1 print float(nb_erreur)/54 *100 , "% d erreur " , nb_erreur , " sur " , 54 for i in range(0,len(color_center) ): #print ' COULEUR SIDE ', c[i], ' liste facet: ', color_center[i], '\n' tabColor = [] for j in range (0 , len(color_center[i])): plt.scatter(i, 10 + j* 5, s=800, marker='o', c= t255to01(color_center[i][j], max_color) ) plt.scatter(i, 0, s=800, marker='o', c= t255to01(c[i],max_color) ) """ plt.scatter(x, y, s=800, marker='s', c=color) plt.title('Rubik\'s cube unfolding') plt.axis('off') plt.savefig('unfolding.png') """ #showData([R1]) tab_tri = repartition_egal(color_center, c, 9) fig = plt.figure() for i in range(0,len(tab_tri) ): #print ' COULEUR SIDE ', c[i], ' liste facet: ', color_center[i], '\n' tabColor = [] for j in range (0 , len(tab_tri[i])): plt.scatter(i, 10 + j* 5, s=800, marker='o', c= t255to01(tab_tri[i][j], max_color) ) plt.scatter(i, 0, s=800, marker='o', c= t255to01(c[i],max_color) ) plt.show()
def test_hsv(data, data2 = []): x, y, color, c, max_color = donnees(data) centre = couleurCentre(data) centre_hsv = [] tab_hsv = [] tab_rgb, data_rgb = [], [] #conversion centre rgb to hsv for i in range(0, len(centre)): color = t255to01(centre[i],max_color) #print " couleur des donnees : " , data[1][4] , " couleur en format 0-1 : ", color centre_hsv.append( colorsys.rgb_to_hsv(color[0], color[1], color[2]) ) #test sur toutes les facets data_hsv ,color_center, tab_rgb = [], [], [] for i in range(0, len(data)): data_hsv.append([]) color_center.append([]) tab_hsv.append([]) tab_rgb.append([]) """ Fig = plt.figure() ax = plt.axes(projection='3d') """ for s, side in enumerate(data): for f, (r,g,b) in enumerate(side): data_hsv[s].append( colorsys.rgb_to_hsv( float(r)/max_color, float(g)/max_color, float(b)/max_color) ) min_distance = 100000 indice = 0 for i in range(0, len(centre_hsv)): dist = distance_hsv(data_hsv[s][f], centre_hsv[i]) if dist < min_distance: min_distance = dist indice = i color_center[indice].append( [r,g,b] ) tab_hsv[indice].append( data_hsv[s][f] ) """ ax.scatter3D(data_hsv[s][f][0], data_hsv[s][f][1], data_hsv[s][f][2], c=t255to01(data[s][f],max_color), cmap=data) """ if len(data2) > 0: taux_erreur(data2, color_center) fig = plt.figure() for i in range(0,len(color_center) ): for j in range (0 , len(color_center[i])): plt.scatter(i, 10 + j* 5, s=800, marker='o', c= rgb255to01(color_center[i][j], max_color) ) plt.scatter(i, 0, s=800, marker='o', c= t255to01(centre[i],max_color) ) tab_repar = repartition_egal(tab_hsv, centre_hsv, 9, False) fig = plt.figure() for i in range(0,len(tab_repar) ): for j in range (0 , len(tab_repar[i])): color = colorsys.hsv_to_rgb( tab_repar[i][j][0], tab_repar[i][j][1], tab_repar[i][j][2]) plt.scatter(i, 10 + j* 5, s=800, marker='o', c= color) plt.scatter(i, 0, s=800, marker='o', c= t255to01(centre[i],max_color) ) plt.show()
def draw_diffRGB(data): x, y, color, c, max_color = donnees(data) n = 9 m = 6 c = couleurCentre(data) color_center = [] for k in range(0,6): color_center.append([]) """ utilisation du filtre uniforme """ for s, side in enumerate(data): for f, (r,g,b) in enumerate(side): if f != 4: indice = 0 min_color = max_color size = len(c) #compare avec chaque centre for i in range(0,size): #calcul la nouvelle nuance de chaque centre color = [0,0,0] for l in range(0,3): color[l] = c[i][l] + diff[i][l] rr = abs(r - color[0]) gg = abs(g - color[1]) bb = abs(b - color[2]) if (min_color > ((rr +gg+bb)/3) ): min_color = (rr +gg+bb)/3 indice = i color_center[indice].append( [r,g,b] ) nb_erreur = 0 for i in range(0, len(color_center)): if ( len(color_center[i]) > 8): nb_erreur += len(color_center[i]) - 8 print float(nb_erreur)/48 *100 , "% d erreur " , nb_erreur , " sur 48" #coeff couleur uniforme plt.figure(0) for i in range(0, len(c)): plt.scatter(i, 0, s=800, marker='s', c=t255to01(c[i], max_color)) #decalage decalage = 5 for j in range (0,len(color_center[i])): plt.scatter(i, decalage + j, s=800, marker='s', c=t255to01(color_center[i][j], max_color) ) c = couleurCentre(data) """ utilisation des filtres cote/coin """ color_center = [] for k in range(0,6): color_center.append([]) for s, side in enumerate(data): for f, (r,g,b) in enumerate(side): if f != 4: indice = 0 min_color = max_color size = len(c) for i in range(0,size): color = [0,0,0] for l in range(0,3): if f%2 == 0: color[l] = c[i][l] + diffCoin[i][l] else: color[l] = c[i][l] + diffCote[i][l] rr = abs(r - color[0]) gg = abs(g - color[1]) bb = abs(b - color[2]) if (min_color > ((rr +gg+bb)/3)): min_color = (rr +gg+bb)/3 indice = i color_center[indice].append( [r,g,b] ) nb_erreur = 0 for i in range(0, len(color_center)): print color_center[i] if ( len(color_center[i]) > 8): nb_erreur += len(color_center[i]) - 8 print float(nb_erreur)/48 *100 , "% d erreur " , nb_erreur , " sur 48" #coeff couleur uniforme plt.figure(1) for i in range(0, len(c)): plt.scatter(i, 0, s=800, marker='s', c=t255to01(c[i], max_color)) #decalage decalage = 5 for j in range (0,len(color_center[i])): plt.scatter(i, decalage + j, s=800, marker='s', c=t255to01(color_center[i][j], max_color) ) plt.show()