Drawing string from numpy array

I've searched far and wide, but haven't found a solution yet, so I'll ask here. I have a script that creates a large numpy array of coordinate points (~ 10 ^ 8 points) and then I want to draw a polygon line using the coordinates. PIL ImageDraw.line works fine for regular lists, but there seems to be a problem when using numpy arrays.

This is my solution now:

image = Image.new('RGB', (2**12, 2**12), 'black')
draw = ImageDraw.Draw(image, 'RGB')
draw.line(pos.tolist(), fill = '#00ff00')

      

where pos

is an array with a large number containing all points in the following order: [x0, y0, x1, y1, ...]

(this can be changed if necessary). The most time consuming part of the program is the part pos.tolist()

that takes about 75% of the execution time.

Is there a way to draw a line and store it in the image and store it as a numpy array? I just want a simple image, nothing more than a line and a black background.

+3


source to share





All Articles