convert - downscaling comic pages

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?".
snibgo
Posts: 12174
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: convert - downscaling comic pages

Post by snibgo » 2014-08-01T08:01:19-07:00

On gamma, Q16 and HDRI: If the first gamma is <1, clipping will occur at the bottom (ie in the shadows).

For a modest "-gamma 3", the result is horrible with integer Q8, but also noticeable at integer Q16. Results are better at integer Q32, or HDRI at Q8, Q16 or Q32.

For a more extreme "-gamma 40", all 6 varieties show clipping, but Q32 HDRI is the clear winner.
snibgo's IM pages: im.snibgo.com

steve___
Posts: 28
Joined: 2012-07-17T09:52:07-07:00
Authentication code: 15

Re: convert - downscaling comic pages

Post by steve___ » 2014-08-01T08:40:29-07:00

Using photoshop I created a set of delta images to illustrate how much
noise was created after down-sampling. The original, down-sample and
delta images can be found here[1]. For the D2 images I upscaled the
original file to twice its size, with nearest-neighbor resampling, then
upscaled the converted images the same way so the duplicated hard pixels
show the difference with no blurring.

'EWA Ginseng-Lab' and 'Lanczos2Sharp-Lab' showed the least noise but
looked a little too sharp. The winner in the initial tests is 'EWA
Ginseng-RGB' and second is 'Lanczos-RGB'. The command used for EWA
Ginseng-RGB' was:

Code: Select all

$ convert infile.jpg -colorspace RGB +sigmoidal-contrast 7.5 -define filter:window=Quadratic -distort Resize 70.8% -sigmoidal-contrast 7.5 -colorspace sRGB outfile.jpg
These are only initial tests. There are many more to do. Besides
looking at deltas, are there any other methods I can use to show the
changes caused by down-sampling?


[1] https://dev.zcomix.com/files/ds_tests.zip

steve___
Posts: 28
Joined: 2012-07-17T09:52:07-07:00
Authentication code: 15

Re: convert - downscaling comic pages

Post by steve___ » 2014-08-01T09:27:55-07:00

I am using:

Code: Select all

$ convert -version
Version: ImageMagick 6.8.7-6 Q16 x86_64 2013-11-17 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2013 ImageMagick Studio LLC
Features: DPC HDRI Modules OpenCL OpenMP
Delegates: bzlib cairo fontconfig freetype gslib jng jp2 jpeg lcms lqr ltdl lzma openexr pangocairo png ps rsvg tiff webp wmf x xml zlib
Based on this, do I need to change the syntax of the code?

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

Re: convert - downscaling comic pages

Post by fmw42 » 2014-08-01T09:33:17-07:00

6.8.7-6 is current enough that -colorspace RGB means linear RGB

see
viewtopic.php?f=4&t=21269

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-01T09:36:39-07:00

Steve:
Your winner is actually sigmoidized EWA Quadratic-Jinc, which has been found, by me and others, to be a good method if you don't like haloing but want strong anti-aliasing.
Normally, I would not recommend sigmoidization, but black on white line drawings are perfect for it.
P.S. Chester Brown. Most excellent taste.
Last edited by NicolasRobidoux on 2014-08-01T09:43:08-07:00, edited 1 time in total.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-01T09:42:17-07:00

I would suggest that instead of using some numerical measure of "good" which most likely is very loosely correlated with actually looking good, you use your eyes, making lots of comparisons in scenarios similar to the ones that matter.

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

Re: convert - downscaling comic pages

Post by fmw42 » 2014-08-01T10:21:34-07:00

NicolasRobidoux wrote:
fmw42 wrote:EWA is of no special help unless you are distorting to some drastically changed view like an extremely tilted perspective. Face-on view don't need EWA.
I beg to disagree: The best resampling filters in ImageMagick are EWA methods. So, it you want the best possible results, you "need" EWA.
To resize using EWA use

Code: Select all

-distort Resize
instead of

Code: Select all

-resize
That's it.
P.S. Fred: I think we misunderstood each other.
Yes, I was only talking about image distortion. Where EWA is spatially varying. I understand that -distort uses the same methods for a circular filter, but I believe they are stationary over the images. Correct me if I am wrong?

But I certainly did not intend to discourage the use of -distort resize.

This is nit-picking, but perhaps we should call it CWA (for cylindrical or more properly circular weighted average) when used in -distort resize rather than EWA.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-01T12:06:58-07:00

Fred:
Indeed, there has been some confusion having to do with the fact that when preserving aspect ratio the ellipses are circles.
Question: "Where do ellipses come from?"
Answer: "Ellipses are the offspring of generality."
Last edited by NicolasRobidoux on 2014-08-02T03:52:20-07:00, edited 1 time in total.

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

Re: convert - downscaling comic pages

Post by fmw42 » 2014-08-01T12:10:26-07:00

Question: "Where do ellipses come from?"
Answer: "Ellipses are the offspring of generality."
The conic sections were named and studied at least since 200 BC, when Apollonius of Perga undertook a systematic study of their properties.

:wink:

Looking at it the other way, circles are just a limiting case of ellipses.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-02T22:23:46-07:00

snibgo wrote:On gamma, Q16 and HDRI: If the first gamma is <1, clipping will occur at the bottom (ie in the shadows).

For a modest "-gamma 3", the result is horrible with integer Q8, but also noticeable at integer Q16. Results are better at integer Q32, or HDRI at Q8, Q16 or Q32.

For a more extreme "-gamma 40", all 6 varieties show clipping, but Q32 HDRI is the clear winner.
Good point Alan. I need to get it out of my head that everyone uses HDRI.

steve___
Posts: 28
Joined: 2012-07-17T09:52:07-07:00
Authentication code: 15

Re: convert - downscaling comic pages

Post by steve___ » 2014-08-21T17:13:30-07:00

After much testing with ImageMagick 6.8.8-5 HDRI Q16 I've settled on Catrom
with a gamma setting of 1.333333333333333/.75 and no ewa. Here is the
syntax I'm using:

Code: Select all

$ convert infile[0] -quiet -colorspace RGB -gamma 1.333333333333333 -filter Catrom -resize $res -gamma .75 -colorspace sRGB +repage outfile
The files I tested with and the output from the Catrom filter is here:
https://dev.zcomix.com/files/convert-tests.zip

I also tried a quick test with graphicmagick. The filesizes are much
smaller. The b&w and solid colour images are useable but the full
colour images (ie colour-complex and colour-detailed) at "web" size are
not. I've included those images in the zip above. The syntax I used
for graphicmagick v1.3.18 was:

Code: Select all

$ gm convert infile -colorspace RGB -gamma .6 -filter Catrom -resize $res -gamma 1.666666666666666 +repage outfile
(adding '-colorspace sRGB' caused the output to be way off)

Let me know if I missed anything.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-23T07:56:17-07:00

Thank you Steve.
Putting the result of your testing in my "What worked for someone" memory box.
P.S. I persist in thinking that an EWA can always be found that does better than any tensor method in a specific situation. Have you tried something like

Code: Select all

convert infile[0] -quiet -colorspace RGB -gamma 1.333333333333333 -filter RobidouxSharp -distort Resize $res -gamma .75 -colorspace sRGB +repage outfile
or

Code: Select all

convert infile[0] -quiet -colorspace RGB -gamma 1.333333333333333 -filter CatRom -distort Resize $res -gamma .75 -colorspace sRGB +repage outfile
?

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-23T11:37:11-07:00

I also think that something like this may work well given what you have found to work well, esp. with color:

Code: Select all

convert \( input.png -depth 16 -set colorspace sRGB -colorspace RGB \) \
 \( -clone 0 -gamma 1.666666666666666 -filter RobidouxSharp -distort Resize $res -gamma 0.6 \) \
 \( -clone 0 -filter RobidouxSharp -distort Resize $res \) \
    -delete 0 \
 \( -clone 1 -colorspace gray -auto-level \) \
 -compose over -composite \
 -set colorspace RGB -colorspace sRGB \
output.png
or maybe the same with RobidouxSharp replaced by CatRom. Instead of GAMMA=5/3 and RECIPROCALOFGAMMA=3/5, you could also try other values. See http://www.luminous-landscape.com/forum ... ic=91754.0
Also, I've not addressed the issue of how best to compress for the web. This is a whole different story. I myself use highly customized calls to libjpeg-turbo after producing images that cjpeg understands. One can do much with ImageMagick, but you need to learn how JPEG compression works to get the most out of it.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-24T00:09:11-07:00

steve___ wrote:After much testing with ImageMagick 6.8.8-5 HDRI Q16 I've settled on Catrom
with a gamma setting of 1.333333333333333/.75 and no ewa. Here is the
syntax I'm using:

Code: Select all

$ convert infile[0] -quiet -colorspace RGB -gamma 1.333333333333333 -filter Catrom -resize $res -gamma .75 -colorspace sRGB +repage outfile
...
It actually does make sense in your context that you are not undoing the gamma you are applying, although this may give very undesirable results when you are dealing with color instead of greyscale. P.S. This previous sentence flirts with nonsense as far as trustable advice goes. Unless you are dealing with greyscale etc, not being consistent in gamma and colorspace handling is flirting with disaster. But it may help with greyscale line art.
Also note that the -colorspace command changed meaning, roughly 2 years ago, in ImageMagick. GraphicsMagick boasts a more stable (meaning frozen) interface, and so it uses the "old" meaning. I venture that it explains the differences you see.
Last edited by NicolasRobidoux on 2014-08-24T08:37:43-07:00, edited 5 times in total.

NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: convert - downscaling comic pages

Post by NicolasRobidoux » 2014-08-24T03:47:48-07:00

Steve: I think you forgot to include the originals in your zip file? Or is the orig folder meant to be empty.

Post Reply