import numpy as np
import cv2
from sklearn.cluster import KMeans
from sklearn.cluster import MiniBatchKMeans

image = cv2.imread('image.jpg')
(h1, w1) = image.shape[:2]

image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)

image = image.reshape((image.shape[0] * image.shape[1], 3))

clt = KMeans(n_clusters = 5)

labels = clt.fit_predict(image)
quant = clt.cluster_centers_.astype("uint8")[labels]

#reshape the feature vectors to images
quant = quant.reshape((h1, w1, 3))
image = image.reshape((h1, w1, 3))

# convert from L*a*b* to RGB
quant = cv2.cvtColor(quant, cv2.COLOR_LAB2BGR)
image = cv2.cvtColor(image, cv2.COLOR_LAB2BGR)

cv2.imwrite('generated.jpg', quant)
cv2.waitKey(0)
cv2.destroyAllWindows()

c2cd72a301b194cbb6c3bb34dbdab779717bae91
<mask token>

<mask token>
cv2.imwrite('generated.jpg', quant)
cv2.waitKey(0)
cv2.destroyAllWindows()

<mask token>
image = cv2.imread('image.jpg')
h1, w1 = image.shape[:2]
image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
image = image.reshape((image.shape[0] * image.shape[1], 3))
clt = KMeans(n_clusters=5)
labels = clt.fit_predict(image)
quant = clt.cluster_centers_.astype('uint8')[labels]
quant = quant.reshape((h1, w1, 3))
image = image.reshape((h1, w1, 3))
quant = cv2.cvtColor(quant, cv2.COLOR_LAB2BGR)
image = cv2.cvtColor(image, cv2.COLOR_LAB2BGR)
cv2.imwrite('generated.jpg', quant)
cv2.waitKey(0)
cv2.destroyAllWindows()

import numpy as np
import cv2
from sklearn.cluster import KMeans
from sklearn.cluster import MiniBatchKMeans
image = cv2.imread('image.jpg')
h1, w1 = image.shape[:2]
image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)
image = image.reshape((image.shape[0] * image.shape[1], 3))
clt = KMeans(n_clusters=5)
labels = clt.fit_predict(image)
quant = clt.cluster_centers_.astype('uint8')[labels]
quant = quant.reshape((h1, w1, 3))
image = image.reshape((h1, w1, 3))
quant = cv2.cvtColor(quant, cv2.COLOR_LAB2BGR)
image = cv2.cvtColor(image, cv2.COLOR_LAB2BGR)
cv2.imwrite('generated.jpg', quant)
cv2.waitKey(0)
cv2.destroyAllWindows()

import numpy as np
import cv2
from sklearn.cluster import KMeans
from sklearn.cluster import MiniBatchKMeans

image = cv2.imread('image.jpg')
(h1, w1) = image.shape[:2]

image = cv2.cvtColor(image, cv2.COLOR_BGR2LAB)

image = image.reshape((image.shape[0] * image.shape[1], 3))

clt = KMeans(n_clusters = 5)

labels = clt.fit_predict(image)
quant = clt.cluster_centers_.astype("uint8")[labels]

#reshape the feature vectors to images
quant = quant.reshape((h1, w1, 3))
image = image.reshape((h1, w1, 3))

# convert from L*a*b* to RGB
quant = cv2.cvtColor(quant, cv2.COLOR_LAB2BGR)
image = cv2.cvtColor(image, cv2.COLOR_LAB2BGR)

cv2.imwrite('generated.jpg', quant)
cv2.waitKey(0)
cv2.destroyAllWindows()
