Last active
August 29, 2015 13:57
-
-
Save arosh/9362385 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# coding: utf-8 | |
import sys | |
import numpy | |
from scipy.misc import imread, imsave | |
from scipy.cluster.vq import kmeans2 | |
def main(): | |
if len(sys.argv) == 2: | |
ifname = sys.argv[1] | |
else: | |
ifname = './shinchoku.jpg' | |
k = 31 | |
src_image = imread(ifname) | |
dots = src_image.reshape((src_image.shape[0]*src_image.shape[1], src_image.shape[2])) | |
centroid, label = kmeans2(dots, k) | |
centroid = centroid.astype(numpy.uint8) | |
dst_image = centroid[label] | |
dst_image = dst_image.reshape((src_image.shape[0], src_image.shape[1], src_image.shape[2])) | |
imsave('dst_image.bmp', dst_image) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment