Program takes long time to run

2 Ansichten (letzte 30 Tage)
Pat
Pat am 10 Dez. 2012
I have a code below,but it takes long time to run,please assist how to make it run faster
for k = 1:(length(dirlist))
img = imread([pathname, dirlist(k).name]);
flatImg =img(:);
idx = k_means(3,flatImg);
N{k}=(reshape(idx,size(img,1),size(img,2)));
end
i have 7 images
please assist
  1 Kommentar
Walter Roberson
Walter Roberson am 10 Dez. 2012
How big are your images? Are your images RGB (truecolor) or grayscale?

Melden Sie sich an, um zu kommentieren.

Antworten (1)

Image Analyst
Image Analyst am 10 Dez. 2012
Use the code profiling tool or insert tics and tocs into the code to find out what's taking so long. It's probably k_means. You might be able to get very close to the same results in 1/16 the sime if you just subsample your image by a factor of 4 in both directions. Please state how long is "a long time". Is it several hours, minutes, or seconds? I've seen some people say 0.05 seconds is too long and others say days is too long and would be happy to get it down to a few hours.
  2 Kommentare
Pat
Pat am 10 Dez. 2012
it nearly takes 20 minutes ,if i use k means i get error,empty clusters ,thats y i have used k_means.
Kelly Kearney
Kelly Kearney am 10 Dez. 2012
You can eliminate the error via the 'EmptyAction' parameter with kmeans; I'm not familiar with your alternative k_means function but perhaps reverting to
kmeans(... , 'EmptyAction', 'drop')
might help?

Melden Sie sich an, um zu kommentieren.

Community Treasure Hunt

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

Start Hunting!

Translated by