Stitching TIF tiles into large image

Is there a command under Linux that can do this?

I personally am not aware of a single command to do what you want.

I tried it with the montage command (part of Imagemagick), but it seems to support only tilesets where each row / column has the same number of tiles.

I don't know if this would be a solution for you, but you could (theoretically) generate the missing images beforehand, then simply include them in the montage command.

For your example image, assuming you had e.g. slice_1_1.tif to slice_1_6.tif for the first row, slice_2_1.tif to slice_2_6.tif for the second row, etc., you could generate "blank" images with something like the following:

magick -size 120x85 canvas:white slice_1_1.tif
magick -size 70x85 canvas:white slice_1_6.tif
magick -size 70x85 canvas:white slice_2_6.tif
magick -size 120x85 canvas:white slice_5_5.tif
magick -size 70x85 canvas:white slice_5_6.tif

You would, of course, need to use the correct sizes for your actual images. You could then run montage as normal:

magick montage *.tif -tile 6x5 -geometry +0+0 example.tif

which would give you something like:

Example TIF

Assuming there weren't any other considerations, I think the toughest part here would (potentially) be automating the "missing" image generation (assuming you needed to do that for some reason).


ImageMagick References

  • Solid Color Canvases

  • Montage