PYTHON CODING
- waclaw_koscielniak

- Oct 15, 2025
- 1 min read
import numpy as np
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
from sklearn.cluster import KMeans
image = mpimg.imread('Baby_dinosaur.jpg')
w, h, d = image.shape
pixels = image.reshape(w * h, d)
n_colors = 16
kmeans = KMeans(n_clusters=n_colors, random_state=42).fit(pixels)
palette = np.uint8(kmeans.cluster_centers_)
plt.imshow([palette])
plt.axis('off')
plt.show()
#Python #PythonCoding #VSC



Try to run it.