Converting TIF image twice produces different image files

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
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Converting TIF image twice produces different image files

Post by rmagick »

Below is a script that takes an input TIFF image and does a "no-op" conversion to TIFF. It then takes the output image and performs the same conversion. It does this 10 times. Each output image file is slightly different, having a different signature, different number of colors, different IPTC profile, etc.

Is this caused by some inherent property of TIFF or am I overlooking something?

Code: Select all

#! /bin/bash 

COUNTER=0
INPUT=input
while [ $COUNTER -lt 10 ]
do
	convert ${INPUT}.tif output${COUNTER}.tif
	md5 output${COUNTER}.tif
	INPUT=output${COUNTER}
	COUNTER=`expr $COUNTER + 1`
done
If it makes a difference I can supply the input image. I'm running my tests with
Version: ImageMagick 6.3.1 12/11/06 Q16 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2007 ImageMagick Studio LLC
on OS X 10.4.8
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Post a URL to your image. In our test we did get a different MD5 but that can be expected since some internal data may change each time the TIFF is written. However we used the compare program and in our tests each output image was exactly the same on a pixel-by-pixel basis.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Test image

Post by rmagick »

Thanks for your help! Here's the input image.

http://rubyforge.org/tracker/download.p ... /input.tif
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Post by rmagick »

Were you able to get to the image I referred to in the previous post?
User avatar
magick
Site Admin
Posts: 11064
Joined: 2003-05-31T11:32:55-07:00

Post by magick »

Your image is JPEG compressed which is a lossy compression algorithm. Some differences are expected when saving images with JPEG compression. Add -compress lzw to your command line and the compare program returns a MSE of 0 as expected for each iteration.
rmagick
Posts: 245
Joined: 2006-03-16T17:30:48-07:00
Location: Durham, NC, USA

Post by rmagick »

Thanks! I knew it was something peculiar to the image.
User avatar
anthony
Posts: 8883
Joined: 2004-05-31T19:27:03-07:00
Authentication code: 8675308
Location: Brisbane, Australia

Post by anthony »

Also as JPG compression was used, loading and saving multiple times using that compression would degrad the image. Best to avoid it if you can, though it will be a lot larger.
Anthony Thyssen -- Webmaster for ImageMagick Example Pages
https://imagemagick.org/Usage/
Post Reply