|
|
Read Multiple Images from a Folder
I have 1500 images in a folder called "Sample" in MATLAB folder. So how can I read 1500 images one by one and make some operations on them? I know I need a for loop, but I cannot think a better way to do this.
I can read multiple images from MATLAB folder using this code...
tifFiles = dir('*.tif');
for k = 1:length(tifFiles)
filename = tifFiles(k).name;
I = imread(filename);
% operations on "I"
end
But if I want to read all the images from a folder called "Sample", what should be my code..?
|
|
1
|
|
|
|
Reply
|
Nehal
|
8/29/2010 9:06:03 PM |
|
Nehal wrote:
> I have 1500 images in a folder called "Sample" in MATLAB folder. So how
> can I read 1500 images one by one and make some operations on them? I
> know I need a for loop, but I cannot think a better way to do this.
>
> I can read multiple images from MATLAB folder using this code...
>
> tifFiles = dir('*.tif'); for k = 1:length(tifFiles)
> filename = tifFiles(k).name;
> I = imread(filename);
> % operations on "I"
> end
>
> But if I want to read all the images from a folder called "Sample", what
> should be my code..?
Either include the directory name sotoo
filename = ['sample\' tifFiles(k).name]; % salt to suit...
or you could change the working directory to the one containing the files.
Or you might find
doc fullpath % and friends
useful
--
|
|
0
|
|
|
|
Reply
|
dpb
|
8/29/2010 9:16:24 PM
|
|
On 29/08/10 4:06 PM, Nehal wrote:
> I have 1500 images in a folder called "Sample" in MATLAB folder. So how
> can I read 1500 images one by one and make some operations on them? I
> know I need a for loop, but I cannot think a better way to do this.
>
> I can read multiple images from MATLAB folder using this code...
>
> tifFiles = dir('*.tif'); for k = 1:length(tifFiles)
> filename = tifFiles(k).name;
> I = imread(filename);
> % operations on "I"
> end
>
> But if I want to read all the images from a folder called "Sample", what
> should be my code..?
The code outline remains very similar to what you had already:
sdirectory = 'Sample';
tifffiles = dir([sdirectory '/*.tif']);
for k = 1:length(tifffiles)
filename = [sdirectory '/' tifffiles(k).name];
I = imread(filename);
% operations on "I"
end
The major thing to note here is that dir() does not retain any directory
information in the .name field of the structure, so if you dir()
something other than the current directory you have to add back in the
directory name when you want to operate on the file.
|
|
0
|
|
|
|
Reply
|
Walter
|
8/29/2010 9:24:35 PM
|
|
Walter Roberson <roberson@hushmail.com> wrote in message <neAeo.2092$rC7.1689@newsfe10.iad>...
> On 29/08/10 4:06 PM, Nehal wrote:
> > I have 1500 images in a folder called "Sample" in MATLAB folder. So how
> > can I read 1500 images one by one and make some operations on them? I
> > know I need a for loop, but I cannot think a better way to do this.
> >
> > I can read multiple images from MATLAB folder using this code...
> >
> > tifFiles = dir('*.tif'); for k = 1:length(tifFiles)
> > filename = tifFiles(k).name;
> > I = imread(filename);
> > % operations on "I"
> > end
> >
> > But if I want to read all the images from a folder called "Sample", what
> > should be my code..?
>
> The code outline remains very similar to what you had already:
>
> sdirectory = 'Sample';
> tifffiles = dir([sdirectory '/*.tif']);
> for k = 1:length(tifffiles)
> filename = [sdirectory '/' tifffiles(k).name];
> I = imread(filename);
> % operations on "I"
> end
>
> The major thing to note here is that dir() does not retain any directory
> information in the .name field of the structure, so if you dir()
> something other than the current directory you have to add back in the
> directory name when you want to operate on the file.
Thank You.
|
|
1
|
|
|
|
Reply
|
Nehal
|
8/30/2010 7:41:05 AM
|
|
Hi,i have 21image and i like to read it at the same time but i can read only from 1 to 9 and then stop can somebody help?the name of the images is anpage.1 to 20.
for i=1:21
if i<20
t(i,:)= ['anpage.' num2str(i) '.jpg'];
filenamee=['C:\Users\houssam\Documents\MATLAB\DP\faces94\female\anpage\' t(i,:)]
I=imread(filenamee);
end
|
|
0
|
|
|
|
Reply
|
fadol (4)
|
7/9/2012 10:42:07 AM
|
|
|
4 Replies
1859 Views
(page loaded in 0.087 seconds)
|
|
|
|
|
|
|
|
|