[Image-SIG] PIL is corrupting/inverting TIFF images
Larry Bates
lbates@syscononline.com
Sat, 13 Oct 2001 12:24:42 -0500
I am attempting to write a program that allows me to "annotate" TIFF images.
I need to be able to read a TIFF image, add textual information to it and
save it back out to a file as a G4 compressed image. I have located
a program (NetPBM) that will take TIFF images and compress them as
G4 images. I have written the following test program:
--------------------
import os, tempfile, sys
# install standard driver
from PIL import Image
#
# Open and read the file
#
im = Image.open("c:\\SPC\\test.tif")
#
# Save it out
#
im.save("c:\\spc\\tempfile.tif", "TIFF")
#
# Call external program to save as compressed TIFF
#
os.system("c:\\NetPBM\\bin\\tiffcp -c g4 %s %s" % (infile,
"c:\\spc\\output.tif"))
-----------------------------------
This program runs, but when if completes the contents of the output file
(c:\spc\output.tif) are inverted. Everything that should be black is white
and everything that is white is black.
I ran NetPBM's TIFFINFO routine and see the following output on
the intermediate file (tempfile.tif) and the final output file (output.tif)
C:\spc>tiffinfo test.tif
TIFF Directory at offset 0x101024
Subfile Type: (0 = 0x0)
Image Width: 2550 Image Length: 3300
Resolution: 300, 300 pixels/inch
Bits/Sample: 1
Compression Scheme: None
Photometric Interpretation: min-is-white
Software: "Pixel Translations Inc., PIXTIFF Version 54.3.218.468"
Orientation: row 0 top, col 0 lhs
Samples/Pixel: 1
Rows/Strip: 3300
Planar Configuration: single image plane
C:\spc>tiffinfo tempfile.tif
TIFF Directory at offset 0x8
Image Width: 2550 Image Length: 3300
Compression Scheme: None
Photometric Interpretation: min-is-black
Rows/Strip: 3300
Planar Configuration: single image plane
C:\spc>tiffinfo output.tif
TIFF Directory at offset 0xc8c4
Image Width: 2550 Image Length: 3300
Compression Scheme: CCITT Group 4
Photometric Interpretation: min-is-black
Rows/Strip: 25
Planar Configuration: single image plane
As you can see the output from the im.save has changed
the Photometric Interpretation to min-is-black (inverted??).
The thing I don't understand is that if I open this file in a
viewing program (Windows Imaging) it doesn't show up
as inverted is shows up just fine (which is why this
problem hasn't been discovered yet). It is only when I
compress the file that it becomes inverted. If I use TIFFCP
to compress test.tif directly (without going through PIL
Image module), it works just fine. PIL Image module is
doing something to the image.
If I use TIFFCP to compress tempfile.tif to packbits it is NOT
inverted (when I open in Windows Imaging), but
Photometric Interpretation is min-is-black when I check
with TIFFINFO.
HELP, I have no idea what to try next.
Regards,
Larry Bates