做項目的時候需要用到把所有圖片旋轉一定角度,所以寫了這個程序,用的matlab。
clc;clear;
%% 批量讀取旋轉圖片
degree = 270 %要旋轉的度數(shù),逆時針
file_path = 'C:\Users\yyy\Desktop\process\raw\';% 圖像文件夾路徑
img_path_list = dir(strcat(file_path,'*.jpg'));%獲取該文件夾中所有jpg格式的圖像
img_num = length(img_path_list);%獲取圖像總數(shù)量
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