Advertisement
Guest User

Untitled

a guest
Jan 28th, 2020
137
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.28 KB | None | 0 0
  1. import cv2
  2. import matplotlib.pyplot as plt
  3. import time
  4. import itertools as it
  5. from mpl_toolkits.mplot3d import Axes3D
  6. from sklearn.cluster import KMeans
  7. from multiprocessing import Pool, cpu_count
  8. from tqdm import tqdm
  9.  
  10.  
  11. def rgb_hex(rgb):
  12. return "#{:02x}{:02x}{:02x}".format(int(rgb[0]), int(rgb[1]), int(rgb[2]))
  13.  
  14. def processing(reform,cluster):
  15. fig = plt.figure()
  16. ax = Axes3D(fig)
  17. #zip(cluster.labels_,reform)
  18. for color in tqdm(reform):
  19. ax.scatter(color[0], color[1], color[2], color = rgb_hex(color))
  20. plt.savefig('figura.png')
  21. plt.show()
  22.  
  23. def funkcja(x):
  24. image = cv2.imread(x)
  25. image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
  26. #print('Wczytano zdjęcie i zamieniono na tablice pixeli')
  27. reform = image.reshape((image.shape[0] * image.shape[1], 3))
  28. cluster = KMeans(5).fit(reform)
  29. colors=cluster.cluster_centers_
  30. start = time.time()
  31. #print('Rozkładanie punktów w układzie')
  32. print('...')
  33. pool = Pool(cpu_count())
  34. results = pool.map(processing(reform,cluster))
  35. end = time.time()
  36. print('Kolorowanie zajęło: ',"{0:.2f}".format(end-start),'s')
  37.  
  38.  
  39. #print('Analiza kolorów elementów stron internetowych')
  40. funkcja('C:/Users/Peter/Desktop/praca/python/test/google.com.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement