The condenseImages action is a utility function that converts a CAS table with numeric pixel values into a CAS table that contains images. Each row in the input table corresponds to a single pixel, and the table must contain columns for pixel values, dimensions, and an identifier for each image.
| Parameter | Description |
|---|---|
| table | Specifies the input table that contains the pixel data to be condensed into images. |
| casOut | Specifies the output table to store the condensed images. |
| copyVars | Specifies a list of variables to be copied from the input table to the output table. |
| decode | When set to true, decodes the images in the input table before processing. |
| depth | Specifies the bit depth of the output images (e.g., BIT8, BIT32, BIT64). |
| groupedChannels | When set to true, indicates that the pixel data is grouped by channels (e.g., all blue values, then all green, then all red). |
| height | Specifies the height of the output images in pixels. |
| inputs | Specifies the input variables (columns) to use for constructing the images. If not specified, all numeric columns are used. |
| numberOfChannels | Specifies the number of channels for the output images (e.g., 1 for grayscale, 3 for color). |
| width | Specifies the width of the output images in pixels. |
This example first creates a synthetic dataset named 'pixel_data'. This table simulates a flattened image format where each row contains an image identifier ('_id_'), a channel identifier ('_channel_'), a row index ('_x_'), a column index ('_y_'), and a pixel value ('_value_'). We generate data for two 2x2 grayscale images.
| 1 | DATA pixel_data; |
| 2 | DO _id_ = 1 to 2; |
| 3 | DO _channel_ = 0 to 0; /* Grayscale */ |
| 4 | DO _y_ = 0 to 1; /* Height */ |
| 5 | DO _x_ = 0 to 1; /* Width */ |
| 6 | _value_ = floor(rand('UNIFORM') * 255); |
| 7 | OUTPUT; |
| 8 | END; |
| 9 | END; |
| 10 | END; |
| 11 | END; |
| 12 | RUN; |
| 13 | |
| 14 | PROC CASUTIL; |
| 15 | load DATA=pixel_data outcaslib='casuser' casout='pixel_data_cas' replace; |
| 16 | RUN; |
This example demonstrates the basic usage of the condenseImages action. It takes the flattened pixel data from 'pixel_data_cas' and reconstructs two 2x2 grayscale images, saving them to the 'condensed_images' table.
| 1 | PROC CAS; |
| 2 | image.condenseImages / |
| 3 | TABLE={caslib='casuser', name='pixel_data_cas'}, |
| 4 | width=2, |
| 5 | height=2, |
| 6 | numberOfChannels=1, |
| 7 | inputs={{name='_value_'}}, |
| 8 | copyVars={'_id_'}, |
| 9 | casOut={caslib='casuser', name='condensed_images', replace=true}; |
| 10 | RUN; |
This example shows how to condense a color image where pixel data is provided with grouped channels. First, we create a dataset for a 2x1 color image where all red pixel values are listed first, then all green, then all blue. The 'groupedChannels=true' parameter is essential for correctly interpreting this data structure.
| 1 | DATA pixel_data_color_grouped; |
| 2 | _id_ = 1; |
| 3 | /* Red channel */ |
| 4 | _channel_ = 0; _y_ = 0; _x_ = 0; _value_ = 255; OUTPUT; |
| 5 | _channel_ = 0; _y_ = 0; _x_ = 1; _value_ = 0; OUTPUT; |
| 6 | /* Green channel */ |
| 7 | _channel_ = 1; _y_ = 0; _x_ = 0; _value_ = 0; OUTPUT; |
| 8 | _channel_ = 1; _y_ = 0; _x_ = 1; _value_ = 255; OUTPUT; |
| 9 | /* Blue channel */ |
| 10 | _channel_ = 2; _y_ = 0; _x_ = 0; _value_ = 0; OUTPUT; |
| 11 | _channel_ = 2; _y_ = 0; _x_ = 1; _value_ = 0; OUTPUT; |
| 12 | RUN; |
| 13 | |
| 14 | PROC CASUTIL; |
| 15 | load DATA=pixel_data_color_grouped outcaslib='casuser' casout='pixel_data_color_grouped_cas' replace; |
| 16 | RUN; |
| 17 | |
| 18 | PROC CAS; |
| 19 | image.condenseImages / |
| 20 | TABLE={caslib='casuser', name='pixel_data_color_grouped_cas'}, |
| 21 | width=2, |
| 22 | height=1, |
| 23 | numberOfChannels=3, |
| 24 | groupedChannels=true, |
| 25 | inputs={{name='_value_'}}, |
| 26 | copyVars={'_id_'}, |
| 27 | casOut={caslib='casuser', name='condensed_color_image', replace=true}; |
| 28 | RUN; |
This example demonstrates condensing pixel data and then immediately encoding the resulting image into PNG format using the 'decode' parameter with 'value=true' and specifying an 'encodeType'. This is useful for creating a viewable or transportable image format directly.
| 1 | PROC CAS; |
| 2 | image.condenseImages / |
| 3 | TABLE={caslib='casuser', name='pixel_data_cas'}, |
| 4 | width=2, |
| 5 | height=2, |
| 6 | numberOfChannels=1, |
| 7 | inputs={{name='_value_'}}, |
| 8 | copyVars={'_id_'}, |
| 9 | decode={value=true, encodeType='PNG'}, |
| 10 | casOut={caslib='casuser', name='condensed_encoded_images', replace=true}; |
| 11 | RUN; |