I am using Python and PIL as part of my work on embedding data in binary images and need to analyse groups of pixels to determine appropriate pixels to manipulate in order to embed data. The image needs to be split into equal 'blocks' of pixel data ready for analysis, but I am struggling to come up with an appropriate method of doing this. I have tried techniques using Python and numPy arrays, but without success. Any suggestions would be greatly appreciated.
Thanks
You can use the little known stride tricks to create a view of your image that is built of blocks. It's very fast and does not take any additional memory (the example is a bit verbose):
You need to use
numpy
array
slicing to get group of pixels. Image is just 2D array, so you can usearr = numpy.array(Image.open(filename))
, and after you can slice it.