有没有一种方式在 ECL 中可视化 BLOB 数据?

huangapple go评论61阅读模式
英文:

Is there a way visualise BLOB data in ECL?

问题

我有一个在Python中嵌入到ECL中的图像(通过EMBED()函数)。这个图像以一个numpy数组的形式存在。我如何将它返回到ECL,并且有没有可视化图像的方法?

我尝试将numpy数组返回到ECL,但找不到正确的数据类型。

英文:

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

得分: 2

以下是翻译好的内容:

在ECL中没有直接可视化图像的方法,但你可以使用ECL数据处理工具和效率来处理从图像中提取的数据。

让我们以从图像中提取RGB像素的示例为例,使用嵌入的Python代码,然后在ECL代码范围内使用这些数据。在此示例中,我们将使用Numpy和Pillow库,但你可以使用任何库。请注意,重要的是在运行平台的环境中安装这些包,不仅在本地机器上安装。Python代码如下:

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)

它将返回RGB代码的图像翻译,逐像素描述它。

现在,我们将它嵌入到ECL中。由于返回的数据类型可能一开始很难识别,我们始终可以使用将其作为STRING返回,然后在ECL中重新格式化它的方法,因为它是一种强大的面向数据的语言。代码如下:

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;

你的WU的输出将是一个包含从嵌入的Python函数中检索的所有数据的字符串。

请注意,Python在检索数据之前会截断结果,你可以通过在Python范围中添加一些代码行来轻松更改这种行为,例如:

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

之后,只需进行数据重新格式化和转换,以便用于你的目的。

希望这有所帮助。

英文:

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:
有没有一种方式在 ECL 中可视化 BLOB 数据?

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.

huangapple
  • 本文由 发表于 2023年6月27日 22:01:06
  • 转载请务必保留本文链接:https://go.coder-hub.com/76565663.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定