Image Segmentation Using K means

When I execute the following command in Matlab 2012a
centroid=kmeans(imread('image.jpg'),4);
I get the following error
Error using +
Integers can only be combined with integers of the same class, or scalar doubles.
Error in kmeans>distfun (line 659)
*D(:,i) = D(:,i) + (X(:,j) - C(i,j)).^2;*
*Error in kmeans (line 273)*
*D = distfun(X, C, distance, 0, rep, reps);*
I need to segment this image into 4 cluster. This image is a CT Brain tumour Image. Size of this image is 233 x 216. Please give me a solution to cluster this image file.

답변 (3개)

Walter Roberson
Walter Roberson 2013년 6월 29일

0 개 추천

YourImage = imread('Image.jpg');
centroid = kmeans(double(YourImage), 4);
Note: if your .jpg is color rather than greyscale, you will probably need to convert it to greyscale before clustering.

댓글 수: 5

Octa
Octa 2013년 6월 29일
I got it. Your reason is correct.
Instead of using kmeans for segmenting, I used the default kmeans in MATLAB. So this error occurred. Now my program is working by using the kmeans segmentation algorithm.
Thanks for commenting on my doubt.
Image Analyst
Image Analyst 2013년 6월 29일
Do you want to cluster based on intensity of pixels (e.g. you want 4 gray level classes), or you want to find spatial clusters (e.g. 4 clumps of spatially separated pixels)?
Octa
Octa 2013년 7월 2일
I want kmeans to cluster based on the intensity of pixels, so I used the kmeans Segmentation algorithm and got the output.
Thank you for your comment
syed salma banu s
syed salma banu s 2018년 12월 31일
sir i need to cluster the image based on intensity of pixels e.g. i want 3 gray level classes
Walter Roberson
Walter Roberson 2018년 12월 31일
convert the image to grayscale and kmeans requesting 3 clusters .

댓글을 달려면 로그인하십시오.

moahaimen talib
moahaimen talib 2017년 4월 10일

0 개 추천

hi i need to use kmean for segmenting and clustering a binary image please help

질문:

2013년 6월 29일

댓글:

2018년 12월 31일

Community Treasure Hunt

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

Start Hunting!

Translated by