pil to numpy conversion leads to arrays like:
a = array([ [[r,g,b],[r,g,b].....[r,g,b],[r,g,b]] , [[r,g,b],[r,g,b.....]] , int8)
triplets of rgb values; within rows so :
a[0] = [[r,g,b],[r,g,b].....[r,g,b],[r,g,b]] = first row
is there a quick way to convert such triplets numpy arrays back and ford to (well especialy back..)
a = [[rrrr],[rrrrr],[rrrrr],.... [bbbbb],[bbbbbb],[bbbbbb]...,[ggggg],[ggg],[ggg]]
or
like
a=[[rrr],[rrrrr],[.... ...]] **or** aa = [rrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrr..]
b=[[bbb],[bbbbb],[.... ...]]**or** bb = [bbbbbbbbbbbbbbbbbbbbbbbbbb..]
c=[[ggg],[ggggg],[.... .]] **or** cc = [ggggggggggggggggggggggggg..]
My problem I have a format like aa bb cc and know the image size 640x480 how to get it fast into pill format as below
a = array([ [[r,g,b],[r,g,b].....[r,g,b],[r,g,b]] , [[r,g,b],[r,g,b.....]] , int8)
Does a.T
give you what you want?
I'm assuming you've created your array using numpy's asarray
function.
import Image, numpy
im = Image.open('test.png')
a = numpy.asarray(im)
R,G,B,A = a.T
The above will give you 4 separate 2D arrays, one for each band.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With