将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