Numpy and sc resize arrays

pil for 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; inside the lines like this:

a[0] = [[r,g,b],[r,g,b].....[r,g,b],[r,g,b]] = first row

there is a quick way to convert such numpyts numpy arrays back and ford to (well especially back ..)

a = [[rrrr],[rrrrr],[rrrrr],.... [bbbbb],[bbbbbb],[bbbbbb]...,[ggggg],[ggg],[ggg]]

or

as

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 I know the image size is 640x480, how to get it in tablet form quickly, as shown below.

a = array([ [[r,g,b],[r,g,b].....[r,g,b],[r,g,b]]  ,  [[r,g,b],[r,g,b.....]] , int8)
+3
source share
2 answers

Does a.Twhat you want provide ?

I assume that you created your array using the numpy function asarray.

import Image, numpy
im = Image.open('test.png')
a = numpy.asarray(im)
R,G,B,A = a.T

In the above example, you get 4 separate 2D arrays, one for each strip.

+4
source

ahum , ...

, , asarray, (asarry ). . ; a = [r, r, r, r, r, r, r, r, r...] r - , .

b = all bleu, c - . , , . , . Pil , , pygame - , PIL ; ; . Numpy , , , ,

, , , , a, b c

a = [123123123132]

b = [989898389398]

c = [343434343434]

d [a, b, c] = a [] + b [] + c [] → > python,

d d [[a, b, c], [a, b, c], [a, b, c],.....]

and d [0] = [1,9,3]

0
source

Source: https://habr.com/ru/post/1792950/


All Articles