Why the error in kmeans too many argument
Show older comments
i want to segment using k means
i was using the code http://in.mathworks.com/help/images/examples/color-based-segmentation-using-k-means-clustering.html
i am getting the error
seg
Error using kmeans
Too many input arguments.
Error in seg (line 21)
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3);
this is my code
he = imread('soil1.jpe');
imshow(he), title('H&E image');
text(size(he,2),size(he,1)+15,...
'Image courtesy of Alan Partin, Johns Hopkins University', ...
'FontSize',7,'HorizontalAlignment','right');
cform = makecform('srgb2lab');
lab_he = applycform(he,cform);
ab = double(lab_he(:,:,2:3));
nrows = size(ab,1);
ncols = size(ab,2);
ab = reshape(ab,nrows*ncols,2);
nColors = 3;
% repeat the clustering 3 times to avoid local minima
[cluster_idx, cluster_center] = kmeans(ab,nColors,'distance','sqEuclidean','Replicates',3);
pixel_labels = reshape(cluster_idx,nrows,ncols);
imshow(pixel_labels,[]), title('image labeled by cluster index');
segmented_images = cell(1,3);
rgb_label = repmat(pixel_labels,[1 1 3]);
for k = 1:nColors
color = he;
color(rgb_label ~= k) = 0;
segmented_images{k} = color;
end
imshow(segmented_images{1}), title('objects in cluster 1');
imshow(segmented_images{2}), title('objects in cluster 2');
imshow(segmented_images{3}), title('objects in cluster 3');
mean_cluster_value = mean(cluster_center,2);
[tmp, idx] = sort(mean_cluster_value);
blue_cluster_num = idx(1);
L = lab_he(:,:,1);
blue_idx = find(pixel_labels == blue_cluster_num);
L_blue = L(blue_idx);
is_light_blue = im2bw(L_blue,graythresh(L_blue));
nuclei_labels = repmat(uint8(0),[nrows ncols]);
nuclei_labels(blue_idx(is_light_blue==false)) = 1;
nuclei_labels = repmat(nuclei_labels,[1 1 3]);
blue_nuclei = he;
blue_nuclei(nuclei_labels ~= 1) = 0;
imshow(blue_nuclei), title('blue nuclei');
7 Comments
Walter Roberson
on 1 Feb 2016
Please show us the result of
which kmeans
Also please indicate which MATLAB version you are using.
debasmita bhoumik
on 2 Feb 2016
Sivakumaran Chandrasekaran
on 2 Feb 2016
he = imread('football.jpg');.... i used this image. no error came. code works perfectly.
Walter Roberson
on 2 Feb 2016
At the MATLAB command line, type
which kmeans
and show us the result.
sanjeev kumar
on 18 May 2016
Edited: Walter Roberson
on 18 May 2016
sir even i got error in same line like
[cluster_idx cluster_center] =kmeans(ab,nColors,'distance','sqEuclidean', ...
and by typing the command which kmeans i got [C:\Users\sanjeev\Documents\MATLAB\kmeans.m] sir what is the error
Walter Roberson
on 18 May 2016
sanjeev kumar, you have your own kmeans.m code, possibly downloaded from somewhere, but you are looking at the documentation for the kmeans routine of the Statistics Toolbox.
khitem amiri
on 2 Aug 2017
Hi, i had the same problem, and after executing "which kmeans" I got a path to a kmeans file that I downloaded and not the one implemented in the statistics toolbox. I just removed the downloaded file and it works without problem. Hope this will help
Answers (0)
Categories
Find more on k-Means and k-Medoids Clustering in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!