Python Forum
Getting a list in pillow - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Getting a list in pillow (/thread-30692.html)



Getting a list in pillow - IlikePi - Nov-01-2020

with Image.open("test.png") as im:
    print(im.format, im.size, im.mode)
    im = im.convert("CMYK")
I now have picture data converted to CMYK.
I can then do something like

Make double for loops and extract all cyan data such as...
cyan=[]
for x in range(0, xsize)
    for y in range(0, ysize)
        cyan = im[x, y,][0]
where [0] is for Cyan, the first of four
I now have a list of cyan pixels.
Note, if the im pixel size is a few million, the above can take many seconds.
For all four colors, it can take minutes.
Is there a way to extract my cyan list and other four colors from im without having to count through the large im object?

My end goal is to use the Multiprocess python feature and do some pixel processing/math on all four colors at the same time.


RE: Getting a list in pillow - IlikePi - Nov-01-2020

I found a solution in numpy

import numpy
cyan = im.getdata(0)
It seems to work much faster than loading via for loops.