I/O operation¶
The Plums dataflow module implements a set of IO routine to ease and speed up opening images and json files.
The Tile class and the ptype¶
The main interface to open and manipulation images in Plums is tthe Tile class. It allows loading images from
disk through a variety of backends (TurboJPEG,
Lycon, OpenCV
and Pillow). It also adds explicit and native support for a variety of
color domain through the ptype, which acts as a declination of numpy’s dtype for pixels.
As of now, the list of explicitly supported ptype is: RGB, BGR, RGBA, BGRA, and GREY.
Additional ptype may be created on the fly as long as they references existing channels.
-
class
plums.dataflow.io.Tile(filename, ptype=ptype('RGB'), dtype=dtype('uint8'), **properties)[source]¶ Bases:
plums.commons.data.mixin.PropertyContainer,plums.commons.data.tile.TileLoad and manipulate images through a high level interface.
The
Tileclass acts as a “concrete” counterpart to the representationalTileclass defined in the Plums data-model.It necessarily stems from an actual image file on-disk and it additionally encloses 2 type information:
The data-type which is nothing more than the native numpy dtype and indicate the actual numeric type used (e.g. uint8, float32…).
The pixel-type which indicates the way a given pixel is stored as a vector of channel values (e.g. RGB, BGR, HSL, XYZ etc…).
- Parameters
filename (PathLike) – The filename from where the image will be read.
ptype (
ptype) – Optional. Default toRGB. The image pixel-type (e.g. RGB, BGR or Grey).dtype (
dtype) – Optional. Default touint8. The internalndarraystorage data type.**properties (Any) – Additional properties to store alongside the image.
-
filename¶ The filename from where the image was read.
- Type
PathLike
-
property
ptype¶ The image pixel-type.
In a similar fashion as data-type, the pixel-type encodes the way a particular pixel vector can be interpreted as actual data carried by the tile.
- Type
-
property
dtype¶ The internal
ndarraystorage data type.Warning
Modifying the
dtypewill only modify the storagendarray’s data type. No domain conversion logic is applied, that is to say that, for example, converting auint8Tiletofloat64will effectively change the underlying array’s type but the data will still be between 0 and 255.- Type
-
save(filepath, ptype=ptype('RGB'))[source]¶ Save the
Tileas a image on disk.- Parameters
- Raises
ValueError – If
filepathrefers to un unsupported image type.TypeError – If
ptypeis not RGB as it is the only supported save format for now.
-
totype(ptype=None, dtype=None)[source]¶ Convert the
Tilestorage format in-place to a new pixel-type or a new data-type.
-
class
plums.dataflow.io.ptype(string)[source]¶ Bases:
objectThe pixel-type of a given image: A representation of its spectral base.
As each actual pixel are stored as vectors, understanding of the base used is compulsory to decode a given pixel vector, the pixel-type class describes the way a given pixel is stored as a vector of channel values (e.g. RGB, BGR, HSL, XYZ etc…).
- Parameters
string (str) – A string description of the pixel-type as a list of channel characters (e.g.
'RGB','rgY','bgr','y'…).
-
contains(channels)[source]¶ Return whether the pixel-type
Channelvector contains a givenChannelorChannel“sub-set”.
-
slice(channels)[source]¶ Compute the pixel-type
Channelvector slice of a given sub-vector.- Parameters
channels (tuple,
Channel) – Either a singleChannelor a tuple ofChannelassumed to be a sub-vector of the pixel-typeChannelvector.- Returns
The slice of the
Channelvector corresponding to the input orNoneif it is not contained in theChannelvector.- Return type
(int, int) or
None
-
index(channels)[source]¶ Compute the pixel-type
Channelindices of a given sub-set.- Parameters
channels (tuple,
Channel) – Either a singleChannelor a tuple ofChannelassumed to be a sub-set of the pixel-typeChannelvector.- Returns
The indices of the
Channelcorresponding to the input orNoneif it is not contained in theChannelvector.- Return type
(int, ) or
None
Deserialize JSON with the fastest backend¶
Plums dataflow allows fast JSON deserialization with additional backends on top of the standard json
library if they are available (OrJSON,
RapidJSON,
and SimpleJSON).
The use ordering is expected to reflect loading speed however, because the relative speed of backends is highly dependent on data, it is recommended to benchmark all library for specific use-cases to select the best possible backend.