Numeric and PIL: 1D array from 2D-tuple 
Author Message
 Numeric and PIL: 1D array from 2D-tuple

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)



Fri, 26 Nov 2004 18:05:46 GMT  
 Numeric and PIL: 1D array from 2D-tuple
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

Quote:

> 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)



Sat, 04 Dec 2004 00:54:50 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. convert 2d array to 1d array without using shift registers and build array

2. 1D binairy array (I16) to 2D array

3. Change a 2D Array into a 1D Array.

4. 1d array containing means of a 2d array

5. 2D array to 1D array

6. Convert 1D string Array to Numeric Array

7. Numeric 2d Array to 3d Array

8. Join 1D three arrays together become a 1d array

9. array 2D to 1D

10. finding 1d index in 2d array of indices

11. creating a new 2D array with two 2D arrays

12. Optimizing 2D tables for speed - 2D array vs. 1D array vs. vector-of-vectors

 

 
Powered by phpBB® Forum Software