3

I've got two tiff stacks with time-lapse data corresponding to different channels acquired in a microscopy experiment. I'd like to merge them into a single stack with two channels. Both stacks are 16-bit greyscale.

When I use:

convert stack1.tiff stack2.tiff stack_merged.tiff

I get a single but concatenated file with two stacks one after another.

Links to file 1 and file 2.

mattek
  • 903
  • 1
  • 6
  • 18
  • Not sure about your term *"stack"*? Does a "stack" hold multiple images of, say, the Red channel at different times and another "stack" hold, say, the Green channel at the same times? Can you provide samples? – Mark Setchell Nov 16 '16 at 16:15
  • Does this give you what you want for the first image? `convert stack1.tiff[0] stack2.tiff[0] -channel RG -combine result.tif` – Mark Setchell Nov 16 '16 at 16:18
  • @MarkSetchell Yes, a stack contains multiple images recorded in one colour channel at different time points. I edited the question to include sample files. The suggested code produces 3 channels with one time point, which is not what I'm after. – mattek Nov 16 '16 at 16:28

1 Answers1

2

I think you need something like this:

#!/bin/bash

# Get index of last frame in TIFF image
last=$(convert stack1.tif -print "%[fx:n-1]" null:)

# Combine all frames
for i in `seq 0 $last`; do
   convert stack1.tif[$i] stack2.tif[$i] -combine miff:-
done | convert miff:- -compress lzw result.tif
Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • 1
    Almost there, except it creates RGB channels. In there any way to restrict the conversion to 2 channels? convert -channel RG ... still produces all 3 channels, with the last one empty. – mattek Nov 16 '16 at 16:44
  • I have improved my original answer a little bit - more flexible in terms of number of images in stack and compressed output file, but am still trying to work out how to do a 2-channel image... – Mark Setchell Nov 16 '16 at 16:57
  • I see. This might be the mother of all my problems. I'll try playing with command-line tools from Bio-Formats then. Many thanks for your effort anyway! – mattek Nov 16 '16 at 17:14