for分を使用して複数の画像を処理する方法について
Show older comments
こんにちは。
画像を射影変換するところなのですが、1つのファイルから複数の画像を読み取り、処理しようと試みました。
以下のコードで実行したのですが、2枚しか処理されません。手動で一枚だけ読み取れば射影変換のところは動くのですが、、、
やりたいこととしては、下記コードのI=imread(b{i});で読み取った画像全てを射影変換し、ファイル(face)に全て格納したいです。
何かアドバイス等いただけると幸いです。よろしくお願いいたします。
clc;clear;
rootfolder = fullfile('C:\Users\*** Lab\Desktop\MATLAB\フリー素材');
%%
j = dir('*.jpg');
a=struct2table(j);
b=a.name;
%%
for i=1:size(b,1)
I=imread(b{i});
mkdir('face'); %新しいフォルダを作成する
oldFolder = cd('face');
for theta = -5:5%回転角11
for s=-2:2%水平奥行10
for c=-2:2%上下5
for size=7:8%圧縮2
o=0;o=o+1;
tm = projective2d([cosd(theta*2) -sind(theta*2) 0.0002*s; ...
sind(theta*2) cosd(theta*2) 0.0002*c; ...
0 0 1]);
outputImage = imwarp(I,tm);%44*10*5=2200
outputImage2 = imresize(outputImage,0.1*size);%2200*2=4400
imwrite(outputImage,(sprintf('Oimg%d.png',o)));%2200
imwrite(outputImage2,(sprintf('ORSimg%d.png',o)));%2200
end
end
end
end
cd(oldFolder);
end
1 Comment
Yasutake Haramiishi
on 23 Feb 2021
Accepted Answer
More Answers (0)
Categories
Find more on 大規模なイメージ ファイル in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!