Is there a way visualise BLOB data in ECL?

56 Views Asked by At

I have an image in Python embedded in ECL(through the EMBED() function). The image is in the form of a numpy array. How do I return it back to ECL and are there any methods to visualize the image?

I tried returning the numpy array back to ECL but couldn't find the right datatype.

1

There are 1 best solutions below

0
On

There is no direct way to visualize images in ECL, but you can use the ECL data manipulation tools and efficiency to work with the data extracted from the image.

Let's use the example of a RGB pixel extraction of an image, using embedded python, and then use the data in the ECL code scope. For this example we'll be using the Numpy and Pillow libraries, but you could be using any library you want. Note that is important to have these packages installed on the environment running the platform, not only in your local machine. The Python code will be:

from PIL import Image
from numpy import asarray

# load the image and convert into
# numpy array
img = Image.open('download.jpg')

# asarray() class is used to convert
# PIL images into NumPy arrays
numpydata = asarray(img)

#  shape
print(numpydata)

It'll return a translation of the image for the RGB code, describing it pixel by pixel.

Now, we embed it in ECL. Since the data type for return may be difficult to spot at first, we can always use an approach of returning it as STRING and reformatting it later using ECL, since it's a powerful data oriented language. The code would be:

IMPORT Python3 as PYTHON;
IMPORT lib_fileservices;

STRING PyImgToECL (STRING LandingZone = 
lib_fileservices.FileServices.GetDefaultDropZone() + '/') := EMBED(Python)
    from PIL import Image
    # import numpy
    from numpy import asarray
    # import sys
    # numpy.set_printoptions(threshold=sys.maxsize)


    # load the image and convert into
    # numpy array
    img = Image.open(LandingZone + '/' + 'download.jpg')

    # asarray() class is used to convert
    # PIL images into NumPy arrays
    numpydata = asarray(img)

    #  return the data as string
    return str(numpydata)
ENDEMBED;

funcReturn := PyImgToECL();
funcReturn;

The output of your WU will be a string containing all the data retrieved from the embedded python function: Workunit result

Notice that Python truncates the results before retrieving the data, you can easily change this behaviour by adding a couple lines of code in the Python scope, such as:

import sys
numpy.set_printoptions(threshold=sys.maxsize)

After that, is just a matter of data reformat and transformation so you can use it to serve your purposes.

Hope this helps.