Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal,... gamma?

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

Here are the (hopefully) final versions of the images that illustrate the best upsamplers. Total size: 116K. Including the image that illustrates downsampling: 336K. Hopefully this is small enough for the "Examples" site.
Image
Image
Image
Last edited by NicolasRobidoux on 2012-09-30T09:07:45-07:00, edited 1 time in total.

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by fmw42 »

If it is not too much work, could you add EWA Catrom? Again you could go to 4x4 rather than 3x5 grid arrangement. I will leave it to you if you want to modify it or leave it as is. I know you don't care much for Catrom results. But since you added the Catrom, it seems fitting to include the EWA version as well.

P.S. The ringing on some of the Linear RGB enlargements is illuminating!

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

@Fred:
I only include methods I recommend, and I'm not ready to recommend EWA Catrom or Lagrange.
(Point, of course, is just there to show what the small images being enlarged is about. I don't recommend it either, except in the most extreme circumstances.)

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

Here is the code that generates the three "enlargements" images. (Not elegant, but it does the job, and it allows me to scrutinize results individually.) You could easily add EWA Catrom and Lagrange, EWA Lanczos2Sharp, and Triangle, which would be informative, even though none of them I myself recommend for enlarging.

Code: Select all

#/bin/sh
# magick -size 10x6 xc:grey85 +antialias -draw 'fill black line 4,0 5,5' \
magick -size 10x6 xc:grey20 +antialias -draw 'fill white line 4,0 5,5' \
    small.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Point -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Point.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Cosine \
    -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Cosine.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Lanczos \
    -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Lanczos.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Catrom \
    -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Catrom.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Mitchell.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -distort Resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB EWARobidoux.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter RobidouxSharp \
    -distort Resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB EWARobidouxSharp.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Lanczos -define filter:blur=.9891028367558475 \
    -distort Resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB EWALanczosSharpAlt.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Lanczos   -define filter:blur=.9264075766146068 \
    -distort Resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB EWALanczosRadius3.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -define filter:window=Jinc -define filter:lobes=3 \
    -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Ginseng.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -define filter:window=Quadratic \
    -distort Resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB EWAQuadraticJinc.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Quadratic \
    -distort Resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB EWAQuadratic.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Spline \
    -distort Resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB EWASpline.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Quadratic \
    -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Quadratic.png

magick small.png -colorspace RGB +sigmoidal-contrast 7 \
    -filter Spline \
    -resize 100x \
    -sigmoidal-contrast 7 -colorspace sRGB Spline.png

montage \
        -label "Point" Point.png \
        -label "Cosine" Cosine.png \
        -label "Lanczos" Lanczos.png \
        -label "Ginseng" Ginseng.png \
        -label "EWA LanczosRadius3" EWALanczosRadius3.png \
        -label "EWA LanczosSharp" EWALanczosSharpAlt.png \
        -label "Catrom" Catrom.png \
        -label "EWA RobidouxSharp" EWARobidouxSharp.png \
        -label "EWA QuadraticJinc" EWAQuadraticJinc.png \
        -label "EWA Robidoux" EWARobidoux.png \
        -label "Mitchell" Mitchell.png \
        -label "EWA Quadratic" EWAQuadratic.png \
        -label "Quadratic" Quadratic.png \
        -label "EWA Spline" EWASpline.png \
        -label "Spline" Spline.png \
        -geometry '120x65>+2+2' \
        -tile x3 \
        -background lightsteelblue \
        -fill black -title "Sigmoidized enlargements (contrast=7)" \
        -depth 8 \
        nicolas_enlarged_sigmoidized.png

pngcrush nicolas_enlarged_sigmoidized.png temp.png

mv temp.png nicolas_enlarged_sigmoidized.png

Code: Select all

#/bin/sh
# magick -size 10x6 xc:grey85 +antialias -draw 'fill black line 4,0 5,5' \
magick -size 10x6 xc:grey20 +antialias -draw 'fill white line 4,0 5,5' \
    small.png

magick small.png -colorspace RGB \
    -filter Point -resize 100x \
    -colorspace sRGB Point.png

magick small.png -colorspace RGB \
    -filter Cosine \
    -resize 100x \
    -colorspace sRGB Cosine.png

magick small.png -colorspace RGB \
    -filter Lanczos \
    -resize 100x \
    -colorspace sRGB Lanczos.png

magick small.png -colorspace RGB \
    -filter Catrom \
    -resize 100x \
    -colorspace sRGB Catrom.png

magick small.png -colorspace RGB \
    -resize 100x \
    -colorspace sRGB Mitchell.png

magick small.png -colorspace RGB \
    -distort Resize 100x \
    -colorspace sRGB EWARobidoux.png

magick small.png -colorspace RGB \
    -filter RobidouxSharp \
    -distort Resize 100x \
    -colorspace sRGB EWARobidouxSharp.png

magick small.png -colorspace RGB \
    -filter Lanczos -define filter:blur=.9891028367558475 \
    -distort Resize 100x \
    -colorspace sRGB EWALanczosSharpAlt.png

magick small.png -colorspace RGB \
    -filter Lanczos   -define filter:blur=.9264075766146068 \
    -distort Resize 100x \
    -colorspace sRGB EWALanczosRadius3.png

magick small.png -colorspace RGB \
    -define filter:window=Jinc -define filter:lobes=3 \
    -resize 100x \
    -colorspace sRGB Ginseng.png

magick small.png -colorspace RGB \
    -define filter:window=Quadratic \
    -distort Resize 100x \
    -colorspace sRGB EWAQuadraticJinc.png

magick small.png -colorspace RGB \
    -filter Quadratic \
    -distort Resize 100x \
    -colorspace sRGB EWAQuadratic.png

magick small.png -colorspace RGB \
    -filter Spline \
    -distort Resize 100x \
    -colorspace sRGB EWASpline.png

magick small.png -colorspace RGB \
    -filter Quadratic \
    -resize 100x \
    -colorspace sRGB Quadratic.png

magick small.png -colorspace RGB \
    -filter Spline \
    -resize 100x \
    -colorspace sRGB Spline.png

montage \
        -label "Point" Point.png \
        -label "Cosine" Cosine.png \
        -label "Lanczos" Lanczos.png \
        -label "Ginseng" Ginseng.png \
        -label "EWA LanczosRadius3" EWALanczosRadius3.png \
        -label "EWA LanczosSharp" EWALanczosSharpAlt.png \
        -label "Catrom" Catrom.png \
        -label "EWA RobidouxSharp" EWARobidouxSharp.png \
        -label "EWA QuadraticJinc" EWAQuadraticJinc.png \
        -label "EWA Robidoux" EWARobidoux.png \
        -label "Mitchell" Mitchell.png \
        -label "EWA Quadratic" EWAQuadratic.png \
        -label "Quadratic" Quadratic.png \
        -label "EWA Spline" EWASpline.png \
        -label "Spline" Spline.png \
        -geometry '120x65>+2+2' \
        -tile x3 \
        -background lightsteelblue \
        -fill black -title "Enlargements through linear RGB" \
        -depth 8 \
        nicolas_enlarged_linear.png

pngcrush nicolas_enlarged_linear.png temp.png

mv temp.png nicolas_enlarged_linear.png

Code: Select all

#/bin/sh
# magick -size 10x6 xc:grey85 +antialias -draw 'fill black line 4,0 5,5' \
magick -size 10x6 xc:grey20 +antialias -draw 'fill white line 4,0 5,5' \
    small.png

magick small.png \
    -filter Point -resize 100x \
    Point.png

magick small.png \
    -filter Cosine \
    -resize 100x \
    Cosine.png

magick small.png \
    -filter Lanczos \
    -resize 100x \
    Lanczos.png

magick small.png \
    -filter Catrom \
    -resize 100x \
    Catrom.png

magick small.png \
    -resize 100x \
    Mitchell.png

magick small.png \
    -distort Resize 100x \
    EWARobidoux.png

magick small.png \
    -filter RobidouxSharp \
    -distort Resize 100x \
    EWARobidouxSharp.png

magick small.png \
    -filter Lanczos -define filter:blur=.9891028367558475 \
    -distort Resize 100x \
    EWALanczosSharpAlt.png

magick small.png \
    -filter Lanczos   -define filter:blur=.9264075766146068 \
    -distort Resize 100x \
    EWALanczosRadius3.png

magick small.png \
    -define filter:window=Jinc -define filter:lobes=3 \
    -resize 100x \
    Ginseng.png

magick small.png \
    -define filter:window=Quadratic \
    -distort Resize 100x \
    EWAQuadraticJinc.png

magick small.png \
    -filter Quadratic \
    -distort Resize 100x \
    EWAQuadratic.png

magick small.png \
    -filter Spline \
    -distort Resize 100x \
    EWASpline.png

magick small.png \
    -filter Quadratic \
    -resize 100x \
    Quadratic.png

magick small.png \
    -filter Spline \
    -resize 100x \
    Spline.png

montage \
        -label "Point" Point.png \
        -label "Cosine" Cosine.png \
        -label "Lanczos" Lanczos.png \
        -label "Ginseng" Ginseng.png \
        -label "EWA LanczosRadius3" EWALanczosRadius3.png \
        -label "EWA LanczosSharp" EWALanczosSharpAlt.png \
        -label "Catrom" Catrom.png \
        -label "EWA RobidouxSharp" EWARobidouxSharp.png \
        -label "EWA QuadraticJinc" EWAQuadraticJinc.png \
        -label "EWA Robidoux" EWARobidoux.png \
        -label "Mitchell" Mitchell.png \
        -label "EWA Quadratic" EWAQuadratic.png \
        -label "Quadratic" Quadratic.png \
        -label "EWA Spline" EWASpline.png \
        -label "Spline" Spline.png \
        -geometry '120x65>+2+2' \
        -tile x3 \
        -background lightsteelblue \
        -fill black -title "Direct sRGB enlargements" \
        -depth 8 \
        nicolas_enlarged_srgb.png

pngcrush nicolas_enlarged_srgb.png temp.png

mv temp.png nicolas_enlarged_srgb.png
It's three shell scripts.
Last edited by NicolasRobidoux on 2012-09-29T16:11:36-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: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

@Fred: Here is the code that does the downsampling.

Code: Select all

#/bin/sh
magick rings_sm_orig.gif -colorspace RGB \
    -filter Point -resize 103x \
    -colorspace sRGB Point.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Cosine \
    -resize 103x \
    -colorspace sRGB Cosine.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Lanczos \
    -resize 103x \
    -colorspace sRGB Lanczos.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Lanczos \
    -resize 103x \
    -colorspace sRGB Lanczos.png

magick rings_sm_orig.gif -colorspace RGB \
    -resize 103x \
    -colorspace sRGB Mitchell.png

magick rings_sm_orig.gif -colorspace RGB \
    -distort Resize 103x \
    -colorspace sRGB EWARobidoux.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter RobidouxSharp \
    -distort Resize 103x \
    -colorspace sRGB EWARobidouxSharp.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Lanczos -define filter:blur=.9891028367558475 \
    -distort Resize 103x \
    -colorspace sRGB EWALanczosSharpAlt.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Lanczos -define filter:blur=.88549061701764 \
    -distort Resize 103x \
    -colorspace sRGB EWALanczos3Sharpest.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Lanczos   -define filter:blur=.9264075766146068 \
    -distort Resize 103x \
    -colorspace sRGB EWALanczosRadius3.png

magick rings_sm_orig.gif -colorspace RGB \
    -define filter:window=Jinc -define filter:lobes=3 \
    -resize 103x \
    -colorspace sRGB Ginseng.png

magick rings_sm_orig.gif -colorspace RGB \
    -define filter:window=Quadratic \
    -distort Resize 103x \
    -colorspace sRGB EWAQuadraticJinc.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Quadratic \
    -distort Resize 103x \
    -colorspace sRGB EWAQuadratic.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Spline \
    -distort Resize 103x \
    -colorspace sRGB EWASpline.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Quadratic \
    -resize 103x \
    -colorspace sRGB Quadratic.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Spline \
    -resize 103x \
    -colorspace sRGB Spline.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Triangle \
    -resize 103x \
    -colorspace sRGB Triangle.png

magick rings_sm_orig.gif -colorspace RGB \
    -filter Triangle \
    -distort Resize 103x \
    -colorspace sRGB EWATriangle.png

montage \
        -label "EWA Lanczos3Sharpest" EWALanczos3Sharpest.png \
        -label "Cosine" Cosine.png \
        -label "Lanczos" Lanczos.png \
        -label "Ginseng" Ginseng.png \
        -label "EWA LanczosRadius3" EWALanczosRadius3.png \
        -label "EWA LanczosSharp" EWALanczosSharpAlt.png \
        -label "EWA RobidouxSharp" EWARobidouxSharp.png \
        -label "EWA QuadraticJinc" EWAQuadraticJinc.png \
        -label "EWA Robidoux" EWARobidoux.png \
        -label "Mitchell" Mitchell.png \
        -label "EWA Triangle" EWATriangle.png \
        -label "Triangle" Triangle.png \
        -label "EWA Quadratic" EWAQuadratic.png \
        -label "Quadratic" Quadratic.png \
        -label "EWA Spline" EWASpline.png \
        -label "Spline" Spline.png \
        -geometry '130x130>+6+0' \
        -tile x4 \
        -background lightsteelblue \
        -fill black -title "Downsizing through linear RGB" \
        -depth 8 \
        nicolas_reduced_linear.png

pngcrush nicolas_reduced_linear.png temp.png

mv temp.png nicolas_reduced_linear.png

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

@Fred: I'm going to show EWA Catrom and Lagrange separately in a few minutes. (I won't add them to the above. That's what I mean by "separately".)

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

Image
Image
Image
Image
EWA Sinc and Jinc do well in the low pass filtering department, but they are only C^0 filters, which means that, even when downsampling, they most likely add quite obvious artifacts. Same with EWA Lagrange.
But then, if you USM...
EWA Catrom nearly perfectly reproduces affine gradients and it's C^1, so it can't be too horrible. And it's not.
-----
Again, I've not experimented enough with these methods to know for sure that they are not worth recommending. But I've also not gone full out into the search for a "USM-like" sharpening resizing filter, and I believe that I could find something better. Better than EWA Lanczos3Sharpest, which is the one I'm recommending now, which I've felt is better than the above.
Last edited by NicolasRobidoux on 2012-09-29T17:48:49-07:00, edited 1 time in total.

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by fmw42 »

NicolasRobidoux wrote:@Fred: I'm going to show EWA Catrom and Lagrange separately in a few minutes. (I won't add them to the above. That's what I mean by "separately".)

Fair enough. I see the examples above.

I am not sure if this is good or bad, but the EWA Catrom And EWA Lagrange sigmoidized enlargements show a more whitish "bend" region than with Linear or normal SRGB.

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

fmw42 wrote:...I am not sure if this is good or bad, but the EWA Catrom And EWA Lagrange sigmoidized enlargements show a more whitish "bend" region than with Linear or normal SRGB.
In my book, it's good.
However, they also show pretty strong oscillations in the straight parts, which is not good. EWA Lagrange, especially. They would be more obvious if I enlarged more.

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

@Fred:
The EWA Sinc 3 images were wrong. (Forgot about the automatic Sinc -> Jinc switch with EWA. Serves me right not to check with filter:verbose=1.)
Fixed now.

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

@Fred and Henry:
EWA Lagrange and Catrom performed better than I expected, although Lagrange has too many artifacts to be a "Pass". (And it's only C^0, which is not the end of the world when downsampling.)
Here is my guess (which may be wrong):
To replace a final USM, use convert {input} -filter Lanczos -define filter:blur={value} -distort Resize {size specification} {output} with a blur {value} between 1/sqrt(2)=0.7071 and 0.885 (which is pretty much the value for Lanczos3Sharpest). 1/Sqrt(2) is not chosen randomly: It is the reciprocal of half the wave length of the highest un-aliased frequency that can "live" on a uniform grid with spacing 1.
I've not tried this, in part because I do not know what people expect out of USM when downsampling (or upsampling). (I'm a "go for natural" kind of guy.)
But my guess is that the above suggestion is most likely to give the best sharpening/artifact ratio.
If this does not quite do it for you, add -define filter:window=cosine or -define filter:window=welch.
Or else, point out to me that I'm wrong, ideally by providing me with examples that show that something else is better.
Last edited by NicolasRobidoux on 2012-09-30T10:51: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: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

@Fred and Henry:
To illustrate the recommendations RE: USM I've had in "The Recommendations" for a while now, I've added EWA Lanczos with blur=0.8 to the "Extra" examples above.
P.S. And if you only wanted one halo, I'd say deblur EWA Quadratic-windowed Jinc 3 (almost certainly less than EWA Lanczos), and if you don't want any second halo, go with Keys, e.g. EWA Catrom.
I simply don't like what I see with EWA Lagrange.
Then again, I've not experimented (enough).

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by fmw42 »

I have not experimented that much on Lagrange either. With my limited tests, I just found that it was quite similar in sharpening to Catrom.

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

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by NicolasRobidoux »

The chip test image, near the beginning of this thread, is one example in which resizing through LAB does particularly well, noticeably better than directly filtering sRGB pixel values.

henrywho
Posts: 188
Joined: 2011-08-17T06:46:40-07:00
Authentication code: 8675308

Re: Enlarge with sRGB, RGB, LAB, LUV, XYZ, sigmoidal...?

Post by henrywho »

NicolasRobidoux wrote:@Fred and Henry:
To illustrate the recommendations RE: USM I've had in "The Recommendations" for a while now, I've added EWA Lanczos with blur=0.8 to the "Extra" examples above.
Does "Extra" refer to some additional parameters?

Locked