Note that there are some explanatory texts on larger screens.

plurals
  1. POnumpy array is shown incorrect with pyglet
    primarykey
    data
    text
    <p>I have problems with displaying a numpy array with pyglet. I have found a very similar topic (<a href="https://stackoverflow.com/questions/3165379/how-to-display-a-numpy-array-with-pyglet">how to display a numpy array with pyglet?</a>) that I used. I want to display the array in greyscale, but pyglet displays it with colours see the image: <a href="https://i.stack.imgur.com/pL6Yr.jpg" rel="nofollow noreferrer">http://i.stack.imgur.com/pL6Yr.jpg</a></p> <pre><code>def create(self, X,Y): IMG = random((X,Y)) * 255 self.IMG = dstack((IMG,IMG,IMG)) return self.IMG def image(self): self.img_data = self.create(X,Y).data.__str__() self.image = pyglet.image.ImageData(X,Y, 'RGB', self.img_data, pitch = -X*3) return self.image </code></pre> <p>If I save and load the array instead it works (but it is horrobly slower):</p> <pre><code>def image(self): self.im_save=scipy.misc.toimage(self.create(X,Y),cmin=0, cmax=255) self.im_save.save('outfile.png') self.image = pyglet.image.load('outfile.png') return self.image </code></pre> <p>And I get what I wanted:</p> <p>i.stack.imgur.com/FCY1v.jpg</p> <p>I can't find the mistake in the first code example :(</p> <p><strong>EDIT:</strong></p> <p>Many thanks for your answers. With the hint from Bago I got this to code to work :) And indeed nfirvine suggestion is reasonable, since I only want to display the matrix in greyscale.</p> <pre><code>def create(self, X,Y): self.IMG = (random((X,Y)) * 255).astype('uint8') return self.IMG def image(self): self.img_data = self.create(X,Y).data.__str__() self.image = pyglet.image.ImageData(X,Y, 'L', self.img_data) return self.image </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload