Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import cv2
- import matplotlib.pyplot as plt
- import time
- import itertools as it
- from mpl_toolkits.mplot3d import Axes3D
- from sklearn.cluster import KMeans
- from multiprocessing import Pool, cpu_count
- from tqdm import tqdm
- def rgb_hex(rgb):
- return "#{:02x}{:02x}{:02x}".format(int(rgb[0]), int(rgb[1]), int(rgb[2]))
- def processing(reform,cluster):
- fig = plt.figure()
- ax = Axes3D(fig)
- #zip(cluster.labels_,reform)
- for color in tqdm(reform):
- ax.scatter(color[0], color[1], color[2], color = rgb_hex(color))
- plt.savefig('figura.png')
- plt.show()
- def funkcja(x):
- image = cv2.imread(x)
- image = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
- #print('Wczytano zdjęcie i zamieniono na tablice pixeli')
- reform = image.reshape((image.shape[0] * image.shape[1], 3))
- cluster = KMeans(5).fit(reform)
- colors=cluster.cluster_centers_
- start = time.time()
- #print('Rozkładanie punktów w układzie')
- print('...')
- pool = Pool(cpu_count())
- results = pool.map(processing(reform,cluster))
- end = time.time()
- print('Kolorowanie zajęło: ',"{0:.2f}".format(end-start),'s')
- #print('Analiza kolorów elementów stron internetowych')
- funkcja('C:/Users/Peter/Desktop/praca/python/test/google.com.png')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement