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

1 回表示 (過去 30 日間)
Frank
Frank 2016 年 6 月 21 日
回答済み: DGM 2024 年 12 月 27 日
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'

回答 (2 件)

Vidip
Vidip 2024 年 12 月 27 日
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 2024 年 12 月 27 日
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.

カテゴリ

Help Center および File ExchangeStatistics and Machine Learning Toolbox についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by