ImageMagick: how to batch combine multiple TIFF file to a single TIFF file in a directory?

ぃ、小莉子 提交于 2019-12-02 00:56:55

问题


I have 600 TIFF files in a directory, c:\temp.

The file names are like:

001_1.tif,
001_2.tif,
001_3.tif

002_1.tif,
002_2.tif,
002_3.tif
....
....
200_1.tif,
200_2.tif,
200_3.tif

The combined files should be placed in same directory and the files should be named like:

1_merged.tif
2_merged.tif
.....
.....
200_merged.tif

I am looking for any single command-line /batch-file to do so through ImageMagick convert/ mogrify command or any other command/tools.

Please note the overall time taken should not be more than 5 second.


回答1:


Assuming you want to combine the 600 single-page TIFFs into one single multi-page TIFF (per set of 3), it is as simple as:

 convert  001_*.tiff  1_merged.tiff
 convert  002_*.tiff  2_merged.tiff
 [....]
 convert  200_*.tiff  200_merged.tiff

Please note that nobody will be able to guarantee any timing/performance benchmarks... least while we don't even have any idea how exactly your input TIFFs are constituted. (Are they 10000x10000 pixels or are they 20x20 pixels?, Are they color or grayscale?, etc.pp.)

This is different from Mark's answer, because he seems to have assumed you want to combine the input files all into a 1-page image, where the originals are tiled across a larger page...




回答2:


This should do it - I will leave you to do error checking in case you haven't actually got all the images you suggest!

@ECHO OFF
setlocal EnableDelayedExpansion
FOR /L %%A IN (1,1,200) DO (
   set "formattedValue=000000%%A"
   set "x=!formattedValue:~-3!"
   convert !x!_*.tif +append !x!_merged.tif
   echo !x!
)

So, if your images look like this

001_1.tif

001_2.tif

001_3.tif

you will get this in merged_001.tif

If you change +append to -append then merged_001.tif will be like this:

If you remove +append altogether, you will get 200 multi-page TIFs with 3 pages each - same as Kurt's answer.



来源:https://stackoverflow.com/questions/30619858/imagemagick-how-to-batch-combine-multiple-tiff-file-to-a-single-tiff-file-in-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!