How can multiple image TIFF files be converted to JPEG files in a batch manner?

Update 1: convert on Linux (part of ImageMagick) as suggested by Miss Cellanie and glallen worked. It was straightforward. I downloaded the ISO image of the netbook version of Kubuntu 9.1, burned it onto a DVD, restarted, started a command-line window, changed current directory to where inter2.tif was and typed:

    convert -separate inter2.tif new_inter2.jpeg

This created the 3 expected images, new_inter2-0.jpeg, new_inter2-1.jpeg and new_inter2-2.jpeg. Some error messages were displayed:

convert: incorrect count for field "DateTime" (21, expecting 20); tag trimmed. `inter2.tif' @ tiff.c/TIFFWarnings/526.
convert: inter2.tif: unknown field with tag 317 (0x13d) encountered. `TIFFReadDirectory' @ tiff.c/TIFFWarnings/526.
convert: inter2.tif: unknown field with tag 33628 (0x835c) encountered. `TIFFReadDirectory' @ tiff.c/TIFFWarnings/526.

I have a lot of microscopy images of cells. They are in the TIFF format, one TIFF file per sample/cell picture and 3 channels/images in each TIFF file (3 different light wavelengths).

The TIFF files need to be converted to JPEG files in a batch manner (user intervention should not be required), 3 JPEG files for each TIFF file (corresponding to the 3 wavelengths).

I have tried to use the command-line tool tiffsplit that is included with LibTIFF to do the first step, extracting the 3 images from the original TIFF to 3 new TIFF files. But it crashes with the TIFF files I have (on Windows XP 64 bit, DEP enabled). The error message is:

Unhandled exception at 0x6fd853d1 in tiffsplit.exe: 0xC0000005: Access violation writing location 0x6fdc8ddb

Do you know of another solution? Either on Windows or Linux.

Here is a sample TIFF file (3.8 MB). Composite image (single JPEG file made by importing in MS Paint and saving as JPEG) to give you an impression of what it is:

alt text

  • Glad it worked! – glallen Jun 20 '12 at 16:11
  • You may also want to look at the perl bindings for imagemagic. You can automate anything imagemagic can do and build entire toolchains for conversion, annotation or extraction of IPTC/EXIF data, resize, channel separation, etc... imagemagick.org/script/perl-magick.php – glallen Jun 20 '12 at 16:17

There's probably a slightly more elegant way, but this should do it for you:

for FILE in $(ls *.tif); do \
    for I in R G B; do \
       convert -channel $I -separate -format jpg $FILE $FILE-$I.jpg ; \
    done ; \
done ; \ 
rename s/\.tif\-/\-/ *.jpg
  • 1
    What language is this? – Michael Todd Dec 2 '09 at 4:31
  • 1
    It's bash shell on linux. The "-channel $I -separate" inside the for loop will generate separate files for each R G B component like you wanted. I downloaded your image and tried it, then added the for loop so you could run it inside a whole directory. After you run the rename command you end up with your original inter2.tif and inter2-R.jpg inter2-G.jpg and inter2-B.jpg. – glallen Dec 2 '09 at 21:24
  • @glallen: Thanks. It is good to know that it actually works with the type of images I have. I may decide to use this route. – Peter Mortensen Dec 2 '09 at 21:35

IrfanView has excellent batch processing abilities.

Irfan View

IrfanView also supports command line operations

i_view32.exe c:\myimages\*.tif /convert=c:\images\*.jpg

Here's the link to Command line manual

  • The dialog is a little busy, but batch processing in IrfanView is powerful and pretty fast. – Michael Todd Dec 2 '09 at 4:32
  • That seems like an excellent way for exploration and for semi-automatic conversion. But would I always need to start IrfanWiew and bring up this dialog? Or can it done using command-line parameters or using some scripting? – Peter Mortensen Dec 2 '09 at 10:00
  • @Peter: IrfanView does support command-line parameters – Sathyajith Bhat Dec 2 '09 at 12:00
  • I have downloaded and installed IrfanView. But "/extract" is not working as documented using the sample TIFF file. It saves only one JPEG file (a composite). Perhaps IrfanView can not handle this kind of TIFF file. I have tried with ImageJ and it can do the split (but this is from the user interface.) – Peter Mortensen Dec 2 '09 at 15:38

Try convert or mogrify using ImageMagick. More instructions from ubuntuforums.org.

  • That looks promising. I will give it a try. – Peter Mortensen Dec 1 '09 at 23:57

Besides the excellent separate tools from ImageMagick, there is also this simple command line tool called img2img which has the ImageMagick convert component bundled into it. It supports tons of formats and can autodetect input formats. You can batch convert like so (be sure to run this in the directory with all of the .tiff files):

for /f "delims=." %x in ('dir /b *.tiff') do img2img "%x.tiff" "%x.jpeg"
  • This will produce the composite image. I have tried to use the "-deconstruct" option but img2img does not seem to recognise any of the options that it lists if run without parameters. Do you have some examples of img2img invocations with options/parameters? – Peter Mortensen Dec 2 '09 at 12:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.