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

조회 수: 1 (최근 30일)
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 CenterFile Exchange에서 Statistics 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