histCosineKmeanDisplay.py 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637
  1. import matplotlib.pyplot as plt
  2. from . import KmeanDisplay
  3. class histCosineKmeanDisplay(KmeanDisplay.KmeanDisplay):
  4. """description of class"""
  5. def __init__(self, L_mean, L_std, pcolor= None):
  6. # map of image according to Lightness mean and std
  7. self.L_mean = L_mean
  8. self.L_std = L_std
  9. # colors
  10. self.colors = ['b', 'g','r','c','m','y','k'] if pcolor == None else pcolor
  11. # figure and axes
  12. fig, ax = plt.subplots(1,2)
  13. fig.suptitle('Histogram Classification by k-means[cosine distance]')
  14. self.fig = fig
  15. self.axes = ax
  16. def plot(self, centroids, assigmentsIdx, iter):
  17. # display centroids shape
  18. self.axes[0].cla()
  19. for i,c in enumerate(centroids): self.axes[0].plot(c,self.colors[i%len(self.colors)])
  20. self.axes[0].set_title("centroids (iter:"+str(iter)+")")
  21. # display assigments
  22. if isinstance(L_mean, np.ndarray) and isinstance(L_std,np.ndarray):
  23. self.axes[1].cla()
  24. self.axes[1].set_title("assigments map")
  25. for i,assigmentId in enumerate(assigmentsIdx):
  26. self.axes[1].plot(L_mean[assigmentId],L_std[assigmentId],self.colors[i%len(self.colors)]+'o', markersize=5)
  27. plt.pause(0.05)