Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Getting a list in pillow
#1
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.
Reply
#2
I found a solution in numpy

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


Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020