Skip to content

Instantly share code, notes, and snippets.

@skt7
Last active January 26, 2018 21:12
Show Gist options
  • Save skt7/3a660ae2b4478349f13b6af6c3e862b8 to your computer and use it in GitHub Desktop.
Save skt7/3a660ae2b4478349f13b6af6c3e862b8 to your computer and use it in GitHub Desktop.
Python code to see which cluster each pixel belong to.
import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
class DominantColors:
def rgb_to_hex(self, rgb):
return '#%02x%02x%02x' % (int(rgb[0]), int(rgb[1]), int(rgb[2]))
def plotClusters(self):
#plotting
fig = plt.figure()
ax = Axes3D(fig)
for label, pix in zip(self.LABELS, self.IMAGE):
ax.scatter(pix[0], pix[1], pix[2], color = self.rgb_to_hex(self.COLORS[label]))
plt.show()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment