8

I am working with 1gb large tiff images of around 20000 x 20000 pixels. I need to extract several tiles (of about 300x300 pixels) out of the images, in random positions.

I tried the following solutions:

  • Libtiff (the only low level library I could find) offers TIFFReadline() but that means reading in around 19700 unnecesary pixels.

  • I implemented my own tiff reader which extracts a tile out of the image without reading in unnecesary pixels. I expected it to be faster, but doing a seekg for every line of the tile makes it very slow. I also tried reading to a buffer all the lines of the file that include my tile, and then extracting the tile from the buffer, but results are more or less the same.

I'd like to receive suggestions that would improve my tile extraction tool!

Everything is welcome, maybe you can propose a more efficient library I could use, some tips about C/C++ I/O, some higher level strategy for my needs, etc.

Regards, Juan

4

5 回答 5

3

[主要编辑 2010 年 1 月 14 日]

当 tiff 没有平铺时,我对您提到的瓷砖感到有些困惑。

我确实使用平铺/金字塔 TIFF 图像。我用 VIPS 创建了那些

vips im_vips2tiff source_image output_image.tif:none,tile:256x256,pyramid

我认为你可以这样做:

vips im_vips2tiff source_image output_image.tif:none,tile:256x256,flat

您可能想尝试使用磁贴大小。然后您可以使用 TIFFReadEncodedTile 进行阅读。

如果您需要放大/缩小,使用金字塔形 tiff 的多分辨率存储要快得多。您可能还想使用它来获得几乎紧跟详细图片的粗略图像。

在切换到(适当大小的)平铺存储(这将为随机访问带来巨大的性能改进!)之后,您的瓶颈将是磁盘 io。如果按顺序读取,文件读取会快得多。这里映射可能是解决方案。

一些有用的链接:

VIPS IIPImage LibTiff.NET stackoverflow VIPS 是一个图像处理库,它可以做的不仅仅是读/写。它有自己的、非常有效的内部格式。它对算法有很好的文档。一方面,它将处理与文件系统分离,从而允许缓存切片。

IIPImage 是一个多缩放网络服务器/浏览器库。我发现文档是关于多分辨率成像的非常好的信息来源(如谷歌地图)

此页面上的另一个解决方案使用 mmap,仅对“小”文件有效。我经常触及 32 位边界。通常,在 32 位操作系统(安装了 4 GBytes RAM)上分配 1 GB 的内存块会失败,因为即使虚拟内存在运行一两个应用程序后也会碎片化。尽管如此,仍有足够的内存来缓存部分或整个图像。更多内存 = 更多性能。

于 2010-01-04T20:41:29.753 回答
2

只需 mmap 您的文件。

http://www.kernel.org/doc/man-pages/online/pages/man2/mmap.2.html

于 2009-10-30T22:09:41.257 回答
2

感谢大家的回复。

实际上,需要更改拼贴的方式,使我能够以顺序而不是随机的方式从硬盘中的文件中提取拼贴。这使我可以将文件的一部分加载到 ram 中,并从那里提取图块。

效率提升是巨大的。否则,如果您需要随机访问文件,mmap 是一个不错的选择。

问候,胡安

于 2010-04-21T08:07:09.093 回答
0

我做了类似的事情来处理任意大的 TARGA(TGA) 格式文件。使这种文件变得简单的事情是图像没有被压缩。您可以计算图像中任意像素的位置,并通过简单的搜索找到它。如果您可以选择指定图像编码,则可以考虑使用 targa 格式。

如果不是,则有多种 TIFF 格式。如果他们已经经历了支持所有不同格式的痛苦,您可能想要使用库。

于 2010-01-04T20:51:55.787 回答
-1

您是否收到特定的错误消息?根据您使用该命令行的方式,您可能一直在踩自己的文件。

如果这不是问题,请尝试使用 imagemagick 而不是 vips(如果可以的话)。

于 2010-11-08T20:26:03.953 回答