我有一张大Tiff图像,想要将其切割成512x512个瓷砖并写入磁盘。
过去我使用过ImageMagick,如下所示:
convert -crop 512x512 +repage image_in.tif image_out_%d.tif
但最近这个方法已经不起作用了,进程会因为内存不足而停止等问题。
在VIPS中是否有类似的命令?我知道它有一个CLI,但是我在文档中找不到例子或有用的解释,而且我还在努力弄清楚nip2 GUI的事情。感谢任何帮助。 :)
我有一张大Tiff图像,想要将其切割成512x512个瓷砖并写入磁盘。
过去我使用过ImageMagick,如下所示:
convert -crop 512x512 +repage image_in.tif image_out_%d.tif
libvips有一个操作符可以帮助您快速完成这项任务。尝试使用以下命令:
$ vips dzsave wtc.tif outdir --depth one --tile-size 512 --overlap 0 --suffix .tif
那是 DeepZoom writer 制作 tif 瓦片深度为 1 的金字塔。请查看 outdir_files/0
中的输出瓦片。有一个关于如何使用 dzsave 的文档章节。
对我来说比 IM 快得多:
$ time convert -crop 512x512 +repage huge.tif x/image_out_%d.tif
real 0m5.623s
user 0m2.060s
sys 0m2.148s
$ time vips dzsave huge.tif x --depth one --tile-size 512 --overlap 0 --suffix .tif
real 0m1.643s
user 0m1.668s
sys 0m1.000s
其中huge.tif
是一个10000×10000像素的未压缩RGB图像。此外,它可以在很少的内存中处理任何大小的图像。
for x in xrange(0, tiles_per_row):
xoffset = x * tile_size
for y in xrange(0, tiles_per_row):
yoffset = y * tile_size
filename = "%d_%d_%d.png" % (zoom, x, y)
command = "vips im_extract_area %s %s %d %d %d %d" % (base_image_name, filename, xoffset, yoffset, tile_size, tile_size)
os.system(command)
然而,您将无法获得与imagemagick裁剪相同的速度...
column_row.tif
,这是你的意思吗? - jcupitt