Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

To resolve issues starting MATLAB on Mac OS X 10.10 (Yosemite) visit: http://www.mathworks.com/matlabcentral/answers/159016

??? Error using ==> kmeans

Asked by ali on 28 Apr 2012

Why this algorithm does not work on my computer. Only displays the original image.

I am using MATLAB Version 7.6.0

1- clc;
2- str1 = strcat('C:\Users\H&m\Desktop\danlod\0-DataSet\312.jpg');
3- he = imread(str1);
4- imshow(he), title('H&E image');
5- ab = double(he(:,:,2:3));
6- nrows = size(ab,1); 
7- ncols = size(ab,2);
8- ab = reshape(ab,nrows*ncols,2);
9- nColors = 6;
10- [cluster_idx cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',5);
11- pixel_labels = reshape(cluster_idx,nrows,ncols);
12- segmented_images = cell(1,nColors);
13- rgb_label = repmat(pixel_labels,[1 1 3]);
14- for k = 1:nColors
     color = he;
     color(rgb_label ~= k) = 0;
     segmented_images{k} = color;    
    end
15-  figure;imshow(segmented_images{1}), title('objects in cluster 1');
16-  figure;imshow(segmented_images{2}), title('objects in cluster 2');
17-  figure;imshow(segmented_images{3}), title('objects in cluster 3');
18-  figure;imshow(segmented_images{4}), title('objects in cluster 4');
19-  figure;imshow(segmented_images{5}), title('objects in cluster 5');
20-  figure;imshow(segmented_images{6}), title('objects in cluster 6');# #   
|??? Error using ==> kmeans
Too many input arguments.
Error in ==> KMeans at 10
[cluster_idx cluster_center] = kmeans('ab','nColors','distance','sqEuclidean','Replicates',5);
>>| 

thanks...

0 Comments

ali

Tags

Products

No products are associated with this question.

1 Answer

Answer by Walter Roberson on 28 Apr 2012

Your code does not match your error message. The error message says

kmeans('ab','nColors','distance','sqEuclidean','Replicates',5);

but your code says

kmeans(ab,nColors,'distance','sqEuclidean','Replicates',5);

The first two arguments should not be quoted strings, and if they were quoted strings then you would get the error message that you indicate.

1 Comment

M@lik Ali on 12 Jul 2012

I am also getting the same error

i am using kmeans like

opts = statset('Display','final');
[idx,ctrs] = kmeans(QF,8,...
                  'Distance','city',...
                  'Replicates',5,...
                  'Options',opts);
the error is 
??? Error using ==> kmeans
Too many input arguments.
Error in ==> imgdivision at 139
[idx,ctrs] = kmeans(QF,8,...

I am using the matlab version 7.10 win 32

Walter Roberson

Contact us