The "processImage" action in SAS is a powerful feature that allows users to perform various image processing operations within the SAS environment. This action enables resizing, cropping, rotating, and applying filters to images, providing precise control over the visual aspects of data presentation. By seamlessly integrating image processing capabilities into the SAS workflow, the "processImage" action streamlines tasks such as generating charts, graphs, and reports with customized and standardized image dimensions.
In this demo, we will walk through an example explaining the importance behind "processImages" action and how useful the function can be for deep learning and machine learning models. We will be using thermal images provided by Kaggle (Chips Thermal Face Dataset) to help demonstrate usefulness of the "processImage" action. By the end of this demo, you will be able to understand each term being used in this throughout this demonstration. First, will discuss some of the terms used in the "processImage" action, this will help give you more insight into what each function is handling within the process image action.
s.image.processimages(
table={'name': 'imgs'},
casout={'name': 'imgsOut', 'replace': True},
imageFunctions=[
{
'functionOptions':
{
'functionType':'RESIZE',
'type': 'BASIC',
'width': 400,
'height': 400
}
}
]
)
In the above code the first term "s.imageprocessimages",it establish the connection to caslib. The caslib is the mechanism used to establish connection to access to tables and data saved. It also allows access to in-memory tables for best performance or load-on-demand access from the caslib's data source for single-pass use. In this demo we are using a session scope-caslib to establish our connection to our thermal image data. The session scope caslib is used in a single session only, it allows access to the caslib and the tables associated with the caslib and are only limited to the session that adds the caslib.
The formatted syntax used for image processing is similar to using Dict ( ) function in python, the dict function creates a dictionary, it consist of a collection of unordered, changeable, and indexed arrays. The table specifies table name, caslib, and other common parameters. The casout specifies the settings for an output table, this will display the image output data of the resized images, the replace function will replace the data with new output data when the dimensions are changed. The "imagefunctions" allows for the user to access function options, from the function options your able to select what type function you would like to perform. There are variety different function options such as resizing, rotating, and blurring as the processing functions, and size, angle. In our demo, we will be performing "RESIZE" function option, this will allow us to change of width and height of the image.
conn.image.loadImages(
caslib='Thermal',
recurse=True,
decode=True,
distribution="random",
labelLevels=1,
casout=dict(name='Thermal', blocksize='128',replace=True)
)
indata = 'Thermal'
From the code above, we are able load the thermal images into cas session. Our assigned cas library 'Thermal" is where the load images are being taken from. The casout table we produce the decode image and place them in the thermal dictionary, the blocksize distributes data, by default the SASHDAT engine distributes data in 2-megabyte blocks. You can override this value by specifying the block size to use.
We first need to use the fetchImage action to retrieve our loaded thermal images before resizing. The fetchImages action normalizes images in a table that can be parsed by clients without requiring additional dependencies.
thermal.Images["Image"][0]
In this part of the demo, we will now use the "processImage" action to process all the images using the step type "RESIZE".
conn.image.processimages(
table={'name': 'Thermal'},
casout={'name': 'Thermal_Out', 'replace': True},'
steps=[
{
'step':
{
'stepType':'RESIZE',
'type': 'BASIC',
'width': 32,
'height': 32
}
}
]
)
NOTE: The table THERMAL contains decoded images.
NOTE: 1275 of 1275 images were processed successfully and saved as decoded images to the Cloud Analytic Services table Thermal_Out.
From the above code, we used the "processImage" action the resize all input for the thermal images to 32x32. The casout table "Thermal_Out" will contain all of decode resized thermal images.
ther=conn.fetchImages(table={'name':'Thermal_Out'})
ther.Images["Image"][0]
From the above code, the fetchImages action will allow access to the decoded images located in the "Thermal_Out" table. The next line of code we call the image function, this specifies the image file that will be displayed graphic output. We are able to see the reduce image sized processed after the "processImage" action.
In conclusion, the "processImages" action can be a useful function action in computer vision pipeline process. It can help with the processing time required when working with deep learning models, for example in this demo our image batch size was 1275 thermal images. If you are working with a larger volume of images you may need to resize the images to perform a deep learning model, this could allows for faster processing time of the deep learning model. For more information about how to use the processImage action and other functions used in this demo please see below.
Available on demand!
Missed SAS Innovate Las Vegas? Watch all the action for free! View the keynotes, general sessions and 22 breakouts on demand.
Data Literacy is for all, even absolute beginners. Jump on board with this free e-learning and boost your career prospects.