I am a newbie in computer vision, and I am trying to do a plot to summarize color identification on an image. I have used KMeans to find the pixel values I needed to detect. But I would like to improve the code with visualization on a palette or a pie chart. I think I should count the pixel's values falling on each cluster. However, I just got stuck, and I do not know how to do it.
from sklearn.cluster import KMeans
import matplotlib.pyplot as plt
import numpy as np
from collections import Counter
from skimage import io, color
def kmeans_segementation(image, n_clusters, random_state=0):
rows, cols, channels = image.shape #get the image shape
X = image.reshape(rows*cols, channels)
kmeans = KMeans(n_clusters=n_clusters, random_state=0).fit(X)
labels = kmeans.labels_.reshape(rows, cols)
labels = kmeans.cluster_centers_ # get group of colors
ordered_colors = [labels[key] for key,value in enumerate(labels)]
print(ordered_colors)
img2_rgb = io.imread('frame41.png')
n_clusters = 15
kmeans_segementation(img2_rgb, n_clusters, random_state=0)


