In [1]:
import imgfun
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import numpy as np
from PIL import Image
%matplotlib inline
Show the original image
In [2]:
img = np.array(Image.open('obama.jpg'))
plt.imshow(img)
Out[2]:
Now run K-means clustering on the pixels and set pixel colors to cluster centers
In [4]:
kimg = imgfun.GenKmeansImage(img, 5) # takes a few seconds
plt.imshow(kimg)
Out[4]:
In [ ]: