tags:

views:

570

answers:

6
+1  Q: 

Tiff Analyzer

I am writing a program to convert some data, mainly a bunch of Tiff images. Some of the Tiffs seems to have a minor problem with them. They show up fine in some viewers (Irfanview, client's old system) but not in others (Client's new system, Window's picture and fax viewer). I have manually looked at the binary data and all the tags seem ok. Can anyone recommend an app that can analyze it and tell me what, if anything, is wrong with it?

Also, for clarity sake, I'm only converting the data about the images which is stored seperately in a database and copying the images, I'm not editting the images myself, so I'm pretty sure I'm not messing them up.

UDPATE: For anyone interested, here are the tags from a good and bad file:

BAD
Tag Type Length Value
256 Image Width SHORT 1 1652
257 Image Length SHORT 1 704
258 Bits Per Sample SHORT 1 1
259 Compression SHORT 1 4
262 Photometric SHORT 1 0
266 Fill Order SHORT 1 1
273 Strip Offsets LONG 1 210 (d2 Hex)
274 Orientation SHORT 1 3
277 Samples Per Pixel SHORT 1 1
278 Rows Per Strip SHORT 1 450
279 Strip Byte Counts LONG 1 7264 (1c60 Hex)
282 X Resolution RATIONAL 1 <194> 200 / 1 = 200.000
283 Y Resolution RATIONAL 1 <202> 200 / 1 = 200.000
284 Planar Configuration SHORT 1 1
296 Resolution Unit SHORT 1 2

Good
Tag Type Length Value
254 New Subfile Type LONG 1 0 (0 Hex)
256 Image Width SHORT 1 1193
257 Image Length SHORT 1 788
258 Bits Per Sample SHORT 1 1
259 Compression SHORT 1 4
262 Photometric SHORT 1 0
266 Fill Order SHORT 1 1
270 Image Description ASCII 45 256
273 Strip Offsets LONG 1 1118 (45e Hex)
274 Orientation SHORT 1 1
277 Samples Per Pixel SHORT 1 1
278 Rows Per Strip LONG 1 788 (314 Hex)
279 Strip Byte Counts LONG 1 496 (1f0 Hex)
280 Min Sample Value SHORT 1 0
281 Max Sample Value SHORT 1 1
282 X Resolution RATIONAL 1 <301> 200 / 1 = 200.000
283 Y Resolution RATIONAL 1 <309> 200 / 1 = 200.000
284 Planar Configuration SHORT 1 1
293 Group 4 Options LONG 1 0 (0 Hex)
296 Resolution Unit SHORT 1 2

A: 

Worth giving ImageMagick a go. My understanding is that TIFF is a rather complex file format, and that not everyone implements the format fully.

Dave Gamble
A: 

LibTIFF might be helpful. Problems viewing Tiff's are often caused by the compression used. I'd look into that.

Jim Blizard
+1  A: 

Usually that's because the tiff is using the JPEG encoding from the 6.0 standard, which was abandoned shortly afterward. Look at tag 259. If it is 6, that is the problem. JPEGs should be encoded with the "newer" scheme, 7. Standard libraries will not read the old one, including the ones that come with Windows.

You can use libtiff (or any of the libraries or programs that use libtiff, most of them do) to read these, but scheme 6 (OJPEG) is deliberately disabled by default in libtiff. You will have to patch and recompile libtiff to enable it. Here's a link with instructions.

R Ubben
Tag 259 is 4 (adding words to meet minimum comment length requirement...sigh)
Kevin
Is the width of the image on the problematic ones divisible by 8? Group 4 compression is supposed to support it, but not everyone does...
R Ubben
Nope, it is 1652. See update in main question text
Kevin
That's odd. For the bad image, the origin is the lower right-hand corner, but that's usually ignored. Also, the good image is in a single strip, but the bad one is in two. Is there a second 273 tag in the bad image?
R Ubben
No, there is not a second 273 tag
Kevin
Well, if the image length is 704, and the rows per strip is 450, there should be a second strip, and a second 273 giving an offset to it, right? When IrfanView (love that program) displays it, how many rows is it showing?
R Ubben
A: 

TIFF is a very complex format - not only in the richness of the data it can encode (various pixel format, various encoders) - but also because of the richness of the file format itself (its a general structure that can hold anything). It's basically trash dump for every idea we've ever had in imaging. :-)

I would highly recommend the WPF Imaging library from .NET 3.0. Its Tiff decoder, while not supporting all pixel formats, it very robust and has an easy interface for accessing all the meta data.

Frank Krueger
+1  A: 

You can try my free tifftool file analyzer. It allows you to see the details of all the tags (and multiple pages).

http://www.bitbanksoftware.com/private/tifftool.zip

I've written a pretty comprehensive imaging library and what I've found is that many other TIFF viewers (e.g. Microsoft's) don't handle default values properly (e.g. unspecified tags), nor do they handle all possible compression types, bit directions and so forth. Also, as it appears with your image, strips don't always get handled properly by some viewers.

Let me know if I can be of assistance.

Larry B.

BitBank
Upvoted for the tiff too.. :) AWESOME! :D
krebstar
A: 

The RowsPerStrip in the bad image is 450, which is less than 704, the image length (height). This implies the image must have two strips. Because of this, StripOffsets and StripByteCounts must both have a count of two. These indicates the file offsets where the strip data is located. When these offsets are missing, only the first strip will be decodeable.

Ryan Wong