Page 1 of 1

convert changes pixel colors unexpectedly

Posted: 2012-09-21T06:14:55-07:00
by pipitas
I've come across this question on Stackoverflow.com: What I'm now wondering about:
  • Why is ImageMagick applying some subtle color changes to pixels even when you simply run

    Code: Select all

    convert  in.jpg  out.jpg
    ?
  • Are there any command line params which would allow to really get an unchanged image from above command?
The original question came from someone who ran

Code: Select all

convert                               \
   http://i.stack.imgur.com/N9h0q.jpg \
  -thumbnail 200x200\>                \
   thumb.jpg
and discovered a different file size as the result, thinking a different compression scheme had been applied. In reality only some pixels (about 18% of them) had their colors changed by a very small amount, as can easily be verified by running "compare http://i.stack.imgur.com/N9h0q.jpg thumb.jpg show:".

Re: convert changes pixel colors unexpectedly

Posted: 2012-09-21T06:53:10-07:00
by glennrp
JPEG is lossy. Subtle changes are unavoidable when you decompress and recompress.

"convert in.jpg out.jpg" might be lossless if "in.jpg" was created with the same version of
ImageMagick and libjpeg. ImageMagick attempts to use the same "quality" and "sampling-factors" that
were used to create the input file.

The "jpegtran" application that comes with libjpeg can do lossless conversions provided that no scaling
is involved; it avoids the decompress/recompress operation.

If you must have exact lossless conversions you should be using a lossless format such as PNG or TIFF.

Re: convert changes pixel colors unexpectedly

Posted: 2012-09-24T09:12:07-07:00
by SummerTerry
Thanks for the answer...
I haven't still solved the problem,
but I think I'll cope with it now.

Re: convert changes pixel colors unexpectedly

Posted: 2012-09-24T09:21:11-07:00
by Bonzo
In your case I would check the image size first and only run it through IM if it needs resizing.