21

I have to write an application for image processing in python. Does anyone know how to convert the file type of an image from JPEG to TIFF?

1
  • Did you try to use PIL ? It can support many image file format. Commented Jun 21, 2012 at 11:27

3 Answers 3

32

Check out the Python Image Library (PIL). See this tutorial, the PIL is quite easy to use.

Supported image formats.

To do the conversion you open the image and then save it with the new extension (which PIL uses to determine what format to use for saving).

import Image
im = Image.open('test.jpg')
im.save('test.tiff')  # or 'test.tif'

Note that the official distribution does not support Python 3.x (yet?), however, at least under Windows there's an unofficial version available that works with v 3.x.

Sign up to request clarification or add additional context in comments.

2 Comments

The original PIL project has been forked and ported to Python 3: Pillow.
For python3 after installing pillow it's from PIL import Image
15

Use the Python Imaging Library (PIL).

from PIL import Image
img = Image.open('image.jpeg')
img.save('image.tiff')

Ref: http://effbot.org/imagingbook/image.htm

1 Comment

Use img.convert() before saving to avoid any errors in file conversion
0

I generally use OpenCV (cv2) to convert them like:

import os
import cv2

path = r"D:\Folder"
i=0
for x in os.listdir(path):
    image = cv2.imread(r"{}\{}".format(path,x))
    cv2.imwrite(r'{}\{}.png'.format(path,i),image)
    i+=1

(replace png with whatever extension you want, in your case .tiff)

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.