image

annotateImages

Description

The `annotateImages` action overlays various annotations onto images within a CAS table. This is useful for visualizing results from image analysis tasks like object detection, segmentation, or feature extraction. You can draw lines, points, or complex shapes defined by protobuf messages, and even overlay segmentation masks with specified color maps and transparency. The resulting annotated images are saved to an output CAS table.

image.annotateImages { annotations={{annotation={annotationType="LINES" | "POINTS" | "PROTOBUF" | "SEGMENTATION", annotationType-specific-parameters}}}, casOut={...}, copyVars={"variable-name-1", ...}, decode={...}, images={...} };
Settings
ParameterDescription
annotationsSpecifies the annotations to be performed on the images.
casOutSpecifies the output table to store the annotated images.
copyVarsSpecifies a list of variables to be copied from the input table to the output table.
decodeWhen set to true, decodes the input images. This is necessary if the images are compressed.
imagesSpecifies the input table containing the images to be annotated.
annotationTypeSpecifies the type of annotation. Can be 'LINES', 'POINTS', 'PROTOBUF', or 'SEGMENTATION'.
thicknessSpecifies the thickness of the lines or points in pixels.
colorMapSpecifies the color map for segmentation annotations.
transparencySpecifies the transparency percentage for segmentation overlays.
Data Preparation View data prep sheet
Creating an Image Table with Annotations

This example demonstrates how to load images from a specified path into a CAS table and prepare it for annotation. We add columns for points and lines that will be used by the `annotateImages` action.

Copied!
1/* Create a CAS table with images and annotation data */
2PROC CAS;
3 LOADACTIONSET 'image';
4 /* Load images into a CAS table */
5 loadimages path='path/to/your/images' casout={name='my_images', caslib='casuser', replace=true};
6 /* Add columns for annotations */
7 altertable 'my_images' addcolumn={name='_points_', type='varchar'};
8 altertable 'my_images' addcolumn={name='_lines_', type='varchar'};
9 /* You would typically populate these columns with annotation data from another source or a previous analysis step */
10QUIT;

Examples

This example demonstrates how to annotate images by drawing red points. The points are defined in the `_points_` column of the input table.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.annotateImages /
3 TABLE={name='my_images', caslib='casuser'},
4 casOut={name='annotated_images_points', caslib='casuser', replace=true},
5 annotations=[
6 {annotation={annotationType='POINTS', r=255, representation={representationType='SINGLE_COLUMN', columnName='_points_'}}}
7 ];
8QUIT;
Result :
The `annotated_images_points` table is created, containing the original images with red points drawn on them based on the coordinates in the `_points_` column.

This example shows how to perform multiple annotations. It draws blue lines with a specified thickness and overlays a segmentation mask using the 'JET' colormap with 50% transparency.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.annotateImages /
3 TABLE={name='my_images', caslib='casuser'},
4 casOut={name='annotated_images_detailed', caslib='casuser', replace=true},
5 annotations=[
6 {annotation={annotationType='LINES', b=255, thickness=3, representation={representationType='SINGLE_COLUMN', columnName='_lines_'}}},
7 {annotation={annotationType='SEGMENTATION', image='_segmentation_mask_', colorMap='JET', transparency=50}}
8 ];
9QUIT;
Result :
The `annotated_images_detailed` table is created. The images in this table will have blue lines and a semi-transparent segmentation overlay, based on the data in the `_lines_` and `_segmentation_mask_` columns respectively.

This example annotates images using object detection bounding boxes stored in a Protobuf format column named `_protobuf_`. This is a common scenario when working with deep learning model outputs.

SAS® / CAS Code Code awaiting community validation
Copied!
1PROC CAS;
2 image.annotateImages /
3 TABLE={name='my_images', caslib='casuser'},
4 casOut={name='annotated_images_protobuf', caslib='casuser', replace=true},
5 annotations=[
6 {annotation={annotationType='PROTOBUF', representation={representationType='SINGLE_COLUMN', columnName='_protobuf_'}}}
7 ];
8QUIT;
Result :
The `annotated_images_protobuf` table is created, with bounding boxes and labels drawn on the images as defined by the content of the `_protobuf_` column.

FAQ

What is the purpose of the `image.annotateImages` action in SAS Viya?
What are the required parameters for the `image.annotateImages` action?
What types of annotations can be performed with this action?
How can I specify the color and thickness of line annotations?
What does the `decode` parameter control?
How do I specify the input table containing the images to be annotated?
Is it possible to copy variables from the input table to the output table?
How can I apply a color map for segmentation annotations?

Associated Scenarios

Use Case
Manufacturing: Circuit Board Defect Visualization

A factory uses automated optical inspection to find defects on circuit boards. After a detection model identifies defect coordinates, this scenario uses `annotateImages` to draw...

Use Case
Medical Imaging: Highlighting Anomalies with Missing Data

A radiologist is reviewing a batch of brain MRI scans. A preliminary AI model has identified potential anomalies (e.g., tumors) and marked their centers with coordinates. Howeve...

Use Case
Autonomous Driving: Multi-Layer Scene Annotation

An autonomous vehicle's perception system identifies objects (cars, pedestrians), classifies drivable areas (road, lane markings), and plans a trajectory. This complex scenario ...