BookmarkSubscribeRSS Feed

How to Load Images in SAS Viya 3.5

Started ‎12-16-2019 by
Modified ‎04-26-2020 by
Views 11,296

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.

 

If you only have 60 seconds

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:

 

22. Viya 3.5 SAS Studio task details.png

 

Use SAS Data Explorer to import the images:

 

6. Viya 3.5 SAS Data Explorer image import parameters.png

 

 

Image formats that can be imported

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

 

The whole process

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.

 

/gelcontent/demo/VSVDMML/images/Giraffe_Dolphin/Dolphin/

 

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.

 

Load images using the visual interface: SAS Data Explorer

Add the source caslib (PATH type):

2. Viya 3.5 source caslib.png

 

Navigate the caslib and the images to be loaded:

3. Viya 3.5 SAS Data Explorer image source caslib.png

 

Import the image folder:

4. Viya 3.5 SAS Data Explorer import image directory.png

 

5. Viya 3.5 SAS Data Explorer image source caslib.png

 

Specify the import parameters:

6. Viya 3.5 SAS Data Explorer image import parameters.png

 

Check the results:

7. Viya 3.5 SAS Data Explorer image CAS tables summary.png

 

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:

 

8. Viya 3.5 SAS Data Explorer image CAS table details.png

 

 

An integrated viewer opens. This comes handy if you need to identify the right image:

 

9. Viya 3.5 SAS Data Explorer image viewer.png

 

 

Load images with a SAS Studio task

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:

22. Viya 3.5 SAS Studio task details.png

 

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:

 

24. Viya 3.5 SAS Studio image visualization.png

 

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.

 

Load images with code: 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;
 
*list images in the folder;
proc casutil ;
   list files incaslib="IMAGE" ;
quit ;
* Assign all available caslib;
caslib _all_ assign;

 

Load all the images

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.

 

Import just one image

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

 

Import several images

You need to prepare a list of files. Create “image_list.txt” and upload it in the same folder as the images:

11. Viya 3.5 list of images to be loaded.png

 

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:

 

12. Viya 3.5 SAS Data Explorer image CAS table details.png

 

Finally:

cas mySession terminate;

 

Next Steps

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.

 

Further Info

I would recommend the following resources:

SAS Studio Load Image Task

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

Want to Learn More about Viya 3.5?

Acknowledgements

Brian Gaines, SAS Studio load images task.

Conclusions

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.

Version history
Last update:
‎04-26-2020 09:58 PM
Updated by:
Contributors

SAS Innovate 2025: Register Now

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!

Free course: Data Literacy Essentials

Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning  and boost your career prospects.

Get Started