將srcimg文件下的bmp文件轉為jpg圖像,存放在dstimg文件夾下
str = 'srcimg';
dst = 'dstimg';
file=dir([str,'\*.bmp']);
for i=1:length(file)
img = imread( [str,'\',file(i).name]);
imwrite(img, [dst,'\',file(i).name(1:end-4),'.jpg']);
end
補充讀取所有的圖像文件
- ext = {'*.jpeg','*.jpg','*.png','*.pgm'};
-
- images = [];
- for i = 1:length(ext)
- images = [images dir([path ext{i}])];
- end
-
- % images are returned with absolute path
- for i = 1:length(images)
- images(i).name = [path images(i).name];
- end
matlab讀取文件夾里所有文件的文件名
imgpath = './test';
fileFolder=fullfile(imgpath);%文件夾名plane
dirOutput=dir(fullfile(fileFolder,'*'));%如果存在不同類型的文件,用‘*’讀取所有,如果讀取特定類型文件,'.'加上文件類型,例如用‘.jpg’
fileNames={dirOutput.name}';
images = cell(length(fileNames) - 2,1);
for i = 3:length(fileNames)
imgname = fileNames(i);
imgname = imgname{1};
images{i-2}= [imgpath imgname];
end
images