Problem with quality of the color gradient

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
Mathematica
Posts: 5
Joined: 2012-06-23T13:32:13-07:00
Authentication code: 13

Problem with quality of the color gradient

Post by Mathematica »

Hello. Excuse me for my English first.
I'm new to IM and I'm trying to convert pages from a PDF document (created with LaTeX) to PNG using ImageMagick.

My command line is :

convert -density 559 -units PixelsPerInch Exercice.pdf -resize 25% Exercice.png

Original PDF file is here : http://ppl.ug/2m59bTWWpmQ/
and the created PNG file is here : http://ppl.ug/ZbdKS14Nh1E/

As you can see, there is a quality problem with the color gradient on the top of the PNG file : I have some colored rectangles from red to orange ... I think there is not enough colors to have a "pretty" color gradient (as the PDF document). I hope to be clear enough.

I'm using IM 6.5.2-0 on a Mac with OS X Snow Leopard.
Thanks for your help.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with quality of the color gradient

Post by fmw42 »

I downloaded your two images and used your command to convert the pdf using IM 6.7.7.9 Q16 Mac OSX Snow Leopard. I opened them all in Mac Preview.

My result looks just like your result and they both look perfectly fine to me compared to the pdf original. I see no artifacts or coarse gradient changes. The gradient looks very smooth to me in all cases. PNG certainly can contain sufficient colors if not converted to palette color (256 colors).

The only issue I had was an error or warning message from IM

convert -density 559 -units PixelsPerInch Exercice.pdf -resize 25% Exercice.png
**** Warning: considering '0000000000 XXXXX n' as a free entry.
**** Warning: considering '0000000000 XXXXX n' as a free entry.

**** This file had errors that were repaired or ignored.
**** The file was produced by:
**** >>>> Mac OS X 10.6.8 Quartz PDFContext <<<<
**** Please notify the author of the software that produced this
**** file that it does not conform to Adobe's published PDF
**** specification.

The verbose information from IM show it is truecolor and not palette so everything looks good to me:

Image: Exercice.png
Format: PNG (Portable Network Graphics)
Class: DirectClass
Geometry: 880x495+0+0
Resolution: 220.08x220.08
Print size: 3.99855x2.24918
Units: PixelsPerCentimeter
Type: TrueColorAlpha
Endianess: Undefined
Colorspace: sRGB
Depth: 16-bit
Channel depth:
red: 16-bit
green: 16-bit
blue: 16-bit
alpha: 16-bit

The image is 16-bits per channel color and it does have a 16-bit alpha channel.



Perhaps it is the image viewer you were using to look at them. Perhaps it cannot display 16-bit color or converts your alpha channel to binary. Are you running Q8 version of IM?
Mathematica
Posts: 5
Joined: 2012-06-23T13:32:13-07:00
Authentication code: 13

Re: Problem with quality of the color gradient

Post by Mathematica »

Thanks a lot for your answer.
I use Preview to look at the PDF source file and Preview again to look at the PNG created file. I note that the color gradient is OK on the PDF
document (the color gradient looks very smooth) but it's not so good with the PNG file.

A make a screen capture of the PDF file :

Image

and another of the PNG file created with IM :

Image

I can see the difference between the two images in this forum too (not only in the Preview App).

Currently, I use IM 6.5.2-0 that was installed on Snow Leopard. Sorry but I don't know what Q8 or Q16 means ...
As you advice, I tried to install IM 6.7.7-8 on my Mac. I dowloaded in $HOME and then :

cd $HOME
tar xvfz ImageMagick-x86_64-apple-darwin11.4.0.tar.gz
export MAGICK_HOME="$HOME/ImageMagick-6.7.7"
export PATH="$MAGICK_HOME/bin:$PATH"
export DYLD_LIBRARY_PATH="$MAGICK_HOME/lib/"
convert logo: logo.gif

I had this message :

Referenced from: .../ImageMagick-6.7.7/bin/convert
Reason: Incompatible library version: convert requires version 10.0.0 or later, but libltdl.7.dylib provides version 9.0.0
Trace/BPT trap

I suppose there is a problem with libraries because Snow Leopard is running Darwin 10.8.0 and the compiled IM version I downloaded
is named "ImageMagick-x86_64-apple-darwin11.4.0.tar.gz". I tried too find a xxx-darwin10.8.0 file on the ftp server, but I didn't find.

Thanks again.
Last edited by Mathematica on 2012-06-24T08:30:07-07:00, edited 1 time in total.
Bonzo
Posts: 2971
Joined: 2006-05-20T08:08:19-07:00
Location: Cambridge, England

Re: Problem with quality of the color gradient

Post by Bonzo »

If I open the two images above and magnify them using Windows picture viewer I can see vertical bands on the SCapture-IM-PNG.png image about the width of a letter.
Once you notice it at that magnification you seem to see it at smaller magnifications as well.
Mathematica
Posts: 5
Joined: 2012-06-23T13:32:13-07:00
Authentication code: 13

Re: Problem with quality of the color gradient

Post by Mathematica »

I tried some other tests with IM Studio online (I think it's a newer version than mine), and I always got the same PB with vertical bands ...

Image

So I think my problem could be the PDF file ... Is there some options for a PDF source file to add in the command line ?

Moreover, I tried to export my PDF file with Pixelmator on my Mac and I got this :

Image

Verticals bands seem to have disappeared ... I really don't know what to do now.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with quality of the color gradient

Post by fmw42 »

I have processed your pdf to png in IM 6.7.7.9 Q16 (hdri) Mac OSX SnowLeopard and zoomed it and do not see any banding. Perhaps it is my old eyes. But there have been quite a few changes to IM with regard to colorspace since 6.7.5.5. Perhaps you should try upgrading. Or perhaps your libpng needs upgrading. I am using

convert -list format
...
PNG* PNG rw- Portable Network Graphics (libpng 1.4.11)
Mathematica
Posts: 5
Joined: 2012-06-23T13:32:13-07:00
Authentication code: 13

Re: Problem with quality of the color gradient

Post by Mathematica »

Thanks a lot for your answer ! After extensive testing, I think I have determined the source of my gradient problem.
I think it comes from the png logo included in the PDF created by LaTeX ...

I changed the logo (png file) which is at the bottom of the PDF. I used a logo with no alpha channel and ...
the problem of gradient disappeared. You can see the result here :
Image

and the result with the logo using alpha channel (there are some vertical bands in the gradient) :
Image

I must say I've tried other versions of IM as IM on OS X Lion (libpng 1.5.2) or IM Studio, always with
the same result (I mean there's a gradient problem if I use my PNG logo with alpha channel and no gradient
problem if I use my PNG logo without alpha channel).

I guess I have to use some command-line option ...

Thanks again.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with quality of the color gradient

Post by fmw42 »

IM uses Ghostscript to convert the pdf. But there are two PS sDevices that can be used in the delegates.xml file. Using pngalpha allows the pdf to maintain the alpha channel but won't properly process multiple PDF pages. Using pnmraw, will not handle alpha channels in the PDF, but will process multiple PDF pages. Check your delegates.xml file and see which is being used. In my case, I was using pngalpha.

So it could also be your version of Ghostscript. My version is 9.05.
Mathematica
Posts: 5
Joined: 2012-06-23T13:32:13-07:00
Authentication code: 13

Re: Problem with quality of the color gradient

Post by Mathematica »

Thanks a lot for your answer.
I checked my delegates.xml file and I found these lines :

<delegate decode="pdf" encode="eps" mode="bi" ..... -sDEVICE=epswrite" "-sOutputFile=%o" "-f%i""/>
<delegate decode="pdf" encode="ps" mode="bi" ..... -sDEVICE=pswrite" "-sOutputFile=%o" "-f%i""/>
.
.
.
<delegate decode="ps" encode="eps" ..... -sDEVICE=epswrite" "-sOutputFile=%o" "-f%i""/>
<delegate decode="ps" encode="pdf" ..... -sDEVICE=pdfwrite" "-sOutputFile=%o" "-f%i""/>
<delegate decode="ps:alpha" stealth="True" ..... -sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u ..... />
<delegate decode="ps:cmyk" stealth="True" ..... -sDEVICE=pam" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u ..... />
<delegate decode="ps:color" stealth="True" ..... -sDEVICE=pnmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u ..... />
<delegate decode="ps:mono" stealth="True" ..... -sDEVICE=pbmraw" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u ..... />

in IM 6.5.2 and IM 6.7.7 too. The entire file can be found here :

http://ppl.ug/TSFtHKbtJyE/

I suppose the interesting lines are those which contain "ps:alpha" and "ps:color" (even though my file is a PDF file). Should I modify my delegates.xml file to use the pngalpha sDEVICE or can I choose this sDEVICE in the command line ? Actually my command line is

convert -density 559 -units PixelsPerInch Exercice.pdf -resize 25% Exercice.png

Exercice.pdf is a unique PDF page (in fact, I tried a document with multiple pdf pages

convert -density 559 -units PixelsPerInch Exercices.pdf[num] -resize 25% Exercice-num.png %%% (num is the page number I want to convert)

or unique pdf page and I have not seen any difference).
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: Problem with quality of the color gradient

Post by fmw42 »

<delegate decode="ps:alpha" stealth="True" ..... -sDEVICE=pngalpha" -dTextAlphaBits=%u -dGraphicsAlphaBits=%u ..... />
If your image has alpha in it then this is correct. If not then pnmraw would work. I don't know too much more, except as far as I know, you have to edit the delegates.xml file. I don't know of any command line switching. The IM developers would have to comment.
Post Reply