[geotk] Efficient subsetting/subsampling of large image
Martin Desruisseaux
martin.desruisseaux at geomatys.fr
Mon Sep 28 11:33:25 EDT 2009
Hello Jon
Jon Blower a écrit :
> Is it possible to use Geotoolkit to read a subset of pixels from a
> large image without reading the entire image into memory? Such
> behaviour would be very useful for a Web Map Service implementation.
If you are reading a single image, you can do that using the standard Java API
defined in the javax.imageio package. The example below read 1 pixel, skip 2,
read 1 pixel, etc.
ImageReader reader = ImageIO.getImageReaders(input).next();
reader.setInput(input);
ImageReadParam param = reader.getDefaultReadParam();
param.setSourceSubsampling(3, 3, 0, 0);
RenderedImage image = reader.read(0, image);
Note that you can also set a subarea of the region you want to read, or read
only some bands using other setter methods in ImageReadParam.
If you want to do the same but on a mosaic of images instead than a single
image, you can do that using the org.geotoolkit.image.io.mosaic package. The
steps are:
1) Create one Tile object for each image.
2) Instantiate a new MosaicImageReader object.
3) Invoke reader.setInput(input) where the input is the array of
tiles created at step 1.
4) Use the standard Java API exactly as you would do for the single
image case. MosaicImageReader will take care of reading only the
needed images.
Martin
More information about the Geotoolkit
mailing list