saving images as a database

조회 수: 2 (최근 30일)
Tony
Tony 2014년 1월 12일
답변: Image Analyst 2014년 1월 14일
I am trying to put a folder of jpg images in a database .mat i tried this from similar stuff that i googled, i was successful doing it to one image using
save('test.mat','f')
here is the failed code,
if true
srcFiles = dir('F:\matlab\face\data\*.jpg') % the folder images are in
for i = 1 : length(srcFiles)
filename = imread(['F:\matlab\face\data\',srcFiles(i).jpg]);
holdImage(i) = imread(filename);
end save('testimagebase.mat','holdImage'); end
  댓글 수: 1
Tony
Tony 2014년 1월 14일
is there a way to just load everything in a folder regardless of the name of the file

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

채택된 답변

Image Analyst
Image Analyst 2014년 1월 14일
Try this snippet. Set folder to:
folder = 'F:\matlab\face\data';
ListOfImageNames = {};
ImageFiles = dir([folder'/*.*']); % Get all files.
for Index = 1:length(ImageFiles)
baseFileName = ImageFiles(Index).name;
[folder, name, extension] = fileparts(baseFileName);
extension = upper(extension);
% Let's save just those we are interested in:
switch lower(extension)
case {'.png', '.bmp', '.jpg', '.tif', '.avi'}
% Allow only PNG, TIF, JPG, or BMP images
ListOfImageNames = [ListOfImageNames baseFileName];
otherwise
end
end
% Now ListOfImageNames is a list of all image format files.
% Now do whatever you want with that list.

추가 답변 (1개)

Ben
Ben 2014년 1월 13일
Try just this inside your loop:
holdImage(i) = imread(['F:\matlab\face\data\' srcFiles(i)],'jpeg');
  댓글 수: 1
Tony
Tony 2014년 1월 14일
is there a way to just load everything in a folder regardless of the name of the file

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

카테고리

Help CenterFile Exchange에서 MATLAB Report Generator에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by