The image_tensor class provides a convenient way to work with image data
in tensor format. It extends the base array class and provides methods
for conversion to/from various image formats, plotting, and printing.
An image_tensor object represents image data in the format "h w c"
(height, width, channels) for single images, or "b h w c"
(batch, height, width, channels) for batches of images, which is a common
format for deep learning frameworks. It also can be a 2D array, in which
case it is treated as a black and white image and shown as such.
The main utility of wrapping image data in the image_tensor class is that
printing of the object will automatically display the image as a plot,
as long as the imager package is installed. Otherwise it will simply
print the dimension of the image.
Value
as_image_tensor(): An object of classimage_tensoras.cimg(): Acimgobject (from imager package)[.image_tensor(): A subset of theimage_tensorobject. For 4D arrays with single index, returns a 3D slice without the batch dimension.plot(): Invisibly returns the input objectprint(): Invisibly returns the input object
Details
The image_tensor class provides the following methods (and more):
as_image_tensor(): Generic function to convert objects toimage_tensorformat. Takes in array-like objects of 2-4 dimensions. for 2 dimensional objects, it will convert them to 3D by repeating the data across 3 channels, essentially converting grayscale images to RGB.as_image_tensor.default(): Default method that converts arrays toimage_tensoras_image_tensor.cimg(): Method to convertcimgobjects (from imager package) toimage_tensoras.cimg.image_tensor(): Method to convertimage_tensorobjects back tocimgformat[.image_tensor(): Subset method forimage_tensorobjectsplot.image_tensor(): Plot method forimage_tensorobjectsprint.image_tensor(): Print method forimage_tensorobjects
Format
An image_tensor object is an array with dimensions in "h w c" format for
single images, or "b h w c" format for batches of images:
h: height dimension (image height in pixels)
w: width dimension (image width in pixels)
c: channel dimension (RGB, only for 3D & 4D arrays)
b: batch dimension (number of images, only for 4D arrays)
