Tiff Image Reader/writer

P

PyPK

Hi I am looking for a simple tiff Image reader/writer in python.Can
anyone point me to the right one.
 
D

Dan Sommers

Hi I am looking for a simple tiff Image reader/writer in python.Can
anyone point me to the right one.

I don't know what your definition of "simple" is, but check out the
Python Imaging Library (PIL) at effbot.org.

Regards,
Dan
 
P

PyPK

Is there any package out there which handles Tiff Images other than PIL
or ImageMagic .
 
P

PyPK

nothing fancy. I just want to be able to read a tiff image, get pixel
values, write back to a tiff file.
 
R

Robert Kern

PyPK said:
nothing fancy. I just want to be able to read a tiff image, get pixel
values, write back to a tiff file.

[An aside: please quote the message you are replying to.]

Why doesn't the PIL satisfy this need? Or are you just collecting a list
of packages with this capability?

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
P

PyPK

One reason why I don't want to use PIL is it seems very slow for tiff
images of very large sizes(2400x4800). So I am looking for a better
tool than does the right job faster.
 
R

Robert Kern

PyPK said:
One reason why I don't want to use PIL is it seems very slow for tiff
images of very large sizes(2400x4800). So I am looking for a better
tool than does the right job faster.

This isn't fast enough?

In [8]: %time img2 = Image.open('foo.tiff')
CPU times: user 0.00 s, sys: 0.01 s, total: 0.01 s
Wall time: 0.03

In [9]: img2.size
Out[9]: (2400, 4800)

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
P

PyPK

When i try this i get this error:

import ImageTraceback (most recent call last):
File "<stdin>", line 1, in ?
File "Image.py", line 858, in getpixel
self.load()
File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line
180, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "Image.py", line 328, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder group4 not available
 
F

Fredrik Lundh

PyPK said:
nothing fancy. I just want to be able to read a tiff image, get pixel
values, write back to a tiff file.

so why doesn't PIL or ImageMagick work for you?

here's a minimal PIL version:

from PIL import Image

im = Image.open("myfile.tiff")
value = im.getpixel((12, 34))
im.save("other.tiff")

</F>
 
P

PyPK

I get a decoder error when i do a get pixel on the Image

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "Image.py", line 858, in getpixel
self.load()
File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line
180, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "Image.py", line 328, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder group4 not available
 
J

James Carroll

Hmm... that's unfortunate.

What platform are you on? If Windows, then I believe that PIL is
statically linked against LibTIFF and that particular libtiff wasn't
compiled with certain options (CCITT formats or something.) (in 1999
that was true, I found a post from Fred here:
http://mail.python.org/pipermail/image-sig/1999-June/000755.html)

If it's a one-time thing, there are ways of converting the TIFF to a
different encoding. I use the libtiff tifftools command tiffcp:

tiffcp -c none infile.tif out file.tif

which will decode into a non-compressed tiff.

Otherwise, you might be out of luck (or have to change some of the
libtiff options.)

If you put your tiff file somewhere where I can download it, I'll try
reading it with the alternatives that I have on my system and let you
know what works...

-Jim
 
F

Fredrik Lundh

PyPK said:
I get a decoder error when i do a get pixel on the Image


Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "Image.py", line 858, in getpixel
self.load()
File "/usr/local/lib/python2.4/site-packages/PIL/ImageFile.py", line
180, in load
d = Image._getdecoder(self.mode, d, a, self.decoderconfig)
File "Image.py", line 328, in _getdecoder
raise IOError("decoder %s not available" % decoder_name)
IOError: decoder group4 not available

PIL doesn't support CCITT encodings out of the box. the following
patch might help:

http://mail.python.org/pipermail/image-sig/2003-July/002354.html

(unfortunately, this currently depends on libtiff internals, which is
why it wasn't added to 1.1.5)

an alternative solution is to pipe your files through tiffcp (see James
mail for details).

</F>
 
M

Marc 'BlackJack' Rintsch

Robert Kern said:
PyPK said:
One reason why I don't want to use PIL is it seems very slow for tiff
images of very large sizes(2400x4800). So I am looking for a better
tool than does the right job faster.

This isn't fast enough?

In [8]: %time img2 = Image.open('foo.tiff')
CPU times: user 0.00 s, sys: 0.01 s, total: 0.01 s
Wall time: 0.03

In [9]: img2.size
Out[9]: (2400, 4800)

It's fast enough to open the file and read the meta-data. The OP wants to
decode the actual pixels.

Ciao,
Marc 'BlackJack' Rintsch
 
R

Robert Kern

Marc said:
Robert Kern said:
PyPK said:
One reason why I don't want to use PIL is it seems very slow for tiff
images of very large sizes(2400x4800). So I am looking for a better
tool than does the right job faster.

This isn't fast enough?

In [8]: %time img2 = Image.open('foo.tiff')
CPU times: user 0.00 s, sys: 0.01 s, total: 0.01 s
Wall time: 0.03

In [9]: img2.size
Out[9]: (2400, 4800)

It's fast enough to open the file and read the meta-data. The OP wants to
decode the actual pixels.

Okay.

In [12]: %time d = img.getdata()
CPU times: user 0.31 s, sys: 1.43 s, total: 1.73 s
Wall time: 6.19

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
J

James Carroll

What do you mean by decode the pixels? If there's some image
processing that needs to be done, or if you want to view, brighten, or
print or something, then there are ways of doing it that will be as
fast as can be. If stepping through the pixels to do your own math
is what you want, then maybe something that puts the pixels in
numarray / scipy / etc. form is what would work for you.

Reading a large image is going to take some time no matter what
language or tool you use... How long does it take a viewer program to
open and display your tiff image?

How fast is the following for your image? (you'll need wxPython)

import wx

wx.InitAllImageHandlers()


# time the following line
image = wx.Image('yourfilename.tif')
print "the image is %ix%i" % (image.GetWidth(), image.GetHeight())
print "the greenness pixel at 10,10 is", image.GetGreen(10,10)

wxWidgets uses libtiff directly, so it will be about as fast as can
be, but wxWidgets does assume that the image is RGB for most
operations.

The Kitware ITK (Insight Toolkit) can read lots of variations of
multi-tiff images, and do tons of different kinds of manipulation on
them... the only downside is its footprint and learning curve.


-Jim

Robert Kern said:
PyPK said:
One reason why I don't want to use PIL is it seems very slow for tiff
images of very large sizes(2400x4800). So I am looking for a better
tool than does the right job faster.

This isn't fast enough?

In [8]: %time img2 = Image.open('foo.tiff')
CPU times: user 0.00 s, sys: 0.01 s, total: 0.01 s
Wall time: 0.03

In [9]: img2.size
Out[9]: (2400, 4800)

It's fast enough to open the file and read the meta-data. The OP wants to
decode the actual pixels.

Ciao,
Marc 'BlackJack' Rintsch
 
R

Robert Kern

Robert said:
Marc 'BlackJack' Rintsch wrote:
It's fast enough to open the file and read the meta-data. The OP wants to
decode the actual pixels.

Okay.

In [12]: %time d = img.getdata()
CPU times: user 0.31 s, sys: 1.43 s, total: 1.73 s
Wall time: 6.19

And for comparison:

In [2]: f = open('foo.tiff')

In [3]: %time s = f.read()
CPU times: user 0.04 s, sys: 0.28 s, total: 0.32 s
Wall time: 2.40

Of course, it's all a moot point since the OP actually has a different
problem with PIL, not its speed.

--
Robert Kern
(e-mail address removed)

"In the fields of hell where the grass grows high
Are the graves of dreams allowed to die."
-- Richard Harter
 
J

James Carroll

I did a test with wxPython 2.6.1 on Windows. I created a G4 TIFF
image that was 4400 x 3599 big, and the following code took under a
half second.

import wx
import time

def readImage(filename):
img = wx.Image(filename)
w = img.GetWidth()
h = img.GetHeight()
value = img.GetGreen(w - 10, h - 10)
return value

image = "D:\\horizLines1g4.tif"

t0 = time.clock()
value = readImage(image)
print time.clock() - t0, "seconds process time"
print "The value in the lower right hand corner is %i" % value


This prints:
0.488175452467 seconds process time
The value in the lower right hand corner is 255

so it is treating it as RGB, but I bet that's not a problem.

-Jim
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
474,007
Messages
2,570,266
Members
46,864
Latest member
DaniEbswor

Latest Threads

Top