open a folder of images thru code

i wanted to do few calculations for all images in a folder and save all the result in a matfile...
when i do only the last result is being saved in the matfile can tell me how to open a folder of images using matlab code and do the calculations and save each images calculation in the same matfile....
i have got the calculation part... some please help me in the remaining part....

 채택된 답변

Walter Roberson
Walter Roberson 2012년 12월 3일

0 개 추천

Together with using the -append flag when you save()
Make sure you use a different variable name each time you save, or else the new value will overwrite the old value.

댓글 수: 5

Elysi Cochin
Elysi Cochin 2012년 12월 3일
편집: Elysi Cochin 2012년 12월 3일
sir using that i did the first part... but while saving to matfile only the last value is being saved in matfile...
my code is as below...
filePattern = fullfile('Dataset', '*.jpg');
jpegFiles = dir(filePattern);
for k = 1:length(jpegFiles)
baseFileName = jpegFiles(k).name;
fullFileName = fullfile('Dataset', baseFileName);
fprintf(1, 'Now reading %s\n', fullFileName);
rgbImage = imread(fullFileName);
I=rgb2gray(rgbImage);
GLCM = graycomatrix(I, 'offset', [0 1]);
stats = Texture_Features(GLCM,0);
display(stats);
statmat=[stats.E stats.cov stats.se stats.de stats.e stats.inf2h stats.id stats.c]
save train statmat
end
the var stats contains 8 values... please tell me how to save the 8 values for each image in the same matfile
Walter Roberson
Walter Roberson 2012년 12월 3일
You are using the same variable each time, "stats". If you managed to save all 8 into a single .mat file, how would you like to be able to refer to the individual value sets when you load() the .mat file?
Elysi Cochin
Elysi Cochin 2012년 12월 3일
ok sir got u...i edited the above code... but still only the last images values are being saved.... what to do...
Walter Roberson
Walter Roberson 2012년 12월 3일
The problem wasn't that stats was a struct, the question is how you are going to specify which struct you wanted. There is no way to say "Give me the third instance of the variable named 'stats'". Only the last version of any variable is available in a file (even if you use the -append flag when you save())
Where you hoping that it would get put into a structure array, such as stats(1).cov for the first saved instance, stats(2).cov for the second saved instance? That is not going to happen even if you use -append: the new variable completely overwrites the old for -append.
If you want a structure array or cell array or whatever, you need to build that up ahead of time and save() only the final result.
There is a way in new-ish versions of MATLAB to add additional information to an array. See matfile. But I think that would be overkill for you and that what you should do is simply construct the array as you go, and save() it all at the end.
Elysi Cochin
Elysi Cochin 2012년 12월 3일
thank u sir..

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

카테고리

도움말 센터File Exchange에서 Startup and Shutdown에 대해 자세히 알아보기

태그

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by