im = imread('hestain.png');
im=rgb2gray(im) //if you only want grayscale intensities
[idx centroids]=kmeans(double(im(:)),4);
??? Error using ==> kmeans>batchUpdate at 436
Empty cluster created at iteration 1.
Error in ==> kmeans at 337
converged = batchUpdate();
Error in ==> Untitled2 at 5
[idx centroids]=kmeans(double(im(:)),4);
Does anyone help ?
Thanks.

답변 (2개)

Walter Roberson
Walter Roberson 2014년 3월 15일

0 개 추천

Look at the documentation page, at the 'emptyaction' option.
Image Analyst
Image Analyst 2014년 3월 15일

0 개 추천

Evidently you've adapted the demo at this web page to your image incorrectly. You don't have clusters because you don't have a second axis. You just passed in a 1D vector. What is the other axis that you think you have that forms clusters?

댓글 수: 6

Tomas
Tomas 2014년 3월 15일
i want coordinates position points in image and color
Image Analyst
Image Analyst 2014년 3월 15일
That does not make sense. You need to study up some more on what kmeans means.
I understand k means method. I don't understand image proccesing and computer vision.
give examples about what I need
in binary images
I,map]=imread('test3','bmp');
I = ~I;
imshow(I,map);
[m n]=size(I)
P = [];
for i=1:m
for j=1:n
if I(i,j)==1
P = [P ; i j];
end
end
end
size(P)
MON=P;
[IDX,ctrs] = kmeans(MON,3)
clusteredImage = zeros(size(I));
clusteredImage(sub2ind(size(I) , P(:,1) , P(:,2)))=IDX;
imshow(label2rgb(clusteredImage))
my output:
I need this also with grayscale and RGB image.
You can do simple color classification by simple thresholding in RGB color space with that image. No kmeans clustering is needed. See my rgb color classification demo in my File Exchange: http://www.mathworks.com/matlabcentral/fileexchange/?term=authorid%3A31862 For example if you want a map (binary image) of where all the pure blue, cyan, or yellow pixels are, you simply do this:
% Extract the individual red, green, and blue color channels.
redChannel = rgbImage(:, :, 1);
greenChannel = rgbImage(:, :, 2);
blueChannel = rgbImage(:, :, 3);
pureYellowPixels = redChannel == 255 & greenChannel == 255 & blueChannel == 0;
pureCyanPixels = redChannel == 0 & greenChannel == 255 & blueChannel == 255;
pureBluePixels = redChannel == 0 & greenChannel == 0 & blueChannel == 255;
If you want a N by 2 listing of all the (row, column) pairs where the pixels lie, just do this:
[rowsY, columnsY] = find(pureYellowPixels);
[rowsC, columnsC] = find(pureCyanPixels);
[rowsB, columnsB] = find(pureBluePixels);
But that kind of thing is rarely needed.
Tomas
Tomas 2014년 3월 15일
ok, Thank you for your time and help.
I have to use clustering methods.
My graduation theses is about cluster analysis.
Image Analyst
Image Analyst 2014년 3월 16일
Then you must know more about it than me. So again I ask you what are the two measures, what are the two axes that something is going to be plotted against, if you're not going to use the locations (rows, columns) like I derived for you? And if you do use those, then there's no need to classify because the classification was done first in order to get the coordinates.

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

카테고리

도움말 센터File Exchange에서 Deep Learning for Image Processing에 대해 자세히 알아보기

질문:

2014년 3월 15일

댓글:

2014년 3월 16일

Community Treasure Hunt

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

Start Hunting!

Translated by