MATLAB版本
把文件下的所有图片压缩到256*256
path = 'E:\python论文及代码\新建文件夹 (4)\imagefusion_densefuse-master\coco2014\train_gray\';
save_path = 'E:\python论文及代码\新建文件夹 (4)\imagefusion_densefuse-master\coco2014\train_gray_256\';
file=dir([path,'*.jpg']);
for i=1:length(file)
I=imread([path,file(i).name]);
J=imresize(I,[256,256]);
imwrite(J,[save_path,file(i).name]);
end
python版本
import cv2
import os
path = 'D:/data/coco2014/train2014'
path1 = 'D:/data/coco2014/train2014gray'
files = os.listdir(path)
for file in files:
img = cv2.imread(path + "/" + file)
img = cv2.cvtColor(img,cv2.COLOR_BGR2GRAY)
img = cv2.resize(img,(256,256))
cv2.imwrite(path1+"/"+str(file),img)