做项目的时候需要用到把所有图片旋转一定角度,所以写了这个程序,用的matlab。
clc;clear;
%% 批量读取旋转图片
degree = 270 %要旋转的度数,逆时针
file_path = 'C:\Users\yyy\Desktop\process\raw\';% 图像文件夹路径
img_path_list = dir(strcat(file_path,'*.jpg'));%获取该文件夹中所有jpg格式的图像
img_num = length(img_path_list);%获取图像总数量
if img_num > 0 %有满足条件的图像
for j = 1:img_num %逐一读取图像
image_name = img_path_list(j).name;% 图像名
image = imread(strcat(file_path,image_name));
fprintf('%d %d %s\n',i,j,strcat(file_path,image_name));% 显示正在处理的图像名
I=imrotate(image,270);
imwrite(uint8(I),['C:\Users\yyy\Desktop\process\rotated\','\',image_name,'.jpg']);%保存
end
end