Posts

Showing posts with the label python-imaging-library

Is there any better way to capture the screen than PIL.ImageGrab.grab()?

Is there any better way to capture the screen than PIL.ImageGrab.grab()? I am making a screen capture program with python. My current problem is PIL.ImageGrab.grab() gives me the same output as 2 seconds later. For instance, for I think I am not being clear, in the following program, almost all the images are the same, have the same Image.tostring() value, even though I was moving my screen during the time the PIL.ImageGrab.grab loop was executing. >>> from PIL.ImageGrab import grab >>> l = >>> import time >>> for a in l: l.append(grab()) time.sleep(0.01) >>> for a in range(0, 30): l.append(grab()) time.sleep(0.01) >>> b = >>> for a in l: b.append(a.tostring()) >>> len(b) 30 >>> del l >>> last = >>> a = 0 >>> a = -1 >>> last = "" >>> same = -1 >>> for pic in b: if b == last: same ...

Working with TIFFs (import, export) in Python using numpy

Working with TIFFs (import, export) in Python using numpy I need a python routine that can open and import TIFF images into numpy arrays, so I can analyze and modify the contained data and afterwards save them as TIFFs again. (They are basically light intensity maps in greyscale, representing the respective values per pixel) I tried to find something, but there is no documentation on PIL methods concerning TIFF. I tried to figure it out, but only got bad mode/ file type not supported errors. What do I need to use here? 6 Answers 6 First, I downloaded a test TIFF image from this page called a_image.tif . Then I opened with PIL like this: a_image.tif >>> from PIL import Image >>> im = Image.open('a_image.tif') >>> im.show() This showed the rainbow image. To convert to a numpy array, it's as simple as: >>> import numpy >>> imarray = numpy.array(i...