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?".
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert - downscaling comic pages

Post by fmw42 »

That is very odd that it creates an edge-like result for either JPG or PNG? Perhaps there is an issue with your older IM version or older png and jpg delegates. Can you upgrade?

I ran this with no problem of that sort on IM 6.8.9.7 Q16 Mac OSX

Version: ImageMagick 6.8.9-7 Q16 x86_64 2014-08-19 http://www.imagemagick.org
Copyright: Copyright (C) 1999-2014 ImageMagick Studio LLC
Features: DPC Modules
Delegates: bzlib cairo fftw fontconfig freetype gslib jbig jng jp2 jpeg lcms lqr ltdl lzma openexr png ps rsvg tiff webp x xml zlib

Portable Network Graphics (libpng 1.6.12)
Joint Photographic Experts Group JFIF format (90)

Code: Select all

convert \( bw-thin_line.jpg -set colorspace sRGB -colorspace RGB \) \
\( -clone 0 -gamma 1.666666666666666 -filter RobidouxSharp -distort Resize 750x1125 -gamma 0.6 \) \
\( -clone 0 -filter RobidouxSharp -distort Resize 750x1125 \) \
-delete 0 \
\( -clone 1 -colorspace gray -auto-level \) \
-compose over -composite \
-set colorspace RGB -colorspace sRGB -depth 8 +repage \
robidouxsharp_rgb_gamma_blend_ewa.png
Image

Code: Select all

convert \( bw-thin_line.jpg -set colorspace sRGB -colorspace RGB \) \
\( -clone 0 -gamma 1.666666666666666 -filter Catrom -distort Resize 750x1125 -gamma 0.6 \) \
\( -clone 0 -filter Catrom -distort Resize 750x1125 \) \
-delete 0 \
\( -clone 1 -colorspace gray -auto-level \) \
-compose over -composite \
-set colorspace RGB -colorspace sRGB -depth 8 +repage \
catrom_rgb_gamma_blend_ewa.png
Image

Code: Select all

convert \( bw-thin_line.jpg -set colorspace sRGB -colorspace RGB \) \
\( -clone 0 -gamma 1.666666666666666 -filter Catrom -resize 750x1125 -gamma 0.6 \) \
\( -clone 0 -filter Catrom -resize 750x1125 \) \
-delete 0 \
\( -clone 1 -colorspace gray -auto-level \) \
-compose over -composite \
-set colorspace RGB -colorspace sRGB -depth 8 +repage \
catrom_rgb_gamma_blend_non_ewa.png
Image

Code: Select all

convert \( bw-thin_line.jpg -set colorspace sRGB -colorspace RGB \) \
\( -clone 0 -gamma 1.666666666666666 -filter RobidouxSharp -resize 750x1125 -gamma 0.6 \) \
\( -clone 0 -filter RobidouxSharp -resize 750x1125 \) \
-delete 0 \
\( -clone 1 -colorspace gray -auto-level \) \
-compose over -composite \
-set colorspace RGB -colorspace sRGB -depth 8 +repage \
robidouxsharp_rgb_gamma_blend_non_ewa.png
Image
steve___
Posts: 28
Joined: 2012-07-17T09:52:07-07:00
Authentication code: 15

Re: convert - downscaling comic pages

Post by steve___ »

fmw42 wrote:That is very odd that it creates an edge-like result for either JPG or PNG? Perhaps there is an issue with your older IM version or older png and jpg delegates. Can you upgrade?
Yes, I get it with either jpg or png. Yep I can upgrade. Thanks a lot for testing.

I find catrom with ewa too sharp. I have it on my list to try Nicolas'
clone method using catrom without ewa.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert - downscaling comic pages

Post by fmw42 »

I added Catrom and RobidouxSharp with -resize (as opposed to -distort resize) as well just now to my earlier post.
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 »

Is it the +repage command that interacts badly with the bit depth shift? This would be a bug in IM, I think.
Do you really need it? Can you just replace it by -strip?
(As always, really quickly off the top of my head.)
Last edited by NicolasRobidoux on 2014-08-26T23:04:44-07:00, edited 1 time in total.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: convert - downscaling comic pages

Post by fmw42 »

NicolasRobidoux wrote:Is it the +repage command that interacts badly with the bit depth shift? This would be a bug in IM, I think.
It worked fine for me in my post above with the pictures. I think it is his IM version or older delegates.
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 »

Steve:
Are you still using mozjpeg? Make sure your jpeg and png libraries are compatible with ImageMagick.
convert -verbose or -version does not necessarily give the whole story because, for example, libjpeg-turbo often installs itself (or, rather, is often installed) as if it was libjpeg (I think; not sure), which is OK because it is a careful clone. So, maybe mozjpeg does the same?
Last edited by NicolasRobidoux on 2014-08-26T23:15:13-07:00, edited 2 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 »

Assuming updating IM does not fix the problem: What happens if you put +repage before -depth 8?
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 »

steve___ wrote: ...
I find catrom with ewa too sharp. I have it on my list to try Nicolas'
clone method using catrom without ewa.
Very reasonable. Orthogonal CatRom is a very good orthogonal method.
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 »

You may want to test other gammas in the "complex script" than 5/3 (and 3/5). I picked that one because you liked 4/3 and because it should do less damage to dense color patterns that than much larger gamma. My hunch is that >>when downsampling a lot<< gamma 2 (and 1/2) are as far as one should go unless the chosen filter really introduces too much halo. And you (Steve) seem to be angling toward filters that produce only one halo, so halo supppression is a bit less of an issue as a result.
steve___
Posts: 28
Joined: 2012-07-17T09:52:07-07:00
Authentication code: 15

Re: convert - downscaling comic pages

Post by steve___ »

My test were before I added +repage

I do not have mozjpeg installed
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 »

Fred: Indeed, the "complex script" with RobidouxSharp -distort Resize looks quite good. Thank you.
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 »

Steve: To my eye, the result with the "complex script" and RobidouxSharp -distort Resize looks a touch too sharp. I suggest you try replacing RobidouxSharp by Mitchell or Robidoux and see what you think (think what you see?).
henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: convert - downscaling comic pages

Post by henrywho »

Nic, I am not really familiar with the composite operator. Would you mind pointing me to the explanation of the "complex" command line and the rationale of the blending using an alpha mask? (I guess it is meant to thicken the black lines by picking more from the gamma-adjusted downsize.)
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 »

henrywho wrote:Nic, I am not really familiar with the composite operator. Would you mind pointing me to the explanation of the "complex" command line and the rationale of the blending using an alpha mask? (I guess it is meant to thicken the black lines by picking more from the gamma-adjusted downsize.)
In this particular case, no, because the gamma is undone at the end.
What this does is a long story. The short version is that the resize through high gamma minimizes dark halos, the resize through linear RGB minimizes light halos, and the two resize results are blended on a pixel by pixel basis based on how light the pixel is. (Lighter -> more linear light resizing; Darker -> more resizing through gamma space.) This manages to do what sigmoidization was meant to but in a much more controlled way, without significant bad side effects when upsampling, and none other than a small penalty for not doing everything in linear light when downsampling.
Some details are found here: viewtopic.php?f=22&t=25935 and the "generic" scheme (not the tuned for downsampling) discussed in http://www.luminous-landscape.com/forum ... ic=91754.0.
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 »

Looked some more the line drawing comics results, and EWA RobidouxSharp with luminance-weighted gamma blending is at once more "defined" (some combination of contrast and sharpness) and less aliased than tensor (orthogonal) CatRom with luminance-weighted gamma blending. It's a close call, but on my MacBook Pro with Retina display, the first one wins consistently. (Hopefully I'm not suffering too badly from selection bias.)
-----
Henri: The longer story is this: luminance-weighted gamma blending steepens the transition between light and dark regions (or lines) while keeping things smooth. This is why it works both as a resampling scheme and a sharpening scheme.
Post Reply