IOLink IOL_v1.8.0_release
|
First of all, IOLink does not allow to open and decode files. It is not its purpose. See IOFormat component for this need.
IOLink defines a set of interfaces, mainly inheriting from View
, to enable better inter-libraries communication. It also provides some common implementations of these interfaces, like the memory ImageView
for example.
You can use IOFormat to open a view onto a specific encoded file, if the format is supported. Or you can implement your own reader, that we call extractors, using the ImageView
interface.
But, to simply create an in-memory view, from scratch, you can use ImageViewFactory
.
The common interfaces implementations, like the in-memory ImageView
, are defined in factories. There is a factory for each kind of view in IOLink, with each method outputting a view of this specific interface. Thus, to create an in-memory ImageView
, you will use ImageViewFactory
as follows:
With this line of code, you requested to create an empty 2-dimensional ImageView
whose size is 100 x 200, and each pixel is a 8 bits unsigned value.
As you can see, views are stored through shared pointers (from C++ standard library), and it ensures that the view's memory will be automatically handled. A memory buffer is allocated to store that image's data, and will only be released when last shared pointer on the view is freed.
You could also request for more complex formats, such as a three-dimensional image, by passing a higher dimension vector as the first parameter.
This time, a larger memory area (100 x 200 x 15 x 2 bytes) is allocated.
This new image could be a video or a volume. In fact, it could be any kind of three-dimensional image. Currently, it does not matter.
ImageView
instances support a set of capabilities, that are needed to call some of its methods.
An ImageView
capabilities can be tested in different ways:
From your ImageView
instance, you have access to basic information about the image: shape, data type, properties, and metadata.
You can access this information directly with an ImageView
object:
When an ImageView
instance supports the READ
capability, you can read its pixels. Most of ImageView
instances returned by ImageViewFactory
support that capability.
You can read one pixel at a time:
With this code, you read the pixel value at position (16,32). The pixelValue
variable is of unsigned 8 bits type as in the ImageView
data type information.
You also can read a region of your image, as follows:
Here we read a region defined by its origin and its size in the original image. A memory buffer correctly allocated is needed before calling the method. The RegionXu64
provides a method to get the number of elements in this region.
The WRITE
capability of ImageView
provides support for methods to write data into the image.
We can write a pixel:
Here we wrote the pixel value 15
at position (16, 32) in our image.
Same thing to write a region of the image:
Now, with these examples, you can apply basic Image modifications in memory. See the How To section for more details.