在java中读取大型tiff图像的最快方法是什么?

时间:2013-06-12 11:14:33

标签: java image-processing gis tiff jai

我目前使用 JAI库来读取tiff图像,但它是非常慢的大tiff图像(我需要使用大小约为1GB的卫星图像)。 我需要从tiff图像中读取每个点的高度,然后相应地对其进行着色。

我正在通过创建PlanarImage并使用image.getData().getPixel(x,y,arr)方法迭代每个像素来阅读图像。

建议我更好地实施解决方案。

编辑: 我找到了错误。我正在通过调用for循环中的image.getData()方法为每个像素创建一个新的图像栅格。只创建一次栅格然后在循环中使用其getPixel()函数解决了我的问题

2 个答案:

答案 0 :(得分:0)

1 GB压缩图像加载到内存时可能大约为20 GB +。在Java中处理此问题的唯一方法是使用非常大的堆空间加载它。

您正在处理非常大的图像,最简单的方法是使用更快的PC。我建议使用超频的i7 3960X,价格合理http://www.cpubenchmark.net/high_end_cpus.html

答案 1 :(得分:0)

来自PlanarImage.getData()的JavaDoc:

  

返回的Raster在语义上是一个副本。

这意味着对于图像的每个像素,您都在内存中创建整个图像的副本......这无法提供良好的性能。

使用getTile(x, y)getTiles()应该更快。

尝试:

PlanarImage image;

final int tilesX = image.getNumXTiles();
final int tilesY = image.getNumYTiles();

int[] arr = null;

for (int ty = image.getMinTileY(); ty < tilesY; ty++) {
    for (int tx = startX; tx < image.getMinTileX(); tx++) {
        Raster tile = image.getTile(tx, ty);
        final int w = tile.getWidth();
        final int h = tile.getHeight();

        for (int y = tile.getMinY(); y < h; y++) {
            for (int x = tile.getMinX(); x < w; x++) {
                arr = tile.getPixel(x, y, arr);
                // do stuff with arr
            }
        }
    }
} 
相关问题