convert changes pixel colors unexpectedly

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
pipitas
Posts: 168
Joined: 2012-07-15T14:06:46-07:00
Authentication code: 15

convert changes pixel colors unexpectedly

Post 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:".
User avatar
glennrp
Posts: 1147
Joined: 2006-04-01T08:16:32-07:00
Location: Maryland 39.26.30N 76.16.01W

Re: convert changes pixel colors unexpectedly

Post 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.
SummerTerry
Posts: 1
Joined: 2012-09-24T09:09:01-07:00
Authentication code: 67789

Re: convert changes pixel colors unexpectedly

Post by SummerTerry »

Thanks for the answer...
I haven't still solved the problem,
but I think I'll cope with it now.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: convert changes pixel colors unexpectedly

Post by Bonzo »

In your case I would check the image size first and only run it through IM if it needs resizing.
Post Reply