How create desired number of images in the folder

How to augment a folder of images?
Suppose i have 7 images in a folder, i wanted to augment these 7 images and create a total of 20 images in the folder (that means 13 new images)
I tried the below code for 1 image
In = imread('peppers.png');
Aug = imageDataAugmenter('RandXReflection',true);
Out = augment(Aug,In);
How to augment, so that i can create desired number of images in the folder

 Accepted Answer

Hello
First of all, if you have folders you better define these:
baseDir = pwd;
that is the base folder or directory, then define the files you have in that folder, if these are png you can just read those:
>> dir0 = dir ('*.png')
dir0 =
11×1 struct array with fields:
name
folder
date
bytes
isdir
datenum
Now you have all the files in that folder and you do not need to write them one by one, e.g.
>> dir0(1).name
ans =
'Image_0.png'
Then you do the augmentation and then save the images to the folder, create a new filename for your output and print to save in the folder where you are working:
filename='Image_0_rotated.png';
print('-dpng','-r100',filename)
Hope that helps. If it does, please accept the answer, if it not, let me know.

5 Comments

If i want 10 new images from a single image, how can i specify the number of new images i want?
That is easy, just add the number to the filename e.g.
for k=1:10
filename=strcat('Image_',num2str(k),'_rotated.png');
disp (filename)
end
Image_1_rotated.png
Image_2_rotated.png
Image_3_rotated.png
Image_4_rotated.png
Image_5_rotated.png
Image_6_rotated.png
Image_7_rotated.png
Image_8_rotated.png
Image_9_rotated.png
Image_10_rotated.png
sir, how to use it in image augmentation function?
That depends on what you want to do to augment, you can use the same for loop and then use the values as parameters to your function:
https://uk.mathworks.com/help/deeplearning/ref/imagedataaugmenter.html
I would suggest to make the changes INSIDE the loop so that you change the parameters automatically.

Sign in to comment.

More Answers (0)

Categories

Find more on Images 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!