Clear Filters
Clear Filters

imageDataAugmenter saving images separately

11 views (last 30 days)
Hello everyone,
I have been having some issues with image augmentation, so in a nutshell what i am trying to do is to have my images augmented then saved indivually in a folder like a regular photo and in a regular folder. for example, in python after I do the augmentation; each augmented image will be saved seperatly as a copy of its original with the same formate in a folder, and that is what i am trying to do here or at least a simialr approach. I have attached my code
clear all
Non_Augmented = 'C:\Users\Main\Desktop\matlab_projects\Non_Augmented';
allImages = imageDatastore(Non_Augmented,"IncludeSubfolders",true,"LabelSource","foldernames");
imageSize = [28 28 1];
imageAugmenter = imageDataAugmenter('RandRotation',[-20,20],'RandXTranslation',[-3 3], 'RandYTranslation',[-3 3]);
auimds = augmentedImageSource([244 244 1],allImages,'DataAugmentation',imageAugmenter);
minibatch = read(auimds);

Answers (2)

Vinayak Choyyan
Vinayak Choyyan on 9 Feb 2023
Hello Engineer Undergoing,
As per my understanding, you would like to perform some augmentation on some images and save the augmented images with the same file format.
I see you have tried to use ‘augmentedImageSource()’. This function is primarily intended to be used along with Neural Networks. Along with ‘imageDatastore()’ this function is used to load data into memory (RAM) in batches. Memory is expensive and limited. Loading an entire huge dataset into memory all at once is not feasible. This function hence loads a batch of images, augments it and then feeds it into a neural network for training or testing.
To achieve the results you are looking for, please use the ‘randomAffine2d()’ function. You can read more about this function here Create randomized 2-D affine transformation - MATLAB randomAffine2d - MathWorks India.
Here is also a demo code for the same:
I = imread(imageFileName);
tform1 = randomAffine2d(Rotation=[35 55]);
J = imwarp(I,tform1);
I hope this helps resolve the issue you were facing. Please alsorefer to the following documents to read more about the following:

Michael Butchers
Michael Butchers on 19 Dec 2023
I'm trying to do the same thing. I've got folders with images that i want to augmentate. Once i have augmentated them, i want to save those images back into the same folder with the original images. The file names of the orginal images are 1, 2, 3, 4, 5 ...etc, so i want the augmentated images to follow suit in the file names i,e. 6, 7, 8, 9 ......
I also need to find the code in which i can create 'x' number of augmentated images. I.e i have 15 original images, and i want to create 50+ more augmentated images using the various augmentated techniques out there.
Any clever person out there that can give me the code for that?

Community Treasure Hunt

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

Start Hunting!