image

augmentImages

Description

The `augmentImages` action is a powerful tool within the Image action set for data augmentation in computer vision tasks. It works by taking an input table of images and generating new, modified images. These transformations can include geometric changes like flipping, rotating, and cropping (creating patches), as well as color and pixel-level mutations such as color jittering, sharpening, lightening, or darkening. This process artificially expands the training dataset, which helps in building more robust and generalized deep learning models by exposing them to a wider variety of image appearances.

image.augmentImages { addColumns={augmentImagesAddColumnsParms}, augmentations={{augmentationOptions-1} <, {augmentationOptions-2}, ...>}, casOut={casouttable}, copyVars={"variable-name-1" <, "variable-name-2", ...>}, decode=TRUE | FALSE, image="variable-name", seed=64-bit-integer, table={castable}, writeRandomly=TRUE | FALSE };
Settings
ParameterDescription
addColumnsSpecifies extra columns to add to the output table, such as augmentation attributes.
augmentationsSpecifies the list of cropping and mutation options to apply to the images.
casOutSpecifies the output table to store the augmented images.
copyVarsSpecifies a list of variables to copy from the input table to the output table.
decodeWhen set to True, decodes the images before processing. Default is False.
imageSpecifies the name of the column that contains the image binaries. Default is '_image_'.
seedSpecifies the random seed to use for augmentations that have a random component, ensuring reproducibility.
tableSpecifies the input CAS table that contains the images to be augmented.
writeRandomlyWhen set to True, writes the generated images to the output table in a random order. Default is False.
Data Preparation View data prep sheet
Loading Images into a CAS Table

Before augmenting images, they must be loaded into a CAS table. The following code uses `proc casutil` to load image files from a specified path into a CAS table named `my_images`. The `casout` statement defines the output table, and the `importoptions` specify the file type as 'IMAGE' and provide the path to the image directory.

Copied!
1 
2PROC CASUTIL;
3load path="/path/to/your/images" casout={name="my_images", caslib="casuser"} importoptions={filetype="image"};
4QUIT;
5 

Examples

This example performs a simple horizontal flip on each image in the `my_images` table. The `useWholeImage=TRUE` option ensures the entire image is used, and the `mutations` parameter specifies the `horizontalFlip` transformation. The resulting augmented images are saved in a new table named `flipped_images`.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.augmentImages /
3 TABLE={name='my_images', caslib='casuser'},
4 augmentations={{useWholeImage=TRUE, mutations={horizontalFlip=TRUE}}},
5 casOut={name='flipped_images', caslib='casuser', replace=TRUE};
6QUIT;
Result :
An output CAS table named `flipped_images` containing the horizontally flipped versions of the original images.

This example demonstrates how to create smaller patches from each image using a sliding window approach. It defines a patch size of 224x224 pixels (`width=224`, `height=224`). The `sweepImage=TRUE` parameter activates the sliding window, which moves across the image with a `stepSize` of 112 pixels both horizontally and vertically. No mutations are applied in this case.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.augmentImages /
3 TABLE={name='my_images', caslib='casuser'},
4 augmentations={{
5 sweepImage=TRUE,
6 width=224,
7 height=224,
8 stepSize=112,
9 verticalStepSize=112
10 }},
11 casOut={name='image_patches', caslib='casuser', replace=TRUE};
12QUIT;
Result :
An output table `image_patches` containing multiple 224x224 pixel patches extracted from each source image.

This example applies a sequence of random transformations to each full image. The `mutations` list includes a random rotation to the left (up to 30 degrees), a random darkening effect, and a horizontal flip. The `seed` parameter is set to ensure the random operations are reproducible.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.augmentImages /
3 TABLE={name='my_images', caslib='casuser'},
4 seed=1234,
5 augmentations={{
6 useWholeImage=TRUE,
7 mutations={
8 rotateLeft={type='RANGE', value={0, 30}},
9 darken={type='RANGE', value={0.1, 0.4}},
10 horizontalFlip=TRUE
11 }
12 }},
13 casOut={name='multi_mutated_images', caslib='casuser', replace=TRUE};
14QUIT;
Result :
A new table `multi_mutated_images` where each image has been rotated, darkened, and flipped.

This example shows how to extract a specific 500x500 pixel crop starting at coordinates (100, 50) from each image. The extracted crop is then resized to 256x256 pixels using the `outputWidth` and `outputHeight` parameters. This is useful for standardizing input size for a neural network.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.augmentImages /
3 TABLE={name='my_images', caslib='casuser'},
4 augmentations={{
5 x=100, y=50, width=500, height=500,
6 outputWidth=256, outputHeight=256
7 }},
8 casOut={name='cropped_resized_images', caslib='casuser', replace=TRUE};
9QUIT;
Result :
An output table `cropped_resized_images` containing 256x256 pixel images, which are the resized versions of the 500x500 crops from the original images.

FAQ

What is the primary purpose of the `augmentImages` action in SAS Viya?
What are the required parameters for the `augmentImages` action?
How can I create image patches using the `augmentImages` action?
What types of image mutations are available in the `augmentations` parameter?
Can I apply a random rotation to an image?
How can I keep track of the augmentations applied to each image?
Is it possible to process the entire image without creating smaller patches?

Associated Scenarios

Use Case
Standard Case: Augmenting Images of Machine Parts for Defect Detection Model Training

A manufacturing company wants to build a deep learning model to automatically detect scratches and dents on metal parts. The initial dataset is small. They need to expand it by ...

Use Case
Performance/Volume Case: High-Volume Patch Generation from Large Satellite Images

An environmental agency is analyzing large, high-resolution satellite images (e.g., 8192x8192 pixels) to train a model for land use classification (forest, urban, water). They n...

Use Case
Edge Case: Robustness Test with Mixed-Quality Medical Scans and Invalid Data

A research hospital is augmenting a dataset of X-ray scans. The dataset is known to have quality issues: some images are too small, and some records have missing or corrupted im...