Advertisement
Guest User

quantify-kmeans.py

a guest
Feb 19th, 2013
246
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.37 KB | None | 0 0
  1. #!/usr/bin/env python2
  2.  
  3. from sys import argv
  4. from PIL import Image
  5. from scipy.cluster.vq import kmeans2
  6. import numpy
  7.  
  8. _, path_in, k, path_out = argv
  9. img = Image.open(path_in).convert('RGB')
  10. centroid, label = kmeans2(numpy.array(img.getdata()), int(k))
  11. centroid = numpy.around(centroid).astype('int')
  12. img.putdata([tuple(centroid[l]) for l in label])
  13. img.save(path_out)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement