473,378 Members | 1,099 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,378 software developers and data experts.

Tiff Image Reader/writer

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
17 9946
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
Is there any package out there which handles Tiff Images other than PIL
or ImageMagic .

Jul 19 '05 #3
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
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
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
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
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
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
"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
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
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
"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
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
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
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Nicolas Guilhot | last post by:
Hi all ! I have a multi-page Tiff image file that I want to convert to PDF. To do so I am using iText library. The conversion is working, but the code execution is very different according to...
0
by: E-Cube | last post by:
Hello all, I am attempting to save a bitmap image and saving it as a tiff image with CCITT4 compression using the folllowing code. oEncoderParameters = New Imaging.EncoderParameters(1) oEncoder...
2
by: S.Creek | last post by:
Hi, I need to take few files (images in my case) and create one file out of them, this file should be accessed so i can grab a single image from it if necessary, i thought of taking all the...
2
by: Al Reid | last post by:
Is it possible to display an image that is stored on the server as a TIFF image, on an ASP.Net page without the use of an add-in viewer? If so, could someone tell me how to do it? TIA -- Al...
5
by: Shane Story | last post by:
I can seem to get the dimensions of a frame in a multiframe tiff. After selecting activeframe, the Width/Height is still really much larger than the page's actual dimensions. When I split a...
6
by: qysbc | last post by:
I have a web page and there is a link to open a TIFF file. The way I do it is to have the server code open a binary stream, set the content type to "image/tiff" and call Response.BinaryWrite. On...
1
by: Stedak | last post by:
I have the following class I use to save Tiff's. The problem I have with it is that the final size of the images are very large. If we scan directly to a file the final tiff may be 600-900 kb.s but...
7
by: Ben | last post by:
Hi We are looking for a component that offers that offers the below for Tiff files: Image clean-up (deskew, despeckle) Printing capabilities from VB The ability to add text to image, e.g....
10
by: =?Utf-8?B?UmludSBHb3BhbGFrcmlzaG5hIFBpbGxhaQ==?= | last post by:
Hi, Please help me to write a dll in C# , that will read each pages of a tiff image from a file and a memory stream object ( need two ways) and creatre a new tiff image object.The dll should...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.