convert and gs results difference

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
wwubcn
Posts: 4
Joined: 2019-10-07T23:47:32+00:00
Authentication code: 1152

convert and gs results difference

Post by wwubcn »

Hello,

I'm doing a OCR project and currently i'm using convert command to convert pdf to jpg.

Due to some reason, i have to use ghostscript now.

From what i see, the image quality from gs is much better.

However, seems OCR has better result from convert command result.

convert result
https://cl.ly/48d7aa1a6ced

gs result
https://cl.ly/eaeb7b32df1e

I wonder what causes this difference. And if i have to use gs now, how could i get similar result as convert?

Commands I use
> convert -quality 100 ~/sample.pdf jpgs/a-%02d.jpg
> gs -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=1 -dGridFitTT=2 "-sDEVICE=png16m" "-r72x72" -sOutputFile=./jpgs/a-%02d.jpg ~/sample.pdf

Thank you very much
User avatar
fmw42
Posts: 25562
Joined: 2007-07-03T00:14:51+00:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert and gs results difference

Post by fmw42 »

ImageMagick uses Ghostscript to process PDF. The only issue would be what arguments are set in the delegates.xml file for reading PS/PDF/etc.
wwubcn
Posts: 4
Joined: 2019-10-07T23:47:32+00:00
Authentication code: 1152

Re: convert and gs results difference

Post by wwubcn »

fmw42 wrote: 2019-10-08T00:31:19+00:00 ImageMagick uses Ghostscript to process PDF. The only issue would be what arguments are set in the delegates.xml file for reading PS/PDF/etc.
Thanks. I wonder where the "bold" font come from in convert result.

I used command in delegates.xml for pdf, it outputed ps, not jpg
snibgo
Posts: 12159
Joined: 2010-01-24T06:01:33+00:00
Authentication code: 1151
Location: England, UK

Re: convert and gs results difference

Post by snibgo »

The two linked images are clearly from different documents, or different parts of the same document, so we don't know why they have different quality. They seem to be rasterized at different densities.

"-verbose" is useful to see what Ghostscript command IM is using.
snibgo's IM pages: im.snibgo.com
wwubcn
Posts: 4
Joined: 2019-10-07T23:47:32+00:00
Authentication code: 1152

Re: convert and gs results difference

Post by wwubcn »

snibgo wrote: 2019-10-08T11:42:40+00:00 The two linked images are clearly from different documents, or different parts of the same document, so we don't know why they have different quality. They seem to be rasterized at different densities.

"-verbose" is useful to see what Ghostscript command IM is using.
You are correct, they are from different pages in the same pdf.

Here is the log with -verbose

```
convert -verbose sample.pdf a.jpg
'gs' -sstdout=%stderr -dQUIET -dSAFER -dBATCH -dNOPAUSE -dNOPROMPT -dMaxBitmap=500000000 -dAlignToPixels=0 -dGridFitTT=2 '-sDEVICE=pngalpha' -dTextAlphaBits=4 -dGraphicsAlphaBits=4 '-r72x72' '-sOutputFile=/var/folders/pb/tbjqx4_56w1cv1htzdm5yh4c0000gn/T/magick-15645ycTMnExb7xla%d' '-f/var/folders/pb/tbjqx4_56w1cv1htzdm5yh4c0000gn/T/magick-156456UMILWLqIH8a' '-f/var/folders/pb/tbjqx4_56w1cv1htzdm5yh4c0000gn/T/magick-15645KqScxlvU4x6G'
/var/folders/pb/tbjqx4_56w1cv1htzdm5yh4c0000gn/T/magick-15645ycTMnExb7xla1 PNG 595x842 595x842+0+0 8-bit sRGB 35364B 0.020u 0:00.011
/var/folders/pb/tbjqx4_56w1cv1htzdm5yh4c0000gn/T/magick-15645ycTMnExb7xla2 PNG 595x842 595x842+0+0 8-bit sRGB 41345B 0.030u 0:00.008
sample.pdf[0] PDF 595x842 595x842+0+0 16-bit sRGB 35364B 0.040u 0:00.008
sample.pdf[1] PDF 595x842 595x842+0+0 16-bit sRGB 41345B 0.010u 0:00.000
sample.pdf=>a-0.jpg[0] PDF 595x842 595x842+0+0 16-bit GrayscaleAlpha Gray 66963B 0.020u 0:00.010
sample.pdf=>a-1.jpg[1] PDF 595x842 595x842+0+0 16-bit GrayscaleAlpha Gray 83686B 0.050u 0:00.021
```

left from gs, right from convert
https://cl.ly/1db1d521d222

Any idea?
snibgo
Posts: 12159
Joined: 2010-01-24T06:01:33+00:00
Authentication code: 1151
Location: England, UK

Re: convert and gs results difference

Post by snibgo »

wwubcn wrote:left from gs, right from convert
The resolution seems to be the same (caps height about 7 pixels) but the IM result is monochrome, black and white with no grays, hence the letters are aliased. The command you show "convert -verbose sample.pdf a.jpg" shouldn't remove grays.

Can you link to a sample input PDF?
snibgo's IM pages: im.snibgo.com
wwubcn
Posts: 4
Joined: 2019-10-07T23:47:32+00:00
Authentication code: 1152

Re: convert and gs results difference

Post by wwubcn »

snibgo wrote: 2019-10-08T12:47:27+00:00
wwubcn wrote:left from gs, right from convert
The resolution seems to be the same (caps height about 7 pixels) but the IM result is monochrome, black and white with no grays, hence the letters are aliased. The command you show "convert -verbose sample.pdf a.jpg" shouldn't remove grays.

Can you link to a sample input PDF?
I'm very sorry that i could not share the pdf.

From gs, now i get png file. Then i use convert on the png to create jpg. The jpg is what I need (bold).

I guess my request is a little strange because i am looking for a 'worse' result :D
Post Reply