Numeric and PIL: 1D array from 2D-tuple
Leon Widdershoven
leonw at gmx.net
Mon Jun 17 12:54:50 EDT 2002
Hi,
you probably wish to use something like:
text = Image.tostring()
arr = Numeric.fromstring( text )
with a possible Numeric.reshape() if you wish to operate
on something else than a 1D array.
Regards,
Leon
Markus von Ehr wrote:
>
> Hi,
>
> I have a 2D tuple (an Image) and want to display it using ImageTk
> in PIL.
> Numeric.choose throws me an error:
>
> Traceback (innermost last):
> File "<pyshell#14>", line 1, in ?
> res = Numeric.choose(MyImage, mask)
> ValueError: invalid entry in choice array
>
> Anybody knows how to get a 1D-array to construct the
> ImageTk.PhotoImage?
>
> Thanks for any comments,
>
> Markus
>
> code:
>
> MyImage = self.cam.Image # MyImage is a 2D-tuple
>
> mask = [1 for i in MyImage]
>
> MyImage = Numeric.choose(MyImage, mask)
>
> new_image = MyImage.tostring()
> self.im.fromstring(new_image, "raw", "RGBX", 0, -1)
>
> self.photoimage = ImageTk.PhotoImage(self.im)
More information about the Python-list
mailing list