开发者

slicing up a very big jpg map image , 49000* 34300 pixel

开发者 https://www.devze.com 2022-12-27 05:47 出处:网络
i want to write a mapviewer, i must to work small tile of big map image file and there is need to tiling the big image, the problem now is to tiling big image to small tiles (250 * 250 pixel or like t

i want to write a mapviewer, i must to work small tile of big map image file and there is need to tiling the big image, the problem now is to tiling big image to small tiles (250 * 250 pixel or like this size) so on, i used ImageMagic program to do it but there was problem now开发者_如何学Go is any other programing method or application that do tiling? can i do it with JAI in java? how?


Have you tried doing it in java yourself? I tried this with (WARNING, big image, can crash your browser, use "save as...") this image. Needed to run with extra memory though (-Xmx400M).

public class ImageTile {
    public static void main(String[] args) throws IOException {
        Dimension tileDim = new Dimension(250, 250);
        BufferedImage image = ImageIO.read(new File(args[0]));

        Dimension imageDim = new Dimension(image.getWidth(), image.getHeight());

        for(int y = 0; y < imageDim.height; y += tileDim.height) {
            for(int x = 0; x < imageDim.width; x += tileDim.width) {

                int w = Math.min(x + tileDim.width,  imageDim.width)  - x;
                int h = Math.min(y + tileDim.height, imageDim.height) - y;

                BufferedImage tile = image.getSubimage(x, y, w, h);
                ImageIO.write(tile, "JPG", new File("tile-"+x+"-"+y+".jpg")); 
            }
        }
    }
}


For the large images sizes like you have, you will be best served with lossless editing of the JPEG files. Not only is this faster, since the image doesn't need to be rendered, but it also preserves quality, since the image is not recompressed.

Lossless editing works on blocks, typically 16px square. While restrictive for some applications, this seems a good fit for mapping. You could implement tiling at different zoom levels by first losslessly cropping the image to sized pieces. (This is quick an efficient since the image is not rendered.) This gives you tiles for full-zoom. To create lower-levels of zoom, combine 2x2 tiles and scale these down to the size of 1 tile. The next level uses 4x4 tiles, and 8x8 and so on, each time scaling down to one tile. At some point when the number of tiles beecomes too large, you can choose to use zoomed tiles as the base resource. For example, at zoom level 8, that would require 256x256 tiles. This might be too much to handle, so you could use 16x16 tiles from zoom level 4.

Wikipedia has more on lossless editing, and links to some implementing libraries.


imagemagick does tiling using -tile. It's more of a repitition of an image, but might be useful esp. since youre already using it. However If you mean generated seamless tiling I'm not sure if imagemagick can do that or not.


GDAL comes with a script called gdal2tiles.py that does exactly what you want, including formatting the tiles for use with Google Maps, OpenLayers, etc.

There seems to be an newer version of GDAL2Tiles as well.


How about a megatexture with an r-tree for efficient access? Apparently it can use images 128000x128000 pixels.


JAI is platform dependent and seems like a dead project today.

I advise using the open-source program imagemagick. Although it is platform dependent, it is available for the same platforms as JAI, but with full community support.

The trick about large images about imagemagick is using its "stream"-command instead of the convert command. Stream only reads the relevant portion of the image and saves the extracted part as raw data. You then need "convert" to save the small raw data as jpeg.

Example to save a tile from large.jpeg of size 800x600 from position 0x0 to tile.jpeg:

    stream -extract 800x600+0+0 large.jpeg tile.rgb

    convert -depth 8 -size 800x600 rgb:tile.rgb tile.jpeg

(When running on windows, be sure to use ImageMagick's convert.exe, as there is a windows command named "convert".)

When working with TIFF-images only, apache Sanselan could be the right choice - it is a pure-java imaging lib. Also, JAI seems to contain a platform independent codec for TIFF.

0

精彩评论

暂无评论...
验证码 换一张
取 消