General Computing
images conversion jpeg tiff
Updated Sat, 18 Jun 2022 12:37:16 GMT

How can multiple image TIFF files be converted to JPEG files?

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


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

Comments (3)

  • +1 – What language is this? — Dec 02, 2009 at 04: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. — Dec 02, 2009 at 21:24  
  • +0 – @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. — Dec 02, 2009 at 21:35