Technical discussion about Matlab and issues related to Digital Signal Processing.
Hi all, Is there any way to write a for loop to read the files i.e. images that are saved in a folder and do some operation on each in every iteration. So let say if I have files a.bmp, b.bmp,... all saved in a folder called image. i want to open c.bmp first----> do some calculation and display the result, then open b.bmp and do the same calculation, then c.bmp and so on. thanks Haidar
Hi ..
Instead of saving it as a,b,c....... try to save it as 1.bmp ,2.bmp
,3,4.....................n.bmp..
try to access the files as given below..
% n - total no of iamges in the folder.
for i = 1:n
str = strcat(int2str(i),'.bmp');
eval('img=imread(str);');
imshow(img)
% img is the image file you need
end
heidar mhr <o...@yahoo.com>
Sent by: m...@yahoogroups.com
28,Mar -2007 01:51 AM
To
Matlab <m...@yahoogroups.com>
cc
Subject
[matlab] for loop to read the files in a folder
Hi all,
Is there any way to write a for loop to read the files i.e. images that
are saved in a folder and do some operation on each in every iteration. So
let say if I have files a.bmp, b.bmp,... all saved in a folder called
image. i want to open c.bmp first----> do some calculation and display the
result, then open b.bmp and do the same calculation, then c.bmp and so on.
thanks
Haidar
use the command list=dir('directory_name');
list is a struct where saved all the file.
e.g.
In local dir you have
a.bmp
b.bmp
c.bmp
after the command
list = dir('.');
>> list(1)
ans =
name: '.'
date: '28-Mar-2007 17:34:20'
bytes: 0
isdir: 1
>> list(2)
ans =
name: '..'
date: '08-Mar-2007 14:14:41'
bytes: 0
isdir: 1
>> list(3)
ans =
name: 'a.bmp'
date: '14-Feb-2007 16:36:57'
bytes: 13
isdir: 0
etc. etc.
On 3/27/07, heidar mhr <o...@yahoo.com> wrote:
>
> Hi all,
>
> Is there any way to write a for loop to read the files i.e. images that
> are saved in a folder and do some operation on each in every iteration. So
> let say if I have files a.bmp, b.bmp,... all saved in a folder called
> image. i want to open c.bmp first----> do some calculation and display the
> result, then open b.bmp and do the same calculation, then c.bmp and so on.
>
> thanks
>
> Haidar
>
Heidar,
Open the file in append mode.
fid = fopen('info.txt', 'a');
regards,
mani
heidar mhr <o...@yahoo.com>
29,Mar -2007 01:36 AM
To
j...@pricol.co.in
cc
Subject
Re: [matlab] for loop to read the files in a folder
Hi, thanks for your reply. Actually your solution worked pretty well. But
I am still having a small problem. what i want to do is after i open each
image, i find the dimension and the number of 1's and 0's in that picture
and then i save it in a text file and i want to do that for all the
pictures that i have in that folder. in the text file, i want to save
these information in a line for each picture and then fo to the next line
and record the information for the second picture and so on. but with the
code that i have written, it only saves the last picture's info! below is
my code. i would apreciate if you can show me how i can accomplish this
goal.
%%%%%%%%%%%%
%%%my code
% n - total no of iamges in the folder.
for i = 1:3
str = strcat(int2str(i),'.bmp');
eval('a=imread(str);');
[x y]=size(a);
n1=length(find(a==1));
n2=length(find(a==0));
fid = fopen('info.txt', 'wt');
fprintf (fid, '%d %d %d %d %d %d',x,y,n1,n2);
fclose(fid);
% img is the image file you need
end
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
waiting for your reply
thanks alot,
Haidar
----- Original Message ----
From: "j...@pricol.co.in" <j...@pricol.co.in>
To: heidar mhr <o...@yahoo.com>
Cc: Matlab <m...@yahoogroups.com>
Sent: Wednesday, March 28, 2007 8:16:23 AM
Subject: Re: [matlab] for loop to read the files in a folder
Hi ..
Instead of saving it as a,b,c....... try to save it as 1.bmp ,2.bmp
,3,4.....................n.bmp..
try to access the files as given below..
% n - total no of iamges in the folder.
for i = 1:n
str = strcat(int2str(i),'.bmp');
eval('img=imread(str);');
imshow(img)
% img is the image file you need
end
heidar mhr <o...@yahoo.com>
Sent by: m...@yahoogroups.com
28,Mar -2007 01:51 AM
To
Matlab <m...@yahoogroups.com>
cc
Subject
[matlab] for loop to read the files in a folder
Hi all,
Is there any way to write a for loop to read the files i.e. images that
are saved in a folder and do some operation on each in every iteration. So
let say if I have files a.bmp, b.bmp,... all saved in a folder called
image. i want to open c.bmp first----> do some calculation and display the
result, then open b.bmp and do the same calculation, then c.bmp and so on.
thanks
Haidar
Hai, You can use the following code: %%%%%%%%%%%%%%%%%%%%%%% x = dir; no_files = size(x); for i= 3: no_files(1,1) ystr = x(i).name; % Do what you want to do with ystr file % e.g. z = edge(ystr); imshow(z); end %%%%%%%%%%%%%%%%%%%%%%% Zahid heidar mhr <o...@yahoo.com> wrote: Hi all, Is there any way to write a for loop to read the files i.e. images that are saved in a folder and do some operation on each in every iteration. So let say if I have files a.bmp, b.bmp,... all saved in a folder called image. i want to open c.bmp first----> do some calculation and display the result, then open b.bmp and do the same calculation, then c.bmp and so on. thanks Haidar
Hello Haidar;
I have done similar thing but i used number instead of letters like below;
for j=100:jmax
str_j=num2str(j);
file=strcat(str_j,'.jpg');
file_path=strcat('C:\database\','\your_folder','\',file);
im=imread(file_path,'jpg');
%im=imread('C:\database\your_folder\100.jpg','jpg'); %creating this path
%do what you want to do
end
You can also change your_folder parameter using a similar way.
I hope it helps.
Regards
Emre
Hello all,
A matrix has 100 elements and their values range from 0 to 500. What to do to
distribute that matrix in two groups. Say a =[ values from 0 to 270 ] and b = [ values from 271
to 500 ].
regards and thanks
humera
h r
well get a list of all the file names using dir but specify only *.bmp
"str = strcat(int2str( i),'.bmp' ); ", thats hardcoding, u shudnt need to change the
name of your files.
----- Original Message ----
From: "j...@pricol.co.in" <j...@pricol.co.in>
To: heidar mhr <o...@yahoo.com>
Cc: m...@yahoogroups.com
Sent: Thursday, March 29, 2007 5:29:47 AM
Subject: Re: [matlab] for loop to read the files in a folder
Heidar,
Open the file in append mode.
fid = fopen('info. txt', 'a');
regards,
mani
heidar mhr <oghab21@yahoo. com>
29,Mar -2007 01:36 AM
To
jmanimekalai@ pricol.co. in
cc
Subject
Re: [matlab] for loop to read the files in a folder
Hi, thanks for your reply. Actually your solution worked pretty well. But
I am still having a small problem. what i want to do is after i open each
image, i find the dimension and the number of 1's and 0's in that picture
and then i save it in a text file and i want to do that for all the
pictures that i have in that folder. in the text file, i want to save
these information in a line for each picture and then fo to the next line
and record the information for the second picture and so on. but with the
code that i have written, it only saves the last picture's info! below is
my code. i would apreciate if you can show me how i can accomplish this
goal.
%%%%%%%%%%%%
%%%my code
% n - total no of iamges in the folder.
for i = 1:3
str = strcat(int2str( i),'.bmp' );
eval('a=imread( str);');
[x y]=size(a);
n1=length(find( a==1));
n2=length(find( a==0));
fid = fopen('info. txt', 'wt');
fprintf (fid, '%d %d %d %d %d %d',x,y,n1,n2) ;
fclose(fid);
% img is the image file you need
end
%%%%%%%%%%%% %%%%%%%%% %%%%%%%%% %%%%%%
waiting for your reply
thanks alot,
Haidar
----- Original Message ----
From: "jmanimekalai@ pricol.co. in" <jmanimekalai@ pricol.co. in>
To: heidar mhr <oghab21@yahoo. com>
Cc: Matlab <matlab@yahoogroups. com>
Sent: Wednesday, March 28, 2007 8:16:23 AM
Subject: Re: [matlab] for loop to read the files in a folder
Hi ..
Instead of saving it as a,b,c....... try to save it as 1.bmp ,2.bmp
,3,4........ ......... ....n.bmp. .
try to access the files as given below..
% n - total no of iamges in the folder.
for i = 1:n
str = strcat(int2str( i),'.bmp' );
eval('img=imread( str);');
imshow(img)
% img is the image file you need
end
heidar mhr <oghab21@yahoo. com>
Sent by: matlab@yahoogroups. com
28,Mar -2007 01:51 AM
To
Matlab <matlab@yahoogroups. com>
cc
Subject
[matlab] for loop to read the files in a folder
Hi all,
Is there any way to write a for loop to read the files i.e. images that
are saved in a folder and do some operation on each in every iteration. So
let say if I have files a.bmp, b.bmp,... all saved in a folder called
image. i want to open c.bmp first----> do some calculation and display the
result, then open b.bmp and do the same calculation, then c.bmp and so on.
thanks
Haidar
a = x(find(x < 271 & x >= 0)); b = x(find(x <= 500 & x >= 271)); On 3/29/07, h u m e r a <h...@hotmail.com> wrote: > > Hello all, > > A matrix has 100 elements and their values range from 0 to 500. What to do > to distribute that matrix in two groups. Say a =[ values from 0 to 270 ] and > b = [ values from 271 to 500 ]. > > regards and thanks > > humera > > * * > *h r* > ** > ** > ** > ** >