Save multiple images with different name in folder
4 ビュー (過去 30 日間)
古いコメントを表示
I am trying to read image from one folder and save new images in different folder with different names. I need all of them in different names because they are generated with different affine2d values. For example images in a1 folder will be aa1,aa2,aa3,aa4,aa5.... and images in a2 folder will be bb1,bb2,bb3.... is there any way for do that ?
srcFiles = dir('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\*.jpg');
for i = 1 : length(srcFiles)
filename = strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\',srcFiles(i).name);
im = imread(filename);
aform = affine2d([1 0 0; .1 1 0; 0 0 1])
bform = affine2d([1 0 0; .2 1 0; 0 0 1])
cform = affine2d([1 0 0; .3 1 0; 0 0 1])
dform = affine2d([1 0 0; .4 1 0; 0 0 1])
eform = affine2d([1 0 0; .5 1 0; 0 0 1])
fform = affine2d([1 0 0; .6 1 0; 0 0 1])
gform = affine2d([1 0 0; .7 1 0; 0 0 1])
hform = affine2d([1 0 0; .8 1 0; 0 0 1])
jform = affine2d([1 0 0; .9 1 0; 0 0 1])
a = imwarp(im,aform);
b = imwarp(im,bform);
c = imwarp(im,cform);
d = imwarp(im,dform);
e = imwarp(im,eform);
f = imwarp(im,fform);
g = imwarp(im,gform);
h = imwarp(im,hform);
j = imwarp(im,jform);
newfilename=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a1\',srcFiles(i).name);
newfilename1=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a2\',srcFiles(i).name);
newfilename2=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a3\',srcFiles(i).name);
newfilename3=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a4\',srcFiles(i).name);
newfilename4=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a5\',srcFiles(i).name);
newfilename5=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a6\',srcFiles(i).name);
newfilename6=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a7\',srcFiles(i).name);
newfilename7=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a8\',srcFiles(i).name);
newfilename8=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a9\',srcFiles(i).name);
imwrite(a,newfilename,'jpg');
imwrite(b,newfilename1,'jpg');
imwrite(c,newfilename2,'jpg');
imwrite(d,newfilename3,'jpg');
imwrite(e,newfilename4,'jpg');
imwrite(f,newfilename5,'jpg');
imwrite(g,newfilename6,'jpg');
imwrite(h,newfilename7,'jpg');
imwrite(j,newfilename8,'jpg');
end
2 件のコメント
採用された回答
Srivardhan Gadila
2020 年 4 月 10 日
Based on above information I'm assuming that the value of srcFiles(i).name is 'i.jpg'
Change the line
newfilename=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a1\',srcFiles(i).name);
to
newfilename=strcat('C:\Users\mstfy\Desktop\Matlab\alex\Train1\Person1\a1\aa',srcFiles(i).name);
Do the same to newfilename1, newfilename2,..newfilename8.
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Convert Image Type についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!