Save multiple images with different name in folder

2 Ansichten (letzte 30 Tage)
Mustafa Yildiz
Mustafa Yildiz am 4 Apr. 2020
Kommentiert: Mustafa Yildiz am 10 Apr. 2020
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 Kommentare
Image Analyst
Image Analyst am 4 Apr. 2020
What's wrong with the way you did it?
Mustafa Yildiz
Mustafa Yildiz am 4 Apr. 2020
code is working , its generating images and saving them but for example it is saving images as 1.jpg,2.jpg,3.jpg.....180.jpg in a1 file and also in a2 file or a9.
But i wanna change it, For example in a1 folder i wanna save images as aa1.jpg, aa2.jpg , aa3.jpg... etc and i wanna save images in a2 folder as ab1.jpg , ab2.jpg....
Because i am gonna put all these images in alexnet so they will be in same folder for training.
All of them need to have special name so i wont lose any data.
Until now i was just generating these images using same code and later i was using another code for rename all images in every file. So its kinda wasting time thats why i am trying to save them with different name when i am generating these images

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Srivardhan Gadila
Srivardhan Gadila am 10 Apr. 2020
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.
Make sure you create the folders a1, a2 ....a9 in the folder Person1 before itself using mkdir.

Weitere Antworten (0)

Kategorien

Mehr zu Image Data Workflows finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by