Image sample augmentation for ML training data generation

Version 1.0.0 (2.82 KB) by Rahul Jacob
serialImageTransformer applies transformations in the order it receives in the input arguments
29 Downloads
Updated 21 Nov 2021

View License

Image sample augmentation for machine learning training data generation
One of the challenging aspects of machine learning is the scarcity in available data which often leads to severe class imbalance, and introduces bias in the machine learning models accidentally. An approach to tackle this challenge is to employ data augmentation. In this project, rotation, resizing, cropping and padding are used as methods of augmentation.
T = serialImageTransformer(I,varargin) takes at minimum 2 arguments and transforms image I sequentially based on options given by varargin. Valid transformations are:
  1. Rotate: rotates the image by degrees specified by angle.
  2. Resize: resizes the image into a image of size numrows x numcols.
  3. Crop: crops the image in rectangular area of (xmin, ymin) and (xmax, ymax).
Pad: adds additional padding to the border of the image.
The augmentation is done one after the other.
Example code:
I = imread("cameraman.tif");
imshow(serialImageTransformer(I,"rotate",45,"crop",100,100,200,200,"resize",256,256))
The argument list varargin also takes an argument for type of interpolation for rotate, resize and crop. Valid interpolations are:
  1. "nearest": Specifies Nearest Neighbor interpolation. Default.
  2. "bilinear": Specifies Bilinear interpolation.
Example code:
I = imread("cameraman.tif");
imshow(serialImageTransformer(imread("cameraman.tif"),"rotate",45,"bilinear","crop",100,100,200,200,"resize",256,256))
Here rotate is in Nearest Neighbour interpolation and after argument "bilinear", crop and resize are in Bilinear interpolation.
Interpolations can be changes multiple number of times. The last interpolation is used for the function.
Example code:
I = imread("cameraman.tif");
imshow(serialImageTransformer(imread("cameraman.tif"),"rotate",45,"bilinear","crop",100,100,200,200,"nearest","resize",256,256))
Here rotate is in Nearest Neighbour interpolation and after argument "bilinear", crop is in Bilinear interpolation and afterward the argument "nearest" resize is in Nearest Neighbour interpolation.

Cite As

Rahul Jacob (2024). Image sample augmentation for ML training data generation (https://www.mathworks.com/matlabcentral/fileexchange/102279-image-sample-augmentation-for-ml-training-data-generation), MATLAB Central File Exchange. Retrieved .

MATLAB Release Compatibility
Created with R2021b
Compatible with any release
Platform Compatibility
Windows macOS Linux

Community Treasure Hunt

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

Start Hunting!
Version Published Release Notes
1.0.0