I want to read images fromdatabase & resiz to same size for all & then take average of it. i have two images int the database.
code is:
clc;
y='z:\project\database';
dirlist=dir;
s=size(dirlist);
for m=1:256
for n=1:256
avg(m,n)=0;
end
end
for m = 3 : s
x= imread(strcat(y,'\',dirlist(m).name));
a= imresize(x,[256 256]);
for i = 1:256
for j = i:256
avg(i,j)=avg(i,j)+a(i,j);
end
end
end
av=avg./m;
figure,imshow(av);
but it won't run.
output is not correct.
plz help me to run this program.
I am expecting your reply soon.
At first it seems you made an error
for j = i:256 - should be replaced by for j = 1:256
Second, the good styly of Matlab programming is vector-matrix operations
You can remove a lot of your for loops causing program run much faster
clc;
y='z:\project\database';
dirlist=dir;
s=size(dirlist);
avg=zeros(256);
for m = 3 : s
x= imread(strcat(y,'\',dirlist(m).name));
a= imresize(x,[256 256]);
avg=avg+a;
end
av=avg./m;
figure,imshow(av);
Thankyou for revealing my mistake .but your code avg=avg + a doesn't run , it shows error message like
??? Error using ==> plus
Integers can only be combined with integers of the same class, or scalar doubles.
Error in ==> locate1 at 10
avg = avg + a;
plz tell me some other way to get average of images.
I am expecting your reply.
Thankyou.
vadkudr said:
At first it seems you made an error
for j = i:256 - should be replaced by for j = 1:256
Second, the good styly of Matlab programming is vector-matrix operations
You can remove a lot of your for loops causing program run much faster
clc;
y='z:\project\database';
dirlist=dir;
s=size(dirlist);
avg=zeros(256);
for m = 3 : s
x= imread(strcat(y,'\',dirlist(m).name));
a= imresize(x,[256 256]);
avg=avg+a;
end
av=avg./m;
figure,imshow(av);
Thankyou for revealing my mistake .but your code avg=avg + a doesn't run , it shows error message like
??? Error using ==> plus
Integers can only be combined with integers of the same class, or scalar doubles.
Error in ==> locate1 at 10
avg = avg + a;
plz tell me some other way to get average of images.
I am expecting your reply.
Thankyou.
vadkudr said:
At first it seems you made an error
for j = i:256 - should be replaced by for j = 1:256
Second, the good styly of Matlab programming is vector-matrix operations
You can remove a lot of your for loops causing program run much faster
clc;
y='z:\project\database';
dirlist=dir;
s=size(dirlist);
avg=zeros(256);
for m = 3 : s
x= imread(strcat(y,'\',dirlist(m).name));
a= imresize(x,[256 256]);
avg=avg+a;
end
av=avg./m;
figure,imshow(av);