image

flattenImages

Description

The flattenImages action converts an image table (containing binary image data) into a wide format table where each pixel represents a column. This is particularly useful for preparing image data for analytical models that require flat vector inputs. The action supports resizing images (height and width), changing the number of channels (e.g., converting to grayscale), grouping channels, and transposing image data during the flattening process.

Settings
ParameterDescription
casOutSpecifies the settings for the output table, including the table name and caslib.
tableSpecifies the input table that contains the image data to be flattened.
widthSpecifies the target width of the output images. The default is 32.
heightSpecifies the target height of the output images. The default is 32.
numberOfChannelsSpecifies the number of channels for the output images. Values can be 'COLOR_IMAGE', 'GRAY_SCALE_IMAGE', or an integer.
groupChannelsWhen set to True, groups the channels of the images together (e.g., all blue pixels, then all green, then all red) in the output.
transposeWhen set to True, transposes the images before writing them to the output table.
copyVarsSpecifies a list of variables to copy from the input table to the output table.
imageSpecifies the name of the column in the input table that contains the image binaries. Default is '_image_'.
Data Preparation View data prep sheet
Load Input Image Data

Loads sample images into a CAS table to be used as input for the flattenImages action.

Copied!
1 
2PROC CAS;
3image.loadImages / path="lib/images", caslib="CASUSER", casOut={name="source_images", replace=true};
4 
5RUN;
6 

Examples

Flattens the input images into a wide table using default settings (resizing to 32x32 pixels).

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3image.flattenImages / TABLE={name="source_images"} casOut={name="flat_basic", replace=true};
4 
5RUN;
6 
Result :
A table named 'flat_basic' is created with columns representing the pixels of the 32x32 resized images.

Flattens images with specific resizing to 64x64, converts them to grayscale, groups channels, and copies the label variable.

SAS® / CAS Code Code awaiting community validation
Copied!
1 
2PROC CAS;
3image.flattenImages / TABLE={name="source_images"} casOut={name="flat_advanced", replace=true} width=64 height=64 numberOfChannels="GRAY_SCALE_IMAGE" groupChannels=true copyVars={"_label_"};
4 
5RUN;
6 
Result :
A table named 'flat_advanced' is created containing 64x64 grayscale flattened images, where channel data is grouped together.

FAQ

What is the primary function of the flattenImages action?
Which parameter is required to specify the output table?
How can I group the color channels of images in the output table?
What are the default dimensions for the output images if I don't specify them?
How do I select specific variables to copy from the input to the output table?
Can I transpose the images during the flattening process?
How do I control the number of channels in the flattened images?