3

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.

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
Arijit Roy
  • 41
  • 1
  • 3

2 Answers2

5

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...

Kurt Pfeifle
  • 86,724
  • 23
  • 248
  • 345
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

enter image description here

001_2.tif

enter image description here

001_3.tif

enter image description here

you will get this in merged_001.tif

enter image description here

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

enter image description here

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

Mark Setchell
  • 191,897
  • 31
  • 273
  • 432
  • Thanks Mark.It worked with slight variation -adjoin instead of -append to get multi-page tif image.But it took me ~30 sec to process.I have tested on Windows 7- Intel(R) core(TM) i3 CPU 550 @3.20 GHZ ,Ram 4 GB.My file sizes are ..1.tf-> ~270 KB, ..2.tf-> ~16 KB, ..3.tif->10 KB.Is there any workaround to achieve this within 5-10 second ? Your feedback is appreciated. – Arijit Roy Jun 04 '15 at 11:53
  • 1
    You can try pre-pending `start /b` in front of `convert` so that the 200 `convert` processes run in parallel - not sure how well windows will handle that though - maybe experiment with 4 parallel converts initially. Or maybe add a parameter to the script of `start` and `end` number, then run one with `1-50` a second with `51-100` and so on all 4 in parallel. – Mark Setchell Jun 04 '15 at 12:09