Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import imagehash as img
- MAX_DIST = 256
- def center(hashes):
- d = MAX_DIST
- cnt = None
- for i in range(len(hashes)-1):
- maxd = 0
- for j in range(i+1,len(hashes)):
- temp = img.hex_to_hash(hashes[i]) - img.hex_to_hash(hashes[j])
- if temp > maxd:
- maxd = temp
- if maxd < d:
- d = maxd
- cnt = hashes[i]
- return cnt, d
- f = open(r"E:\coins\coin_hash.txt", "r")
- buf = f.read()
- f.close()
- allhash = eval(buf)
- tres = allhash[3]
- cluster = {}
- for trihash in tres:
- if not cluster.keys():
- cluster[trihash] = {'neib':[trihash], 'dist': MAX_DIST}
- else:
- mind = MAX_DIST
- minkey = None
- for clus in cluster.keys():
- d = img.hex_to_hash(clus)-img.hex_to_hash(trihash)
- if d < mind:
- minkey = clus
- mind = d
- if mind > 25:
- cluster[trihash] = {'neib': [trihash], 'dist': MAX_DIST}
- else:
- cluster[minkey]['neib'].append(trihash)
- c, dist = center(cluster[minkey]['neib'])
- if c != minkey:
- cluster[c]=cluster[minkey]
- del cluster[minkey]
- cluster[c]['dist'] = dist
- print(cluster)
Advertisement
Add Comment
Please, Sign In to add comment