Guest User

quantify-kmeans.py

a guest
Feb 19th, 2013
143
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

Adblocker detected! Please consider disabling it...

We've detected AdBlock Plus or some other adblocking software preventing Pastebin.com from fully loading.

We don't have any obnoxious sound, or popup ads, we actively block these annoying types of ads!

Please add Pastebin.com to your ad blocker whitelist or disable your adblocking software.

×