0

I want to use VIPS to append a directory of many smaller images in to one massive image. The node module "sharp" uses libvips. Is there any way to use sharp to append 2 images together? VIPS has a "LRJOIN" function but I don't see a sharp implementation of it.

I really just to know the fastest possible way to have VIPS append a directory of images to one big TIFF. The image is too big to use ImageMagick etc. because of memory issues.

Edit:

I used ruby-vips to join the images and call the VIPS command line tool to generate the 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")

I found the code on a ruby-sharp github issue and modified it a bit. The results (just the joining part) for 550 4096x256 images:

real    0m17.283s
user    0m47.045s
sys     0m2.139s
jcupitt
  • 10,213
  • 2
  • 23
  • 39
JHawk
  • 11
  • 3
  • https://github.com/lovell/sharp/blob/master/CONTRIBUTING.md#submit-a-new-feature-request or even better https://github.com/lovell/sharp/blob/master/CONTRIBUTING.md#submit-a-pull-request-with-a-new-feature :) – Lovell Fuller Jul 13 '15 at 21:42
  • Just wanted to make sure I wasn't missing anything! I ended up using ruby-vips to make a tiff and dzi. Sharp is great though, I'm very interested in running it on AWS Lambda. – JHawk Jul 16 '15 at 02:57
  • Re: AWS Lambda, there are some suggestions for how to compile the required static library at https://github.com/lovell/sharp/issues/169 – Lovell Fuller Jul 16 '15 at 09:36

1 Answers1

0

If Ruby or Python are OK, you could try them. For example:

#!/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])

Joining 100 2000x2500 rgb tif images needs 1gb of memory and 30s or so on this desktop:

$ 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

Most of the time is obviously spent in disc IO.

jcupitt
  • 10,213
  • 2
  • 23
  • 39
  • I had trouble getting the python binding working on Amazon Linux so I used Ruby. Interesting that yours spent so much time in IO. – JHawk Jul 16 '15 at 03:00
  • It's a mechanical HDD and the data wasn't in cache. If I run the command a second time it's only 3s I think. – jcupitt Jul 16 '15 at 13:18