Re: Large image re-scaling

From: Dave Martindale (davem_at_cs.ubc.ca)
Date: 06/05/04


Date: Sat, 5 Jun 2004 17:01:35 +0000 (UTC)

crwper@mustagh.com (Michael Cooper) writes:
>I have a fairly large image (21600x21600x3) which I would like to
>enlarge to 32768x32768. I've tried several packages (GIMP,
>ImageMagick, Paint Shop Pro, Image Genius, PhotoZoom Pro, etc.), but
>they all seem to be trying to load the entire file into memory first.
>I'm not terribly fussy about the interpolation technique, although I'd
>like something better than the nearest-neighbour code I've just
>written. Bicubic would be fine. The image is currently in TIFF format.

It doesn't have to be done this way. Upsampling, like many image
processing operations, is a localized computation. Every output pixel
depends on a limited-size region of the input. For bicubic resampling,
the input size is 4x4, while larger filters use 8x8 input pixels or even
more. But whatever the number, it's a tiny fraction of the total image.

If there is no rotation involved, the simplest method for limited-memory
resampling is to read as many scanlines of the original as the extent
of the filter kernel into a buffer. Then you generate one output
scanline. Every several output scanlines (depending on the
magnification factor), you dump the oldest input scanline which is no
longer needed, and read in one new scanline. I've written an image
resampler that works this way.

If even that involves too much memory, or if rotation is involved, it's
probably best to divide the input image into square tiles, and then
manage a tile input buffer rather than scanline buffer. For reasonable
tile and kernel sizes, you'll probably find you need only 4 input tiles
and one output tile in memory at any time.

As for commercial software that does this, Photoshop operates on image
tiles if the image won't fit in the amount of main memory you give it.

But, as the other followup said, why do you want to resize this image in
the first place? There's almost certainly a better way to do whatever
you're trying to accomplish without creating all that redundant data.

        Dave



Relevant Pages

  • Re: Memory modulates color appearance
    ... need to invoke "higher level memory" to explain what was observed? ... We must think about HLM, otherwise the phenomenon serves for nothing. ... Anytime we observe something in nature, we try to explain it using ... Make a set of tiles of different shapes, ...
    (comp.ai.philosophy)
  • Re: Stitching lots of images together?
    ... Keep track of available memory, find out how many tiles he ... then scale down the tiles that you stitch together. ... them over to the picturebox at 178 X 178. ... get the Free Memory value, ...
    (microsoft.public.vb.general.discussion)
  • Re: Tiling large bitmap, what size tile is best?
    ... image and a set of device caps, and will load all of the data into memory ... > like fixed-size tiles would help prevent cracks at the boundaries. ... > advantage of smaller tiles is that they would use less texture memory but ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Map granularity in City Navigator 8 Europe - really not happy!
    ... around 270 map tiles. ... that Garmin had reduced the number of subdivisions to around 100 tiles, ... There are now routes I cover which won't all fit into memory anymore as ... Garmin has said that City Navigator NA 8 will have more segments than CN NA 7. ...
    (sci.geo.satellite-nav)
  • Re: Storing Tilemaps/Drawing Tilemaps
    ... > half of my tiles were empty - so this was a huge waste of memory. ... oldest chunk from memory and read it off disk. ...
    (comp.games.development.programming.misc)