Image Action Set
Loading an RGB Image and a Segmentation Image, and Annotating the Former with the Latter
This example is not available for the CAS programming language.
Loading an RGB Image and a Segmentation Image, and Annotating the Former with the Latter
This example is not available for the Lua programming language.
Loading an RGB Image and a Segmentation Image, and Annotating the Former with the Latter
This section contains Python code. For more information about coding in Python, see Getting Started with SAS Viya for Python and SAS Viya: System Programming Guide.
The following Python code loads an RGB image and an 8-bit, single-channel segmentation image, and overlays the latter on the former. Note that the runCode action in the dataStep action set is used to merge the two loaded tables into one. The view action is called to convert the binary variable _image_ to character variable format, because the dataStep action set does not yet support binary variables. Figure 2, Figure 3, and Figure 4 show the input and output images.
# Load an RGB image
imdata = s.CASTable('imdata', replace=True)
s.image.loadimages(path='bldgc_pi.png',
casout=imdata,
)
# Load a simple segmentation image
imdata_seg = s.CASTable('imdata_seg', replace=True)
s.image.loadimages(path='bldgc_pi_box.png',
casout=imdata_seg,
)
# Join the 2 image tables
r = s.table.view(
name='view',
tables=[dict(name='imdata',
computedvars={'vcimage'},
computedvarsprogram="length vcimage varchar(*);"
"vcimage=_image_;",
varlist={'_id_'})],
replace=True)
r = s.table.view(
name='view_seg',
tables=[dict(name='imdata_seg',
computedvars={'vcimage_seg'},
computedvarsprogram="length vcimage_seg varchar(*);"
"vcimage_seg=_image_;",
varlist={'_id_'})],
replace=True)
r = s.dataStep.runcode(code="data merged;"
"merge view(in=a) view_seg(in=b);"
"by _id_;"
"if a & b;"
"run;")
# Do annotation
merged = s.CASTable('merged', replace=True)
adata = s.CASTable('adata', replace=True)
s.image.annotateimages(images=dict(table=merged, image='vcimage'),
annotations=[
dict(annotationparameters=dict(
annotationType='segmentation',
image='vcimage_seg',
colorMap='autumn',
transparency=50,
))
],
casout=adata)
Figure 2: The RGB Image on Which the Annotation Is Made

Figure 3: The Segmentation Image Used to Annotate the RGB Image

Figure 4: The Result of Annotation

Loading an RGB Image and a Segmentation Image, and Annotating the Former with the Latter
This example is not available for the R programming language.