By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,627 Members | 1,211 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,627 IT Pros & Developers. It's quick & easy.

Tiff Image Reader/writer

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

Jul 19 '05 #1
Share this Question
Share on Google+
17 Replies


P: n/a
On 13 Jun 2005 07:55:04 -0700,
"PyPK" <su*******@gmail.com> wrote:
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

--
Dan Sommers
<http://www.tombstonezero.net/dan/>
Jul 19 '05 #2

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

Jul 19 '05 #3

P: n/a
What sort of things do you want to do with the TIFFs? How
heavy-weight or light-weight are you interested in? For heavy-weight
there are:

- wxPython will do a bunch of tiff reading, and some image processing
http://www.wxpython.org

- GDAL
(quoting Khalid Zuberi:)
GDAL supports GeoTIFF and includes python bindings:

http://www.remotesensing.org/gdal/
- ITK Insight Toolkit from Kitware (wicked heavy-weight)
http://www.itk.org

-Jim

On 13 Jun 2005 12:50:48 -0700, PyPK <su*******@gmail.com> wrote: Is there any package out there which handles Tiff Images other than PIL
or ImageMagic .

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #4

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

Jul 19 '05 #5

P: n/a
PyPK wrote:
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
rk***@ucsd.edu

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

Jul 19 '05 #6

P: n/a
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.

Jul 19 '05 #7

P: n/a
PyPK wrote:
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
rk***@ucsd.edu

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

Jul 19 '05 #8

P: n/a
When i try this i get this error:

import Image
im = Image.open('image.tif')
im.getpixel((10,19))

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

Jul 19 '05 #9

P: n/a
"PyPK" wrote:
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>

Jul 19 '05 #10

P: n/a
I get a decoder error when i do a get pixel on the Image
im.getpixel((12,34))


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

Jul 19 '05 #11

P: n/a
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/ima...ne/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

On 14 Jun 2005 05:25:46 -0700, PyPK <su*******@gmail.com> wrote:
I get a decoder error when i do a get pixel on the Image
im.getpixel((12,34))


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

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #12

P: n/a
"PyPK" <su*******@gmail.com> wrote:
I get a decoder error when i do a get pixel on the Image
im.getpixel((12,34))


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/ima...ly/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>

Jul 19 '05 #13

P: n/a
In <ma**************************************@python.o rg>, Robert Kern
wrote:
PyPK wrote:
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
Jul 19 '05 #14

P: n/a
Marc 'BlackJack' Rintsch wrote:
In <ma**************************************@python.o rg>, Robert Kern
wrote:
PyPK wrote:
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
rk***@ucsd.edu

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

Jul 19 '05 #15

P: n/a
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

On 6/15/05, Marc 'BlackJack' Rintsch <bj****@gmx.net> wrote:
In <ma**************************************@python.o rg>, Robert Kern
wrote:
PyPK wrote:
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
--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #16

P: n/a
Robert Kern wrote:
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
rk***@ucsd.edu

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

Jul 19 '05 #17

P: n/a
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


On 14 Jun 2005 05:25:46 -0700, PyPK <su*******@gmail.com> wrote:
I get a decoder error when i do a get pixel on the Image
im.getpixel((12,34))


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

--
http://mail.python.org/mailman/listinfo/python-list

Jul 19 '05 #18

This discussion thread is closed

Replies have been disabled for this discussion.