Data has moved from traditional files and tables to anything that can be processed. SAS Viya 3.5 provides CAS actions for processing images. To step in the realm of computer vision, first you need to load images in CAS. Read more and learn the basics of loading.
SAS Viya CAS image action allows you to read, write images, process images and manipulate image data. Firstly, you need to load the images in CAS. This is when the loadImages CAS action comes handy. A SAS Visual Data Mining and Machine Learning license is required.
You have several options:
Write a CAS action in SAS Studio (the full sample code is below):
* load many files based on list; proc cas; image.loadImages / casOut={name="dolphin_images", replication=0, replace=true} caslib="IMAGE" path="image_list.txt" decode=TRUE pathIsList=TRUE; quit;
Use a SAS Studio Load Images task:
Use SAS Data Explorer to import the images:
The loadImages action reads images and associated metadata into memory. Viya 3.5 can work with the following formats:
Format | File Extensions |
Windows bitmap | .bmp, .dib |
Joint Photographic Experts Group (JPEG) | .jpeg, .jpg, .jpe |
Portable Network Graphics | .png |
Tagged Image File Format (TIFF) | .tiff, .tif |
ZIP files of photos | .zip |
Digital Imaging and Communications in Medicine (DICOM) standard | .dcm, none |
Nearly raw raster data (NRRD) | .nrrd, .nhdr |
Neuro-imaging Informatics Technology Initiative (NIfTI) | .nii |
Analyze | .img |
MetaImage | .mha, .mhd |
WebP | .webp |
Portable image format | .pbm, .pgm, .ppm |
JPEG 2 | .jp2 |
Suppose you want to train / score a detection model. And you want to test your model on a few images in .jpg format.
Copy these images to a directory that a CAS server can access. For example, FTP them on the SAS CAS controller.
Add a source caslib: IMAGES. This must be of type PATH.
Add or identify the target caslib, for example: CASUSER. The target caslib is a global caslib on the same CAS server as the source caslib. Each row in the output table represents one image and its metadata. The caslib for the target table must support labels, therefore they can be a PATH, DNFS and HDFS type. A caslib for a DBMS does not support labels.
Add the source caslib (PATH type):
Navigate the caslib and the images to be loaded:
Import the image folder:
Specify the import parameters:
Check the results:
The CAS table contains 5 columns and 237 rows (one row for each image in the folder). With SAS Data Explorer, all images from the folder are imported.
In Details: _image_ is a varbinary image variable storing the image data. The rest is image metadata.
In Sample data, click on the image icon:
An integrated viewer opens. This comes handy if you need to identify the right image:
The task gives you the flexibility of the code (discussed below) with a point and click interface.
Load the images in a location accessible to SAS Studio and CAS.
In SAS Studio Start a session and assign the source image caslib:
* Initialize session variables; options msglevel=i; %let clib=IMAGE; * start CAS session; CAS mySession SESSOPTS=(CASLIB=casuser TIMEOUT=999 LOCALE="en_US" metrics=true); * define the PATH caslib on the images folder; caslib IMAGE path="/gelcontent/demo/VSVDMML/images/Giraffe_Dolphin/Dolphin/" type=path global;
In the Tasks pane, select SAS Viya Machine Learning > Computer Vision > Load Images. The Load Images task opens: load from source IMAGE caslib to target CASUSER.dolphin_images CAS table:
Run. Check the log
NOTE: Executing action 'image.loadImages'.
NOTE: Loaded 237 images from /gelcontent/demo/VSVDMML/images/Giraffe_Dolphin/Dolphin/ into Cloud Analytic Services table dolphin_images.
NOTE: Action 'image.loadImages' used (Total process time):
NOTE: real time 2.478914 seconds
The results contain a random set of the images in the directory. Here is an example of the results in a new browser window:
This task is a part of a larger computer vision project SAS is working on that involves developing a series of related computer vision tasks in SAS Studio that will ultimately cover the end-to-end analysis pipeline (load, explore, process, augment, model, score). The goal is for these tasks to make it easier for users to implement image processing and deep learning capabilities. The current focus is on image classification but it might expand to cover other applications such as object detection, segmentation, and 3D medical images.
Start a session and assign the source image caslib:
* Initialize session variables; options msglevel=i; %let clib=IMAGE; * start CAS session; CAS mySession SESSOPTS=(CASLIB=casuser TIMEOUT=999 LOCALE="en_US" metrics=true); * define the PATH caslib on the images folder; caslib IMAGE path="/gelcontent/demo/VSVDMML/images/Giraffe_Dolphin/Dolphin/" type=path global; *list images in the folder; proc casutil ; list files incaslib="IMAGE" ; quit ; * Assign all available caslib; caslib _all_ assign;
proc cas; table.dropTable / caslib="casuser" name="dolphin_images" quiet=TRUE; run; image.loadImages / casOut={name="dolphin_images", replication=0, replace=true} caslib="IMAGE" recurse=TRUE; run; table.promote / caslib="IMAGE" drop=TRUE name="dolphin_images" target="dolphin_images" targetLib="casuser"; quit;
Check the log:
NOTE: Executing action 'image.loadImages'. NOTE: Loaded 237 images from /gelcontent/demo/VSVDMML/images/Giraffe_ Dolphin/Dolphin/ into Cloud Analytic Services table dolphin_image.
The results will be the same as your import with SAS Data Explorer.
You could write:
* load a single image; proc cas; table.dropTable / caslib="casuser" name="dolphin_images" quiet=TRUE; run; image.loadImages / casOut={name="dolphin_images", replication=0, replace=true} caslib="IMAGE" path="dolphin_10752.jpg"; run; table.promote / caslib="IMAGE" drop=TRUE name="dolphin_images" target="dolphin_images" targetLib="casuser"; quit;
Check the log:
NOTE: Executing action 'image.loadImages'. NOTE: Loaded 1 image from /gelcontent/demo/VSVDMML/images/Giraffe_ Dolphin/Dolphin/dolphin_10752.jpg into Cloud Analytic Services
You need to prepare a list of files. Create “image_list.txt” and upload it in the same folder as the images:
In the code your write, use the path=”image_list.txt” pathIsList=TRUE :
* load many images based on a list; proc cas; table.dropTable / caslib="casuser" name="dolphin_images" quiet=TRUE; run; image.loadImages / casOut={name="dolphin_images", replication=0, replace=true} caslib="IMAGE" path="image_list.txt" pathIsList=TRUE decode=TRUE; run; table.promote / caslib="IMAGE" drop=TRUE name="dolphin_images" target="dolphin_images" targetLib="casuser"; quit;
Check the log:
NOTE: Loaded 2 images from /gelcontent/demo/VSVDMML/images/Giraffe_Dolphin/Dolphin/image_list.txt into Cloud Analytic Services
Check the output in SAS Data Explorer:
Finally:
cas mySession terminate;
You are now ready to start processing images using Viya 3.5. More actions are available in the CAS Image Action Set: annotate images with metadata, augment, compare, condense, extract detected objects, fetch, flatten, match, process, save and summarize.
I would recommend the following resources:
Viya 3.4 BLOBs (Binary Large Objects) in CAS
SAS Data Explorer 2.5 importing images
SAS® 9.4 and SAS® Viya® 3.5 Programming
Beth’s Computer Vision: What Is It? and Image Processing with SAS Viya
Brian Gaines, SAS Studio load images task.
Loading all images is simple and straightforward with the visual interface. If you need to load selectively or customize the image metadata, you now have a very useful SAS Studio task or you can use code.
Stay tuned for more stories. And please comment, share and help others. Thank you for your time.
Registration is now open for SAS Innovate 2025 , our biggest and most exciting global event of the year! Join us in Orlando, FL, May 6-9.
Sign up by Dec. 31 to get the 2024 rate of just $495.
Register now!
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.