question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Merging multipages TIF files into a single multipage TIF

See original GitHub issue

I have 8 different multipage TIF stacks which I would like to merge into a single TIF stack in order to have an easier way to extrapolate the data I need from each image. I’ve been trying to use the arrayjoin method by loading each TIF stack as a list element, but in this way I believe that only a single image of each stack would be taken to create the new TIF stack. Is there an easier way to do this? Overall all the stacks are up to 30 GB big, and loading them in RAM to merge them one by one doesn’t seem particularly convenient.

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:27 (16 by maintainers)

github_iconTop GitHub Comments

1reaction
jcupittcommented, Oct 21, 2021

I think there’s some confusion over terminology, here’s a summary:

  • format – The numeric type of a pixel. Yours are unsigned 16-bit integers, I think.
  • slice – A width by height array of pixels. libtiff calls these pages, since in a TIFF container each one is stored as a separate page. Slices only have one band, ie. they are a single uint16 number for each pixel, they are not eg. RGB. Also called frames.
  • stack – An ordered list of slices with identical width, height and format. libtiff stores these as a multi-page image, with each page being one slice.
  • toilet-roll libvips represents a whole stack as a very tall, thin image with an attached metadata item called page-height which gives the vertical height of each slice. Number of slices times page-height is always exactly toilet-roll image height.
  • pyramid – For fast viewing, formats like OME-TIFF store reduced-resolution versions of large images. These extra layers get smaller in powers of two, usually down to eg. a 256 x 256 final image.
  • subifd – TIFF images are arranged in directories, one directory per page. The directory lists all the image tags (small items of metadata). One tag is called SUBIFD and is a pointer to a list of private subdirectories for this directory. OME-TIFF uses these private subdirectories to hold the extra pyramid layers for each page.
  • tile – Large images are stored as a set of tiles, each usually 256 x 256 pixels, plus an index. You don’t need to think about this, though you will see references to tile-width and tile-height in TIFF load and save.
  • image-description – This is a TIFF tag (of string type) which in OME-TIFF holds XML describing the overall structure of thie TIFF file.
1reaction
jcupittcommented, Oct 20, 2021

Oh wait, I’ve found a bug, the page-height argument in tiffsave isn’t handled correctly, sorry.

As a workaround, set page-height in the image metadata instead. Try this:

final_image.set_type(pyvips.GValue.gint_type, "page-height", 2048))
final_image.write_to_file(final_stack_filename, subifd=True)
Read more comments on GitHub >

github_iconTop Results From Across the Web

converting multiple tiff files into one - Microsoft Community
Enter the same filename, choose TIFF Multipaged (*.tif) and check Append to file, then click Save. Now open the Excel spreadsheet and click...
Read more >
Combine TIFF Files Into One: Best Software - Windows Report
Click File > Merge Files. · Choose Add Files to choose the images to include within the multipage TIFF. · Select a folder...
Read more >
How to merge multiple TIFF files to a ... - Advanced TIFF Editor
Method 1. ... On the File menu, click Merge Files. You'll see Merge Files dialog window. ... Click Add Files to add your...
Read more >
TIFF Merger online - Aspose Products
Merge TIFF files in order you want. Modern free online conversion tool is created to fast join multiple files into a single document....
Read more >
How to merge multiple TIFF files to a single multi-page image?
Method 1. By this method, you can merge TIFF files and arrange order according to your needs. On the File menu, click Merge...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found