From: Ruby on 14 Sep 2006 01:14 Hi ! I tried your program but It won't run. It shows error message. Your code is : clc; y='z:\project\database'; s=dir(y); s([s.isdir])=[]; avg = zeros(256, 256); for m = 1 : length(s) x= imread(dir(m).name); a = imresize(x, [256 256]); avg = avg + a; end av=avg./m; figure,imshow(av); It shows error message ??? Complex values cannot be converted to logicals. Error in ==> locate2 at 7 x= imread(dir(m).name); This is my problem. I want to read files from directory & resize it to the same size for all images in the database & then take average of it , finally we will get a single image. Thank You Sir. Peter Boettcher wrote: > > > "Yesubai Rubavathi" <yesubai(a)mepcoeng.ac.in> writes: > >> Hi Everybody ! >> >> I am doing project in image processing & I have a problem in >> averaging images from database.Since I am not familiar with > matlab , >> I need help from you. >> >> I have code for image averaging, but it won't run. >> My code is >> >> clc; >> y='z:\project\database'; >> s=dir(y); >> for m=1:256 >> for n=1:256 >> avg(m,n)=0; >> end >> end >> for m = 1 : length(s) >> x(m) = imread(dir(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 >> >> moreover I don't know whether this code correctly return the > number >> of files in directory.I need code for counting number of files in > a >> directory also & for averaging 10 images in a given > database.finally >> output will be a single image. > > Jérôme has tried to address your file read problem. By the way, > a > little more detail would help in diagnosing this. In what way does > it > not run? Error message? > > Anyway, your code will be simpler if you use the matrix operations > of > MATLAB: > > avg = zeros(256, 256); > > for m = 1 : length(s) > x = imread(dir(m).name); > a = imresize(x, [256 256]); > avg = avg + a; > end > > > > -- > Peter Boettcher <boettcher(a)ll.mit.edu> > MIT Lincoln Laboratory > MATLAB FAQ: <http://www.mit.edu/~pwb/cssm/> >
From: Ruby on 14 Sep 2006 01:20 Hi ! I tried your program but it didn't run. It shows error message. Your code is: clc; y='z:\project\database'; s=dir(y); s([s.isdir])=[]; avg=zeros(256); for m = 1 : length(s) x(m)= imread(s(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 av=avg./m; end figure,imshow(avg); It shows error message ??? Error using ==> imread File "fig1.jpg" does not exist. Error in ==> locate1 at 7 x(m)= imread(s(m).name); but I have files in the database. This is my problem. I want to read files from directory & resize it to the same size for all images in the database & then take average of it , finally we will get a single image. Thank You Sir. J?r?me wrote: > > > Hi, > > try this : > > clc; > y='z:\project\database'; > s=dir(y); > s([s.isdir])=[]; > > avg=zeros(256); > > for m = 1 : length(s) > x(m) = imread(s(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 > > J?r?me
From: Ruby on 14 Sep 2006 01:30 I tried but it shows error message like ??? Error using ==> imread File "fig1.jpg" does not exist. Error in ==> locate1 at 7 x(m)= imread(s(m).name); but I have database in which there are two face image files. Ruby wrote: > > > Hi ! > > I tried your program but it didn't run. > It shows error message. > Your code is: > clc; > y='z:\project\database'; > s=dir(y); > s([s.isdir])=[]; > avg=zeros(256); > for m = 1 : length(s) > x(m)= imread(s(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 > av=avg./m; > end > figure,imshow(avg); > > It shows error message > > ??? Error using ==> imread > File "fig1.jpg" does not exist. > > Error in ==> locate1 at 7 > x(m)= imread(s(m).name); > but I have files in the database. > This is my problem. > I want to read files from directory & resize it to the same size > for > all images in the database & then take average of it , finally we > will get a single image. > Thank You Sir. > > J?r?me wrote: >> >> >> Hi, >> >> try this : >> >> clc; >> y='z:\project\database'; >> s=dir(y); >> s([s.isdir])=[]; >> >> avg=zeros(256); >> >> for m = 1 : length(s) >> x(m) = imread(s(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 >> >> J?r?me
From: Peter Bone on 14 Sep 2006 05:38 I think the problem is in av=avg./m; It should be av=avg./s . m is undefined because it's not inside the for loop for m. Why are you starting from 3 (m=3:s)? Maybe it should be av=avg./(s-2) if starting from 3. You should use vectorized code instead of for loops. replace for m=1:256 for n=1:256 avg(m,n)=0; end end with avg = zeros(256); and replace for i = 1:256 for j = i:256 avg(i,j)=avg(i,j)+a(i,j); end end with avg = avg + a;
From: Peter Boettcher on 14 Sep 2006 16:34
Ruby <yesubai(a)mepcoeng.ac.in> writes: > Hi ! > > I tried your program but It won't run. > It shows error message. > Your code is : > > clc; > y='z:\project\database'; > s=dir(y); > s([s.isdir])=[]; > avg = zeros(256, 256); > for m = 1 : length(s) > x= imread(dir(m).name); > a = imresize(x, [256 256]); > avg = avg + a; > end > av=avg./m; > figure,imshow(av); > > It shows error message > > ??? Complex values cannot be converted to logicals. > > Error in ==> locate2 at 7 > x= imread(dir(m).name); I made typo in that line (not on purpose, sorry). See if you can figure out what it is. -- Peter Boettcher <boettcher(a)ll.mit.edu> MIT Lincoln Laboratory MATLAB FAQ: http://www.mit.edu/~pwb/cssm/ |