[Image-SIG] float rgba list -> Image
Charlie Clark
charlie.clark at clark-consulting.eu
Wed Aug 31 17:06:37 CEST 2011
Am 31.08.2011, 16:21 Uhr, schrieb Ingo Randolf <ingo at quitch.net>:
> Hi all.
> I have a list with float-values describing an image like this:
> [R, G, B, A, R, G, B, A, R, G, B, A, R, G, B, A, R, G, B, A, ... etc.]
> the RGBA-values are from 0. - 1.
> is there a clever way to make a PIL-Image out of something like this?
> i played around with putdata... and came along with this, very, very
> slow solution:
> px = list-of-rgba-values-as-floats
> img = the-image
> #make int-tuples
> newdata = [(int(px[(x*4)]*255), int(px[(x*4)+1]*255),
> int(px[(x*4)+2]*255), int(px[(x*4)+3]*255)) for x in range( img.size[0]
> * img.size[1] )]
> Image.putdata(newdata)
> well i never saw a result, because it took too long for my short
> patience...
You can turn that list into a list of tuples for each pixel like this
new_array = []
for idx in range(0, len(l), 4)
new_array.append(tuple(l[idx:idx+4]))
You can probably wrap this in some functional programming so that you are
not using memory for transitional data structures.
Charlie
--
Charlie Clark
Managing Director
Clark Consulting & Research
German Office
Helmholtzstr. 20
Düsseldorf
D- 40215
Tel: +49-211-600-3657
Mobile: +49-178-782-6226
More information about the Image-SIG
mailing list