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!
"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
% 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
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!
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!
"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.
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
"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.
fullFileName = fullfile(folderName, baseFileName);
imageArray = imread(fullFileName);
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!
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