K-means for a grayscale image
5 ビュー (過去 30 日間)
古いコメントを表示
I've tried the below code to cluster the grayscale image,
I = imread('sym_059.tif');
I = im2double(I);
c = kmeans(I, 3);
p = reshape(c, size(I));
executing this code, I am getting error as follows "Error using reshape-To RESHAPE the number of elements must not change." How can I debug this.? Help appreciated.
8 件のコメント
Image Analyst
2018 年 10 月 24 日
Try my code (hidden in the comments above), NOT the code that anusha says there is a problem with.
採用された回答
Walter Roberson
2016 年 5 月 29 日
kmeans returns a vector of cluster indices, one index per row of input. You are trying to reshape that as if it had as many entries as the number of pixels in your image.
Possibly you want to try
c = kmeans(I(:), 3);
21 件のコメント
Salma Hassan
2021 年 6 月 27 日
編集済み: Image Analyst
2021 年 6 月 27 日
What about several images? How can I cluster them into k clusters?
Walter Roberson
2021 年 6 月 27 日
Provided the images are the same number of pixels, and are all RGB or are all grayscale, then construct an array in which each row is reshape() of an image into a single row, and the rows correspond to different images. Then kmeans() .
This would attempt to cluster the images as a whole into clusters.
その他の回答 (1 件)
Image Analyst
2021 年 4 月 16 日
- kmeans hyperspectral 1.bmp
- kmeans hyperspectral 2.bmp
- kmeans hyperspectral 3.bmp
- kmeans hyperspectral 4.bmp
- kmeans hyperspectral 5.bmp
- kmeans hyperspectral 6.bmp
- kmeans_color_segmentation.m
- kmeans_for_angles.m
- kmeans_grayscale_brain.png
- kmeans_grayscale_segmentation.m
- kmeans_hyperspectral_segmentation.m
- kmeans_relabel_class_numbers.m
Demos for kmeans for images attached.
0 件のコメント
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!