Engee documentation
Notebook

Working with images in Engee

Let's present an approach for designing image processing algorithms to load an image into a component on the Engee canvas and process different colour channels.

Purpose of the example

Graphical design environments allow you to achieve very high speed of development. And although full-fledged graphical development requires a large library of components, which the designer must be able to understand, this approach allows to avoid coding errors and generally equalise the opportunities of professional programmers and experts of other applied scientific fields.

Task description

In this example we will show how to load an image into a canvas component and invert one of the channels. The name of the input file with the image should be given as the parameter Название файла of the block Изображение. It is assumed that the image has 4 channels.

If there is no Alpha channel (transparency channel) in the input image, the model will output a matrix consisting of 255 values at the output A.

Image size warning

The method of storing an image inside a block is not very efficient when dealing with large images. This may be the case if you store matrices in text form inside the block code.

We recommend debugging the algorithm on a small-sized image (less than 200 pixels on a side). Most likely, for good processing of large images, it is necessary to place them in the code of components in the format char* and "unpack" them with the help of additional C/C++ libraries.

With an initial 300 by 300 image, the model compiles 62 seconds, initialises 49, executes 0.36s (total 110s).

With a 200 by 200 source image, the model compiles for 18 seconds, initialises for 25, and runs for 0.32 seconds (total 43 s).

100*100 images are processed in less than 10 seconds, including model compilation and initialisation.

Model description

When the mask parameters are changed, the image on the front of the block is updated. The image is also placed inside the block code and is not erased if you move the model or move or delete the original image file.

image.png

Let's run the model through the programme control mechanism:

In [ ]:
model_name = "picture_read_model";
model_name in [m.name for m in engee.get_all_models()] ? engee.open(model_name) : engee.load( "$(@__DIR__)/$(model_name).engee");
res = engee.run( model_name );

Examine the transformed image by accessing the function RGBA of the library Images.jl

In [ ]:
pic = RGBA.( collect(res["out_R"])[end,end]./255,
       collect(res["out_G"])[end,end]./255,
       collect(res["out_B"])[end,end]./255,
       collect(res["out_A"])[end,end]./255 )
Out[0]:
No description has been provided for this image

Let's save the obtained image to a file.

In [ ]:
save( "out.png", pic )

As expected, we inverted the values in the red colour channel, removed the transparency channel and output the image.

Conclusion

Engee allows relatively easy prototyping of machine vision algorithms, while maintaining the hierarchy and logistical clarity of the operations performed that graphical programming provides.

Blocks used in example