How to correct the assignment Error?

조회 수: 4(최근 30일)
PRIYANGA
PRIYANGA 2012년 12월 14일
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
PRIYANGA
PRIYANGA 2012년 12월 14일
ok Sir I have to try.

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

채택된 답변

José-Luis
José-Luis 2012년 12월 14일
Try
img_hist(i)= sum(sum(sum(im==(i-1))));
im might be a three dimensional matrix.
  댓글 수: 2
José-Luis
José-Luis 2012년 12월 14일
My pleasure, but please edit your posts for clarity in the future.

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

추가 답변(1개)

Jürgen
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
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

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

범주

Find more on Statistics and Machine Learning Toolbox 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!

Translated by