swat.cas.datamsghandlers.Image

class swat.cas.datamsghandlers.Image(data, nrecs=1000, subdirs=True)

Bases: swat.cas.datamsghandlers.CASDataMsgHandler

CAS data message handler for images.

Parameters
datastr, pathlib.Path, or iterable of images
Multiple formats are supported for providing images:
  • str or pathlib.Path Path to a directory containing one or more images.

  • iterable of str or pathlib.Path a list of file paths specifying the location of each image.

  • iterable of numpy.ndarray a list of arrays where each array contains the pixel values for the image. Arrays should be (height, width) or (height, width, 3). Channel order is assumed to be RGB.

  • iterable of PIL.Image.Image a list of Pillow Image objects.

nrecsint, optional

The number of rows to allocate in the buffer. This can be smaller than the number of totals rows since they are uploaded in batches nrecs long.

subdirsbool, optional

Whether to search subdirectories for additional images. Only applies when data is a path to a directory. If images are read from subdirectories, the name of the subdirectory will be used as the image class label.

See also

CASDataMsgHandler
numpy.ndarray
PIL.Image.Image

Notes

When using this data message handler to upload client-side images to CAS, the behavior should be similar to that of the image.loadImages CAS action for loading server-side images:

.htm # noqa: E501

Although images will be stored in binary format to a CAS table column labeled “_image_”, the CAS table metadata will not indicate that this column should be interpreted as images. Use the altertable CAS action to update the column’s type:

>>> conn.addtable(table='mytable', **imagedmh.args.addtable)
>>> conn.altertable(table='mytable', columns=[{'name': '_image_', 'binaryType': 'image'}])

Examples

>>> dmh = Image('/path/to/images')
>>> conn.addtable(table='mytable', **dmh.args.addtable).casTable
... CASTable('MYTABLE', caslib='CASUSER(user)')
__init__(self, data, nrecs=1000, subdirs=True)

Initialize self. See help(type(self)) for accurate signature.

Methods

__init__(self, data[, nrecs, subdirs])

Initialize self.

finish(self, connection)

Finish the data sending operation

getone(self, connection, \*\*kwargs)

Get a single response from the server

getrow(self, row)

Get a row of values from the data source

send(self, connection, nrecs)

Send the records to the connection

write(self, row, values)

Write the value to the row and column specified in the buffer

Attributes

args

Property that generates the CAS action parameters for CAS actions that use a data message handler.