Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

how to load multiple images with matlab

141 views
Skip to first unread message

maribo bo

unread,
Sep 14, 2010, 8:21:09 AM9/14/10
to
Hello everyone,

this is my first post...hope it goes well!
I wanted to ask how to load multiple images.
I'll explain better.
I have a ransac code that works on only one image. I want this code to work on many other images, which are around 2000.
The name of the images are 00000.tiff, 00001.tiff, ..., 00010.tiff, ...,00234.tiff and so on.
So I had this piece of code:
images = cell(1,10);
filename = '0000%d.tiff';
for k = 1 : N;
IMAGES{k} = imread(sprintf(filename,k)); %#ok<AGROW>
end

but this doesn't work for the image 00000.tiff neither for the others from the 10th,
because it becomes 000010.tiff.
So how can I load the images in a general way, in the way I don't have to change the filename at any rate ?

thank you very much for your attention and your answers!

Steven_Lord

unread,
Sep 14, 2010, 9:15:58 AM9/14/10
to

"maribo bo" <mar...@blu.it> wrote in message
news:i6npbk$ecm$1...@fred.mathworks.com...

Use the DIR approach described in question 4.12 in the newsgroup FAQ.

--
Steve Lord
sl...@mathworks.com
comp.soft-sys.matlab (CSSM) FAQ: http://matlabwiki.mathworks.com/MATLAB_FAQ
To contact Technical Support use the Contact Us link on
http://www.mathworks.com

ImageAnalyst

unread,
Sep 14, 2010, 12:33:53 PM9/14/10
to
That won't work for ANY images. Try this instead:

% filename = '0000%d.tiff'; % Unneeded - delete this line.


for k = 1 : N;

baseFileName = sprintf('%5.5d.tiff', k); % Note the 5.5 -
it's important.
IMAGES{k} = imread(baseFileName);
end


maribo bo

unread,
Sep 15, 2010, 4:45:24 AM9/15/10
to
"Steven_Lord" <sl...@mathworks.com> wrote in message <i6nsie$fg1$1...@fred.mathworks.com>...


thank you very much for your quick answer. I tried your tip at once :)

imagelist = dir('*.tiff');
N = numel(imagelist);
imdata = cell(1, numel(imagelist));

for k = 1: N

imdata{k} = imread(imagelist(k).name);
%ransac code
end

IT WORKS!! :D

Anyway. I have another question.

With the imagelist in the code I have to put all images in the MATLAB directory,
but if I put :
imagepath = 'C:\Desktop\Raccolte\Documenti\MATLAB\tiff\';
patternname ='*.tiff';
imagelist = dir (fullfile(imagepath,patternname));
imdata = cell (1, numel(imagelist));

but it doesnt' work... can someone explain me why and how can I change it in order to choose another directory where I can put all images? otherwise I have to mixe all .m files with the images... and it grows in a exponential way.
Sorry for the basic question, but I am new at MAtlab, even though I like it very much.

Thank you for your attention and your answers!

maribo bo

unread,
Sep 15, 2010, 4:48:14 AM9/15/10
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <c4327317-1efb-4a56...@e20g2000vbn.googlegroups.com>...


Thank you for your answer!
can you please me explain briefly how it works?
I don't understand the syntax ('%5.5d.tiff', k).
Thanks in advance!

ImageAnalyst

unread,
Sep 15, 2010, 6:44:06 AM9/15/10
to
On Sep 15, 4:48 am, "maribo bo" <mari...@blu.it> wrote:
> Thank you for your answer!
> can you please me explain briefly how it works?
> I don't understand the syntax ('%5.5d.tiff', k).
> Thanks in advance!
-----------------------------------------------------
It's just like with C. The 5.5 says to have a field width of 5 and
add 0's in front of the number until you get 5 numbers (digits). The
%5.5 says that's where the k value is supposed to go. The .tiff just
comes along for the ride and gets tacked on at the end. See the
sprintf() or consult any book on C programming for more explanation.

Steven_Lord

unread,
Sep 15, 2010, 9:54:04 AM9/15/10
to

"maribo bo" <mar...@blu.it> wrote in message

news:i6q134$22$1...@fred.mathworks.com...


> "Steven_Lord" <sl...@mathworks.com> wrote in message
> <i6nsie$fg1$1...@fred.mathworks.com>...

*snip*

> Anyway. I have another question.
>
> With the imagelist in the code I have to put all images in the MATLAB
> directory,
> but if I put :
> imagepath = 'C:\Desktop\Raccolte\Documenti\MATLAB\tiff\';
> patternname ='*.tiff';
> imagelist = dir (fullfile(imagepath,patternname));
> imdata = cell (1, numel(imagelist));
>
> but it doesnt' work... can someone explain me why and how can I change it
> in order to choose another directory where I can put all images? otherwise
> I have to mixe all .m files with the images... and it grows in a
> exponential way.
> Sorry for the basic question, but I am new at MAtlab, even though I like
> it very much.

Are you remembering, in the call to whatever function you use to read in the
image, to use FULLFILE to add the image path in front of the image name?
The name field of the struct array that DIR outputs only contains, as you
would expect from the name of the field, the name of the file not the full
path.

maribo bo

unread,
Sep 16, 2010, 9:28:04 AM9/16/10
to
> > imagepath = 'C:\Desktop\Raccolte\Documenti\MATLAB\tiff\';
> > patternname ='*.tiff';
> > imagelist = dir (fullfile(imagepath,patternname));
> > imdata = cell (1, numel(imagelist));
> >
------------------------------------------------------------

>
> Are you remembering, in the call to whatever function you use to read in the
> image, to use FULLFILE to add the image path in front of the image name?
> The name field of the struct array that DIR outputs only contains, as you
> would expect from the name of the field, the name of the file not the full
> path.
>
> --
> Steve Lord
-----------------------------------------------------------------

Hi Steve,

thank you for answering again. Would you please tell me how to set the path to a whatever directory in order to process the images ? that directory is not suppose to be "matlab"'s, because I have thousands of images and it is better to process them where they are. Probably it is a basic question, but be sure I am discovering matlab step by step and I am putting all my effort in it.
Thank you very much

Maribo Bo

Steven_Lord

unread,
Sep 16, 2010, 9:35:12 AM9/16/10
to

"maribo bo" <mar...@blu.it> wrote in message

news:i6t614$l71$1...@fred.mathworks.com...


>> > imagepath = 'C:\Desktop\Raccolte\Documenti\MATLAB\tiff\';
>> > patternname ='*.tiff';
>> > imagelist = dir (fullfile(imagepath,patternname));
>> > imdata = cell (1, numel(imagelist));
>> >
> ------------------------------------------------------------
>>
>> Are you remembering, in the call to whatever function you use to read in
>> the image, to use FULLFILE to add the image path in front of the image
>> name? The name field of the struct array that DIR outputs only contains,
>> as you would expect from the name of the field, the name of the file not
>> the full path.
>>
>> --
>> Steve Lord
> -----------------------------------------------------------------
>
> Hi Steve,
>
> thank you for answering again. Would you please tell me how to set the
> path to a whatever directory in order to process the images ? that
> directory is not suppose to be "matlab"'s, because I have thousands of
> images and it is better to process them where they are.

Are you looking for the CD function?

> Probably it is a basic question, but be sure I am discovering matlab step
> by step and I am putting all my effort in it.

In that case I recommend you work your way through the Getting Started
section of the documentation for MATLAB. Use the DOC function to open the
documentation, then navigate to MATLAB, then to Getting Started.

ImageAnalyst

unread,
Sep 16, 2010, 10:15:23 AM9/16/10
to
Maribo Bo:
Just specify your directory somehow, be it hardcoded, or by asking the
user via uigetdir(). Then make up the full pathname of your files
with fullfile

fullFileName = fullfile(folderName, baseFileName);
imageArray = imread(fullFileName);

maribo bo

unread,
Sep 17, 2010, 7:07:04 AM9/17/10
to
> Are you looking for the CD function?

Yes! thank you Steven, sei il migliore! :)

> > Probably it is a basic question, but be sure I am discovering matlab step
> > by step and I am putting all my effort in it.
>
> In that case I recommend you work your way through the Getting Started
> section of the documentation for MATLAB. Use the DOC function to open the
> documentation, then navigate to MATLAB, then to Getting Started.
>

I've started with some chapters, thank you for the advice!

maribo bo

unread,
Sep 17, 2010, 7:33:05 AM9/17/10
to
ImageAnalyst <imagea...@mailinator.com> wrote in message <9bf83fc2-09b1-414f...@l17g2000vbf.googlegroups.com>...
-------------
thank you for your help!
I would surely look for uigetdir(), it sounds good! :)

maribo bo

unread,
Sep 22, 2010, 3:28:06 AM9/22/10
to
WHAT HAPPENs?

I have this code:

cd('D:\Documenti\MATLAB\tiff\');


imagelist = dir('*.tiff');

num = numel(imagelist);
imdata = cell(1, numel(imagelist));

for kappa = 1: num
imdata{kappa} = imread(imagelist(kappa).name);
disp(size(imdata{kappa}));
[y,x] = find(imdata{1,kappa} == 0);
matrind2Npts = [x'; y'];
[rows, Npts] = size(matrind2Npts);
ransac code
end

I don't know why, but from yesterday only, the images that I loaded with dimensions 64*128, now their dimensions are 480 * 641 * 3.
It seems to me that more images are loaded in the same matrix. Am I wrong?
How can I load the images with dimension 64*128 one for each matrix as before?
I really don't know why from yesterday things've changed.
Please, help me.

Thank you very much for your attention and for your answers!

maribo

ImageAnalyst

unread,
Sep 22, 2010, 8:54:15 AM9/22/10
to
All I can say is that you must have overwritten your original images
somehow with larger, color versions.
0 new messages