Filter löschen
Filter löschen

Info

Diese Frage ist geschlossen. Öffnen Sie sie erneut, um sie zu bearbeiten oder zu beantworten.

problem in the code,getting following error

1 Ansicht (letzte 30 Tage)
Poonam
Poonam am 20 Sep. 2013
Geschlossen: MATLAB Answer Bot am 20 Aug. 2021
for i=1:256
img_hist(i)=sum(sum(im==(i)));
end
In an assignment A(:) = B, the number of elements in A and B must be the same.
Error in ==> kmeansclustering at 7 img_hist(i)=sum(sum(im==(i)));

Antworten (2)

Image Analyst
Image Analyst am 20 Sep. 2013
Bearbeitet: Image Analyst am 20 Sep. 2013
Why not just use imhist():
[counts, grayLevels] = imhist(im);
If you have to do it your way, try this and see how the times compare:
im=randi(256, [1000,1000]) - 1;
% Horribly inefficient way of getting histogram:
img_hist = zeros(1,256);
tic;
for i=0:255
img_hist(i+1)=sum(sum(im==i));
end
toc;
% Less inefficient way (more than 10 times faster)
img_hist = zeros(1,256); % Reset
tic
[rows, columns] = size(im);
for col = 1 : columns
for row = 1 : rows
img_hist(im(row,col)+1) = img_hist(im(row,col)+1) + 1;
end
end
toc
% Best way is to use imhist()
tic
img_hist = imhist(im);
toc;
Elapsed time is 0.479380 seconds.
Elapsed time is 0.047586 seconds.
Elapsed time is 0.008468 seconds.
Now, which way do you think is best? That is, simplest and fastest?

Azzi Abdelmalek
Azzi Abdelmalek am 20 Sep. 2013
Bearbeitet: Azzi Abdelmalek am 20 Sep. 2013
clear img_hist
for i=1:256
img_hist{i}=sum(sum(im==(i)));
end

Diese Frage ist geschlossen.

Community Treasure Hunt

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

Start Hunting!

Translated by