TIF to PNG to TIF is not the same input as output

Questions and postings pertaining to the usage of ImageMagick regardless of the interface. This includes the command-line utilities, as well as the C and C++ APIs. Usage questions are like "How do I use ImageMagick to create drop shadows?".
Post Reply
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

TIF to PNG to TIF is not the same input as output

Post by jaffamuffin »

Hi All

What I expect to be able to do is store an uncompressed TIF as a losslessly compressed PNG, and be able to convert the PNG back to TIF and have the same image as before. But it doesn't seem to be the case. Can anyone explain what is happening and how I may achieve my goal ? Thanks

Code: Select all

W:\png_tif>convert 000025_orig.tif 25.png
W:\png_tif>convert 25.png -strip 25_png_strip.tif
W:\png_tif>convert 000025_orig.tif -strip 25_tif_strip.tif

W:\png_tif>md5sums 25_tif_strip.tif
25_tif_strip.tif                                     3755906e7bed98db95ccc0106e461b6c

W:\png_tif>md5sums 25_png_strip.tif
25_png_strip.tif                               924c9de42959ebefc7b61ba75f848ee0

W:\png_tif>compare 25_tif_strip.tif 25_png_strip.tif diff.png
The source image is a scanned page of Text in 8bpp gray.
The last command a compare shows a feint version of the page, like someone upped the brightness of the original scan, which shows that the image data is different, and not just the file data.

Any thoughts ?

im version Version: ImageMagick 6.9.1-2 Q8 x64 2015-04-14 http://www.imagemagick.org Win 7
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: TIF to PNG to TIF is not the same input as output

Post by fmw42 »

try adding -compress none when converting a tiff.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: TIF to PNG to TIF is not the same input as output

Post by snibgo »

md5sums will find differences in metadata as well as the image.

Please put 000025_orig.tif somewhere like dropbox.com and paste the URL here.
snibgo's IM pages: im.snibgo.com
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: TIF to PNG to TIF is not the same input as output

Post by glennrp »

snibgo wrote:md5sums will find differences in metadata as well as the image.
Right. Use

Code: Select all

 identify -verbose file.tif | grep ignature
to find out if the image data is the same. But OP said the result was lighter, which sounds to me like a problem with RGB (linear) versus sRGB (gamma) colorspace. I don't think "-compress none" is likely to help.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: TIF to PNG to TIF is not the same input as output

Post by snibgo »

Yes. A possible cause is 000025_orig.tif isn't sRGB and contains correct metadata, so converting to sRGB 25.png works fine, and converting that to 25_png_strip.tif also works fine. But reading 000025_orig.tif them immediately "-strip" removes the metadata, so it won't get converted to sRGB correctly.

But that's just a guess. We need to see the file 000025_orig.tif.
snibgo's IM pages: im.snibgo.com
jaffamuffin
Posts: 59
Joined: 2009-01-30T03:46:08-07:00

Re: TIF to PNG to TIF is not the same input as output

Post by jaffamuffin »

https://www.dropbox.com/sh/p0gjpa7k5x7t ... GdyZa?dl=0

Hi Guys Thanks for your replies. See the above dropbox link for the files. Interesting about the RGB data, I haven't yet had a chance to test any further yet, but the files are there if you want to have a look.

The idea was to be able to store TIF images in a more efficient way, but still be able to veiw/work with them etc and restore them to the original TIF if required. Is converting to PNG a reasonable approach to this ? An added benefit is web browsers can view png natively which does come in handy.
snibgo
Posts: 12159
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: TIF to PNG to TIF is not the same input as output

Post by snibgo »

jaffamuffin wrote:The last command a compare shows a feint version of the page, like someone upped the brightness of the original scan, which shows that the image data is different, and not just the file data.
The output image of "compare" shows differences in red, over a very grayed version. You are seeing the very grayed version.

It may be easier to use a specific metric:

Code: Select all

f:\web\im\samples2>%IM%compare -metric AE 25_tif_strip.tif 25_png_strip.tif d.png
0
How many pixels are different? Zero.

Aside: tiff files can be compressed in various ways, if you want. I generally use "-compress Zip".
snibgo's IM pages: im.snibgo.com
Post Reply