使用节点锐利(libvips)附加图像

时间:2015-07-13 17:11:59

标签: node.js image vips

我想使用VIPS将许多较小图像的目录附加到一个大图像中。节点模块" sharp"使用libvips。有没有办法使用sharp将2张图像附加在一起? VIPS有一个" LRJOIN"功能,但我没有看到它的明确实施。

我真的只知道让VIPS将图像目录附加到一个大TIFF的最快方法。由于内存问题,图像太大而无法使用ImageMagick等。

编辑:

我使用ruby-vips加入图像并调用VIPS命令行工具来生成DZI。

#!/usr/bin/ruby

require 'rubygems'
require 'vips'

a = VIPS::Image.new(ARGV[1])
ARGV[2..-1].each {|name| a = a.tbjoin(VIPS::Image.tiff(name, :compression => :deflated))}                              
a.write("output.tiff", :compression => :deflated)

system("vips dzsave output.tiff '#{ARGV[0]}'/output_dz.zip --overlap=0 --suffix=.jpg")

我在ruby-sharp github问题上找到了代码并对其进行了一些修改。 550 4096x256图像的结果(仅加入部分):

real    0m17.283s
user    0m47.045s
sys     0m2.139s

1 个答案:

答案 0 :(得分:0)

如果Ruby或Python没问题,你可以尝试一下。例如:

#!/usr/bin/python

import sys
from gi.repository import Vips

if len(sys.argv) < 3:
    print("usage: join outfile in1 in2 in3 ...")
    sys.exit(1)

def imopen(filename):
    return Vips.Image.new_from_file(filename,
                                    access = Vips.Access.SEQUENTIAL_UNBUFFERED)

acc = imopen(sys.argv[2])
for infile in sys.argv[3:]:
    acc = acc.join(imopen(infile), Vips.Direction.HORIZONTAL,
                   align = "centre",
                   expand = True,
                   shim = 50,
                   background = 255)

acc.write_to_file(sys.argv[1])

加入100个2000x2500 rgb tif图像需要1GB的内存和30s左右的桌面:

$ time ../join.py x.tif *.tif
real    0m36.255s
user    0m8.344s
sys 0m3.396s
$ vipsheader x.tif 
x.tif: 204950x2500 uchar, 3 bands, srgb, tiffload

大部分时间显然花在光盘IO上。

相关问题