How can multiple image TIFF files be converted to JPEG files?
Solution 1
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
Solution 2
IrfanView has excellent batch processing abilities.
IrfanView also supports command line operations
i_view32.exe c:\myimages\*.tif /convert=c:\images\*.jpg
Here's the link to Command line manual
Solution 3
Try convert
or mogrify
using ImageMagick. More instructions from ubuntuforums.org.
Solution 4
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"
Related videos on Youtube
Peter Mortensen
Updated on September 17, 2022Comments
-
Peter Mortensen over 1 year
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:
-
glallen almost 12 yearsGlad it worked!
-
glallen almost 12 yearsYou 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
-
-
Peter Mortensen over 14 yearsThat looks promising. I will give it a try.
-
Michael Todd over 14 yearsWhat language is this?
-
Michael Todd over 14 yearsThe dialog is a little busy, but batch processing in IrfanView is powerful and pretty fast.
-
Peter Mortensen over 14 yearsThat 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 over 14 yearsThis 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?
-
100rabh over 14 years@Peter: IrfanView does support command-line parameters
-
Peter Mortensen over 14 yearsI 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 over 14 years@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.