![]() |
IOLink Python IOL_v1.8.0_release
|
IOLink Python has capacity to inter-operate with NumPy arrays.
Python user can import its data from a NumPy Array into IOLink, and can interpret an ImageView
that support the MEMORY_ACCESS capability as a NumPy array, without memory duplication.
IOLink python contains a class NumpyInterop
which provides services for interoperability with NumPy.
Good to know, when the numpy array content is modified, the view content is impacted, and vice-versa.
Numpy allows to create arrays with different memory layouts:
Console outputs:
IOLink uses a canonical order of dimensions for reading and writing.
Dimensions are always ordered as following:
If the Numpy array to import into IOLink does not follow the same logic, IOLink allows to configure the import mechanism as follow:
By doing this, data are reorganized for IOLink, without impact on Numpy array original content, and without any copy.
The export only works with ImageView
with the MEMORY_ACCESS capability since data must be available in memory for Numpy. Numpy array and ImageView share the same memory. Consequently, a modification in one will impact the other.
As IOLink views and Numpy arrays use different conventions for the order of dimensions, we need to change the indexing.
In Numpy conventions, order is almost inversed (T, Z, Y, X, C) in comparison to IOLink canonical order.
In the case of a view on vectorial data, Vector3u16 for example, the Numpy array will have an additionnal dimension at the end, its size being the number of components of the vectorial data type.
Example: a VOLUME
ImageView of shape (12, 4, 6) will result in a Numpy array with a shape of (6, 4, 12) if the view store a scalar data type. If the stored data type is vectorial, for example Vector3u16, the resulting Numpy array will have the following shape (6, 4, 12, 3).
Console outputs:
If your ImageView has no axes interpretation
, which means dimensions are not clearly identified, the reorder is not possible at conversion into Numpy. Dimensions are kept in original order. Only vectorial DataType will be converted into an additionnal dimension at the end.
Console outputs:
As developers can choose to not follow Numpy convention, IOLink provides another method to export an ImageView as a Numpy Array. This time, the developer can choose the order of axes during export. But it needs the ImageView has all its axes well-defined (axes interpretation
should not be UNKNOWN).
Console outputs:
In the case of vectorial data, a CHANNEL
dimension will be created at export and shall be also ordered:
Console outputs:
In io module, I/O classes provides APIs to manipulate data streams.
StreamAccess in IOLink allows to manipulate raw data and is quite similar with the abstract class io.RawIOBase
(which inherits from io.IOBase
.
IOLink provides an inter-operability mechanism to adapt StreamAccess as a io.RawIOBase
object.
Console outputs: