How can I change each pixel value in a cluster using k-means algorithm to different colors

2 views (last 30 days)
I am using k-means for segmentation and I have five clusters. I analyze each clusters and find the mean value of each cluster. I then sort each cluster based on the mean value in ascending order. What I want to do is make each pixel value associated with a cluster a different color (e.g. cluster1 = 'red', cluster2 = 'green', cluster3 = 'brown', cluster4 = 'cyan', cluster5 = 'yellow'

Answers (2)

Vidip
Vidip on 27 Dec 2024
I understand that you are using k-means for segmentation and want to assign different colors to each cluster. Please refer to the below MATLAB Answer which discusses about a apporoach which can be followed for the same: https://in.mathworks.com/matlabcentral/answers/561650-how-can-i-add-colors-to-a-k-means-gscatter-plot-based-on-a-certain-cluster

DGM
DGM on 27 Dec 2024
Create a label array from the segmentation. Create a color table associating each label to a desired color -- either the mean color for each cluster or some arbitrarily chosen color. Then use labeloverlay() to apply both to the original image.
If the entire image is labeled, you don't need to use labeloverlay(), since the label array then constitutes an indexed color image. Just use ind2rgb() or use any one of the image formats which support indexed color.

Categories

Find more on Statistics and Machine Learning Toolbox in Help Center and File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!