Reply To: Doing stats with pixel values

Forums General Discussion Doing stats with pixel values Reply To: Doing stats with pixel values

#632921
Dominic Ford
Keymaster

Hi James,

I fear this isn’t the answer you’re looking for, but this is the kind of task that is very easy in Python:

from PIL import Image
im = Image.open("my_image.tif")
pixels = list(im.getdata())
width, height = im.size
pixels = [pixels for i in xrange(height)]

You can then do whatever you like with your giant array of pixel values. The numpy module already has lots of statistical tools available for immediate use, so your final Python script might be fewer than ten lines of code.

The BAA forum has removed a set of brackets from the last line of the code snippet above and I can’t work out how to fix it, but you should get the idea nonetheless…

Best wishes,

Dominic

  • This reply was modified 2 months, 1 week ago by Dominic Ford.