minimize resize halo by luminance-weighted gamma blending

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

minimize resize halo by luminance-weighted gamma blending

Post by NicolasRobidoux » 2014-07-18T01:29:02-07:00

As discussed initially in
viewtopic.php?f=1&t=25736 and
viewtopic.php?f=22&t=21804#p89728
and further developed in
http://www.luminous-landscape.com/forum ... #msg745796 and
http://www.luminous-landscape.com/forum ... #msg746273,
I have proposed a new approach to the minimization of haloing when using resampling filters that introduce it (filters "with negative lobes").
I suggest that, within the ImageMagick forums, we centralize the discussion here.
Thanks to Bart van der Wolf and Fred Weinhaus who have been really helpful.
Last edited by NicolasRobidoux on 2014-08-12T23:42:34-07:00, edited 1 time in total.

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

Re: halo minimization by luminance-weighted gamma blending

Post by fmw42 » 2014-07-19T16:05:06-07:00

Nicolas came up with a new method of blending gamma adjusted linear RGB magnification with the negated same so as to reduce both bright and dark halos.

see http://www.luminous-landscape.com/forum ... #msg746689

Here is the (unix syntax) command lines that I used for testing (in IM 6.8.9.5 Q16 Mac OSX). All tests were 800% magnification, except for the first example with the checker pattern, which is 3200% magnification.

Code: Select all

sRGB:
convert input_small.png -set colorspace sRGB \
-filter LanczosRadius -distort Resize 800% \
-depth 8 input_small_LanczosRadius_s800_sRGB.png

RGB:
convert input_small.png -depth 16 -set colorspace sRGB -colorspace RGB \
-filter LanczosRadius -distort Resize 800% \
-set colorspace RGB -colorspace sRGB \
-depth 8 input_small_LanczosRadius_s800_RGB.png

LAB:
convert input_small.png -depth 16 -set colorspace sRGB -colorspace LAB \
-filter LanczosRadius -distort Resize 800% \
-set colorspace LAB -colorspace sRGB \
-depth 8 input_small_LanczosRadius_s800_LAB.png

Blended (gamma 2 adjusted with no gamma) RGB:
convert \( input_small.png -depth 16 -set colorspace sRGB -colorspace RGB \) \
\( -clone 0 -gamma 2 -filter LanczosRadius -distort Resize 800% -gamma 0.5 \) \
\( -clone 0 -filter LanczosRadius -distort Resize 800% \) \
\( -clone 2 -colorspace gray -auto-level \) \
-delete 0 -compose over -composite \
-set colorspace RGB -colorspace sRGB \
-depth 8 input_small_LanczosRadius_blended_s800_g2_RGB.png

Blended (gamma 3 adjusted with no gamma) RGB:
convert \( input_small.png -depth 16 -set colorspace sRGB -colorspace RGB \) \
\( -clone 0 -gamma 3 -filter LanczosRadius -distort Resize 800% -gamma 0.333333333333333 \) \
\( -clone 0 -filter LanczosRadius -distort Resize 800% \) \
\( -clone 2 -colorspace gray -auto-level \) \
-delete 0 -compose over -composite \
-set colorspace RGB -colorspace sRGB \
-depth 8 input_small_LanczosRadius_blended_s800_g3_RGB.png

Dual Blending (gamma 3 and negated image with gamma 3), RGB:
convert \( input_small.png -depth 16 -set colorspace sRGB -colorspace RGB \) \
\( -clone 0 -gamma 3 -filter LanczosRadius -distort Resize 800% -gamma 0.333333333333333 \) \
\( -clone 0 -negate -gamma 3 -filter LanczosRadius -distort Resize 800% -gamma 0.333333333333333 -negate \) \
\( -clone 1 -clone 2 -evaluate-sequence mean -colorspace gray -auto-level \) \
-delete 0 -compose over -composite \
-set colorspace RGB -colorspace sRGB \
-depth 8 input_small_LanczosRadius_dualblended_s800_g3_RGB.png
Here are results for various images. The mitigation of haloing is most evident on the puzzle and valiant images.

All the images can be downloaded at http://www.fmwconcepts.com/misc_tests/R ... ests_8.zip

input (checker):
Image

sRGB:
Image

RGB:
Image

LAB:
Image

Blended gamma=2 RGB:
Image

Blended gamma=3 RGB:
Image

Dual Blended gamma=3 RGB:
Image



input (puzzle):
Image

sRGB:
Image

RGB:
Image

LAB:
Image

Blended gamma=2 RGB:
Image

Blended gamma=3 RGB:
Image

Dual Blended gamma=3 RGB:
Image



input (valiant):
Image

sRGB:
Image

RGB:
Image

LAB:
Image

Blended gamma=2 RGB:
Image

Blended gamma=3 RGB:
Image

Dual Blended gamma=3 RGB:
Image



input (chip):
Image

sRGB:
Image

RGB:
Image

LAB:
Image

Blended gamma=2 RGB:
Image

Blended gamma=3 RGB:
Image

Dual Blended gamma=3 RGB:
Image



input (wizzard):
Image

sRGB:
Image

RGB:
Image

LAB:
Image

Blended gamma=2 RGB:
Image

Blended gamma=3 RGB:
Image

Dual Blended gamma=3 RGB:
Image



input (person):
Image

sRGB:
Image

RGB:
Image

LAB:
Image

Blended gamma=2 RGB:
Image

Blended gamma=3 RGB:
Image

Dual Blended gamma=3 RGB:
Image


All the images can be downloaded at http://www.fmwconcepts.com/misc_tests/R ... ests_8.zip

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

Re: halo minimization by luminance-weighted gamma blending

Post by NicolasRobidoux » 2014-07-23T02:43:53-07:00

This viewtopic.php?f=1&t=25945#p113621 and some of the preceding posts in the same thread are relevant to this subject.

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

Re: halo minimization by luminance-weighted gamma blending

Post by NicolasRobidoux » 2014-08-10T01:29:35-07:00


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

Re: minimize resize halo by luminance-weighted gamma blendin

Post by NicolasRobidoux » 2014-09-20T09:26:25-07:00

There is yet another iteration of the script, which has three variants as explained in http://www.luminous-landscape.com/forum ... #msg763245

snibgo
Posts: 12008
Joined: 2010-01-23T23:01:33-07:00
Authentication code: 1151
Location: England, UK

Re: minimize resize halo by luminance-weighted gamma blendin

Post by snibgo » 2014-09-25T07:31:59-07:00

I'll mention here that I've written my own version of the script, and done some trials with it: http://im.snibgo.com/resamphm.htm

I shouldn't judge the results from a single image, but I gotta say: I love the downsampling with sharpen. It's much better than I get with "-resize -unsharp".
snibgo's IM pages: im.snibgo.com

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

Re: minimize resize halo by luminance-weighted gamma blendin

Post by NicolasRobidoux » 2014-10-05T01:34:24-07:00

Alan:
Suggestion:
For downsampling, try

Code: Select all

convert input.jpg -set colorspace sRGB -colorspace RGB -define filter:c=SHARPENINGAMOUNT -filter cubic -distort Resize SIZESPECIFICATION -set colorspace RGB -colorspace sRGB output.png
or something like that, where SHARPENINGAMOUNT is between 0 and .6666666666666, with the C values between the Robidoux and Catmull-Rom being most interesting. (Unless your image is really blurry or you like out of this world sharpness, I'd stick to value strictly less than C=.5, and I would not go below the RobidouxSoft value, value used by Bart's script, unless blur is what you consider the least offensive artifact.)
I am not sure that Bart's script's complications are responsible for what you like in the downsampling results. EWA with a Keys cubic through linear light may give something you like just as much.
It just may. And if so, I'd love to know.

Post Reply