Page 1 of 1

Why is convert reducing quality when PNG -> PNG

Posted: 2014-11-14T01:05:12-07:00
by freyja
When I convert PNG to PNG, the quality is reduced (I can see it visually and also OCR output quality is greatly reduced):

Code: Select all

convert Fontanes.png Fontanes.output.png
Here is the input:
http://www.cs.put.poznan.pl/ekowalczuk/Fontanes.png
and result:
http://www.cs.put.poznan.pl/ekowalczuk/ ... output.png

Using

Code: Select all

identify
I see that the types of pictures differ:

Code: Select all

Fontanes.png PNG 825x73 825x73+0+0 8-bit DirectClass 62.9KB 0.000u 0:00.000
Fontanes.output.png[1] PNG 825x73 825x73+0+0 8-bit PseudoClass 256c 37.7KB 0.000u 0:00.000
...
Colorspace: sRGB
Colorspace: Grey
I don't understand why the picture is altered at all.

Of course I don't need to convert PNG to PNG, but I believe this behaviour affects what happens in JMagick code. When I feed bytes extracted in IM the OCR output quality is worse than when feeding it with bytes read for example from ImageIO.

I want to support many different formats, so I cannot use ImageIO for this purpose.

I will appreciate any remarks on this. Thanks!

Re: Why is convert reducing quality when PNG -> PNG

Posted: 2014-11-14T01:38:36-07:00
by snibgo
I think you are using an old version of IM, when it converted grayscale to linear.

What does "convert -version" say? If older than 6.8.8, I suggest you upgrade.

Re: Why is convert reducing quality when PNG -> PNG

Posted: 2014-11-14T01:39:34-07:00
by rich2005
Not comparing like-with-like

Original is RGB, converted file is greyscale.

Try convert in.png png24:out.png

Re: Why is convert reducing quality when PNG -> PNG

Posted: 2014-11-14T03:56:47-07:00
by pipitas
My version of convert (6.8.9-8 Q16 x86_64 2014-10-03) does not exhibit this problem. I did run:

Code: Select all

convert Fontanes.png Fontanes.output2.png 

compare Fontanes.png Fontanes.output2.png -compose src delta.png
The resulting delta.png does not show a single red pixel.

Re: Why is convert reducing quality when PNG -> PNG

Posted: 2014-11-14T08:51:49-07:00
by freyja
Thank you for such quick answers.

Indeed upgrading the version to 6.8.9-8 helped for console case, but it caused JMagick to behave strangely (MagickImage constructor using byte[] returns 0-size image and blobToImage method hangs).

It might be so that IM and JMagick versions have to match exactly.
The newest JMagick I could found was 6.7.7 (complied from repository).
I will try to ask on JMagick mailing list about it.

Update:
JMagick developer confirmed that versions of IM and JMagick have to match exactly. If they match I don't get an empty picture when using the constructor, but a proper one. Method blobToImage hangs indifferently in both IM version, but I don't need it when constructor works.