Getting list of pixel values from PIL

image, python, python-imaging-library

Solution

Python shouldn't crash when you call getdata(). The image might be corrupted or there is something wrong with your PIL installation. Try it with another image or post the image you are using.

This should break down the image the way you want:

from PIL import Image
im = Image.open('um_000000.png')

pixels = list(im.getdata())
width, height = im.size
pixels = [pixels[i * width:(i + 1) * width] for i in xrange(height)]

Problem

I'm trying to convert a black & white `.jpg` image into a list which I can then modulate into an audio signal. I have imported the PIL module and am trying to call the built-in function: `list(im.getdata())`. When I call it, python crashes. Is there some way of breaking down the image (always 320x240) into 240 lines to make the computations easier? Or am I just calling the wrong function?

Original source