[Image-SIG] reaching memory limits with crop method]

Fredrik Lundh fredrik at pythonware.com
Fri Sep 9 12:46:53 CEST 2005

Adam J Smith wrote:

>>following up to the response you got may also be a good
> My apologies, I see that I accidentally replied to your personal email
> instead of the list.

that's not a problem in itself, but I never got it (from what I can tell).
probably a spam filter issue :-(

> Here is it again. Does this help?

this shows that the image is sliced and uncompressed, which means
that you should be able to read the image piece by piece simply by
manipulating the contents of the "size" and "tile" attributes before you
load the image.

I don't have time to dig up a tested example right now, but here's an
"off the top of my head and completely untested" outline:

    im = Image.open(...)
    tiles = im.tile

    for tile in tiles:

        # get the tile parameters
        layout, extent, offset, args = tile

        # where in the image should this data go
        x0, y0, x1, y1 = extent

        assert layout == "raw"

        im = Image.open(...)

        # read a single tile
        im.size = x1-x0, y1-y0
        im.tile = [(layout, (0, 0) + im.size, offset, args]

        ... process the image ...

to speed things up, you may want to process multiple tiles in each iteration
(to get this right, you need to calculate a proper size for a group of tiles, and
set the tile extent properly for each subtile).


More information about the Image-SIG mailing list