1

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

我通过使用该方法创建PlanarImage并遍历每个像素来读取图像。image.getData().getPixel(x,y,arr)

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

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

4

2 回答 2

1

从 JavaDoc 的PlanarImage.getData()

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

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

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

尝试:

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
            }
        }
    }
} 
于 2013-06-12T11:41:38.820 回答
0

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

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

于 2013-06-12T11:20:21.730 回答