daily pastebin goal
49%
SHARE
TWEET

quantify-kmeans.py

a guest Feb 19th, 2013 109 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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)
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top