How to correct the assignment Error?
2 ビュー (過去 30 日間)
古いコメントを表示
I have to run the K-means clustering program using matlab.
im = imread('D:\lena256.jpg');
k=5;
%histogram calculation
img_hist = zeros(256,1);
hist_value = zeros(256,1);
for i=1:256
img_hist(i)=sum(sum(im==(i-1)));
end
Run above code the following error occurred.
??? In an assignment A(:) = B, the number of elements in A and B
must be the same.
Error in ==> kmeansclustering at 10
img_hist(i)=sum(sum(im==(i-1)));
Error in ==> main at 5
[clusters, result_image, clusterized_image] = kmeansclustering(im,k);
How do I solve this problem?
3 件のコメント
Matt J
2012 年 12 月 14 日
Incidentally, why not use HISTC to generate the histogram? Why re-invent that wheel with for-loops?
採用された回答
José-Luis
2012 年 12 月 14 日
Try
img_hist(i)= sum(sum(sum(im==(i-1))));
im might be a three dimensional matrix.
2 件のコメント
その他の回答 (1 件)
Jürgen
2012 年 12 月 14 日
Hi,
there is a function: imhist(I) , quite useful for this work, + if you want to calculate the hist by summing for each value 0=>255 you will get a array with a lenght of 256 not 256*256
regards,J
1 件のコメント
Jürgen
2012 年 12 月 14 日
and indeed the comment of JL above is also a good point: the image could be a (VertRes, HorRes,3) matrix
参考
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!