![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/320032/image.png)
Index Matrix to RGB Matrix
조회 수: 2 (최근 30일)
이전 댓글 표시
Hi. I have calculated the index matrix from kmeans clustering algorithm. My data set have 16 class and every class is indexed in the matrix. Also my data coming from a image so I have a 145x145 image matrix with variables changing from 1 to 16. I want to color every class in the image. I would be appreciated if you could help me. Thanks.
Note: I have added the matrix.
댓글 수: 0
답변 (2개)
Ameer Hamza
2020년 6월 22일
Which colormap do you want to use. For example, try this
cmap = summer(16);
rgb_imag = ind2rgb(ind_fin, cmap);
imshow(rgb_imag);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/320032/image.png)
댓글 수: 0
Image Analyst
2020년 6월 22일
Here's one way
s = load('kmeansclusteredindex.mat')
ind_fin = s.ind_fin;
subplot(2, 1, 1);
imshow(ind_fin, []);
title('Original Image', 'FontSize', 20);
customColorMap = jet(16); % Use whatever colormap you want.
colormap(customColorMap);
colorbar;
subplot(2, 1, 2);
histogram(ind_fin);
grid on;
title('Histogram', 'FontSize', 20);
xlabel('Class Number', 'FontSize', 20);
ylabel('Pixel Count', 'FontSize', 20);
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/320614/image.png)
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Matrix Indexing에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!