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.
| Parameter | Description |
|---|---|
| addColumns | Specifies extra columns to add to the output table, such as augmentation attributes. |
| augmentations | Specifies the list of cropping and mutation options to apply to the images. |
| casOut | Specifies the output table to store the augmented images. |
| copyVars | Specifies a list of variables to copy from the input table to the output table. |
| decode | When set to True, decodes the images before processing. Default is False. |
| image | Specifies the name of the column that contains the image binaries. Default is '_image_'. |
| seed | Specifies the random seed to use for augmentations that have a random component, ensuring reproducibility. |
| table | Specifies the input CAS table that contains the images to be augmented. |
| writeRandomly | When set to True, writes the generated images to the output table in a random order. Default is False. |
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.
| 1 | |
| 2 | PROC CASUTIL; |
| 3 | load path="/path/to/your/images" casout={name="my_images", caslib="casuser"} importoptions={filetype="image"}; |
| 4 | QUIT; |
| 5 |
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`.
| 1 | PROC 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}; |
| 6 | QUIT; |
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.
| 1 | PROC 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}; |
| 12 | QUIT; |
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.
| 1 | PROC 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}; |
| 14 | QUIT; |
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.
| 1 | PROC 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}; |
| 9 | QUIT; |
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 ...
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...
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...