I implemented a loop where I read images from a folder and do some calculation on each of these. I then write the result in a txt file. I'm starting to think that it doesn't read the images in the right order (the names are following each others: XYZ_1.bmp, XYZ_2.bmp 3-4-5-6...) because when I do the calculation on only one image, I get the result of another image.
Therefore, I would like to write the name of the image on my result txt file in order to check if it is the right image.
I did not succeed. I'm guessing the code I made is not saving the image name when reading it, isn't it ? Do you have tips ? Is that anyway possible that the code is not reading the image in the right order (1-2-3-4...) ?
Here is my code :
rep=sprintf('foldername');
ext='*.bmp';
chemin = fullfile(rep,ext);
list1 = dir(chemin);
n=numel(list1);
A=zeros(4,n); % result tab
for k=1:n
I= imread(fullfile(rep,list1(k).name),ext(3:end));
%SOME CALCULATIONS
%Filling up result tab
A(1,k)=ME;
A(2,k)=NU;
A(3,k)=PO;
A(4,k)=N;
end
fid = fopen('Parameters_Seg_Im5_9.txt','w');
fprintf(fid,'%5s %5s %4s %6s\r\n','ME', 'NU', 'P', 'N');
fprintf(fid,'%5.4f %5.4f %4.3f %7d\r\n',A);
fclose(fid);
The way I wrote filenames was not right :1-2-3-4-5-6-7-8-9-10-11...
I guess the rule is to write filenames with the maximum number of digits : 001-002-003-004...-...-100...-...-999.
Question solved: writing tips!