Pages: 1 ... 4 5 [6] 7 8 ... 24   Go Down

Author Topic: A free high quality resampling tool for ImageMagick users  (Read 240572 times)

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8913
Re: A free high quality resampling tool for ImageMagick users
« Reply #100 on: July 25, 2014, 03:52:26 am »

Hi all,

The down-sampling with sharpening code in Windows Batch script dialect is now:
convert ( "input.png" -depth 16 -set colorspace sRGB -colorspace RGB ) ^
 -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 800x800 ^
 -set colorspace RGB -colorspace sRGB ^
 -define convolve:scale=^75%%,100 -morphology Convolve DoG:0,0,0.5007503035749775 ^
 "output.png"

As coded here, it assumes the original is larger that fits in an 800x800 pixel boundary, and will be down-sampled. I've selected an 'amount' setting of 75 (to allow to spot it easily) in the code snippet, but values from 50 to 100 can be considered normal. When set to normal at 50, there is minimal halo risk, and when set to crisp at 100, there is some halo risk (but usually too small to see at 100% display zoom). Therefore, in the full script it is a variable that takes user input, thus allowing to adjust based on personal preference and image content. Higher values can also be used, but currently have a higher risk of causing clipping if there is already high contrast detail near the clipping points (although it does allow to bring out structure in otherwise lower contrast regions in the medium brightness tonal range).

If no post-down-sample sharpening is anticipated to be done, one may better use another algorithm that's sharper by definition than the purposely blurry 'RobidouxSoft', because without additional sharpening there is no risk of boosting halos.

Again, this is specific code for down-sampling, since the Point Spread Function that is used for deconvolution is optimized for that type of image content when using the 'RobidouxSoft' filter settings. When cheating a bit, one can select this algorithm for upsampling, and use a significantly higher 'Amount', but in general one gets better results with the initial more general blending algorithm optimzed for those upsampling scales.

Cheers,
Bart

P.S. Attached you will find the most recent version (1.1.2)
« Last Edit: July 25, 2014, 04:12:08 am by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #101 on: July 25, 2014, 03:57:23 am »

Irregardless (wonderful word) of the occasional invocation of my name, I am watching this thread with immense interest while tending to unrelated urgent tasks.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #102 on: July 25, 2014, 04:01:27 am »

Hi all,

The down-sampling with sharpening code in Windows Batch script dialect is now:
convert ( "input.png" -depth 16 -set colorspace sRGB -colorspace RGB ) ^
 -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 800x800 ^
 -set colorspace RGB -colorspace sRGB ^
 -define convolve:scale=^75%%,100 -morphology Convolve DoG:0,0,0.5007503035749775 ^
 "output.png"
Opinion: Instead of doing your deconvolution in sRGB, convert to a suitably chosen gamma space, deconvolve there, ungamma back to linear RGB, convert to sRGB.
It's that annoying linear bit near black.
Another thing you could try (?) is deconvolve in linear, deconvolve in gamma (converted back to linear) and then blend with the weight of the linear result proportional to itself after auto level.
P.S. I actually like the ring of this last idea a lot. Someone who wants less sharpening (because the above blend is a sharpened result) can blend the result with the plain (not deconvolved) linear RGB result. After that, ship everything back to sRGB (or Adobe RGB).
« Last Edit: July 25, 2014, 04:55:15 am by NicolasRobidoux »
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8913
Re: A free high quality resampling tool for ImageMagick users
« Reply #103 on: July 25, 2014, 04:53:38 am »

Opinion: Instead of doing your deconvolution in sRGB, convert to a suitably chosen gamma space, deconvolve there, ungamma back to linear RGB, convert to sRGB.

Hi Nicolas, opinion noted.

My main concern (well, one of them) as a photographer is the accuracy of color blending when downsampling (e.g. for Web publishing), which by definition requires linear light space. The example image from Eric Brasseur's web page holds up better in (also my current) linear light resampling than in a different gamma, or even a partial linear gammas blend.

EDIT:Deconvolution is also a weighted blend of multiple neighboring pixels, although perhaps less destructive to color accuracy due to the lower weights of more distant pixels. It does attempt to restore the original signal's color better by 'pulling in' some blur and linearly mixed contamination from surrounding pixels.

I've attached an example of a 50% downsample with your Gamma 1 and additional Gamma 2 blend (which is pretty decent for down-sampling, although better for upsampling), and my current 'RobidouxSoft' Cubic implementation in simple linear light with a sharpening amount of 100 (much better color).

Quote
It's that annoying linear bit near black.

Yes, it's a bitch. Lanczos is pretty awesome (and theoretically optimal) if it were not for that dark side edge halo in linear light.

Quote
Another thing you could try (?) is deconvolve in linear, deconvolve in gamma (converted back to linear) and then blend with the weight of the linear result proportional to itself after auto level.

I'll have a look (when time allows), but I'm afraid that the deconvolution in linear space again amplifies any dark side edge (halo) more that we'd like, making blending mandatory.

Cheers,
Bart
« Last Edit: July 25, 2014, 06:31:39 am by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #104 on: July 25, 2014, 04:57:03 am »

My main concern (well, one of them) as a photographer is the accuracy of color blending when downsampling (e.g. for Web publishing), which by definition requires linear light space. The example image from Eric Brasseur's web page holds up better in (also my current) linear light resampling than in a different gamma, or even a partial linear gammas blend.
See http://www.luminous-landscape.com/forum/index.php?topic=91754.msg747632#msg747632. If there is clipping, the "by definition" is bent. Brasseur used (TTBOMK) bilinear: no overshoots, no clipping. Boringly soft, yet aliased. (Gotta run.)
P.S. Moire is another example of why it may not pay to worship the linear light god to idolatry level: A non-linear light resampling/sharpening method that is sharp and yet avoids moire beats a pure linear light resampling methods that does. The "thought experiment" I linked above assumes that the pixel values we get are representative of the result of filtering at infinite density and locally averaging somehow. Near identity transformations (resize down by one half of one percent) often violate this.
P.S. I don't mean to trivialize how important linear light is. I just mean that it should be treated as a harsh mistress, not a god. A powerful tool, not a panacea.
« Last Edit: July 26, 2014, 03:36:55 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #105 on: July 25, 2014, 05:55:31 am »

Bart:
As you probably know, RobidouxSoft is explicitly designed to preserve (an approximation of what can be crudely described as) mid-tones.
« Last Edit: July 25, 2014, 06:59:55 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #106 on: July 25, 2014, 01:13:17 pm »

Bart:
From your latest examples, it looks like the "always downsample through linear light" still stands, despite all the caveats I can muster.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #107 on: July 25, 2014, 01:18:23 pm »

...
I'll have a look (when time allows), but I'm afraid that the deconvolution in linear space again amplifies any dark side edge (halo) more that we'd like, making blending mandatory.
It's the same trick, namely "luminance weighted gamma resampling" except that resampling is replaced by deconvolution. Then, the downsampling itself is pure linear light processing. Only the deconvolution mixes in gamma. But indeed if the "dark edge" is already ugly in gamma, blending in some linear is not going to help matters. All I could suggest, then, is to push the gamma to 3 and then convert back to linear then sRGB.
« Last Edit: July 25, 2014, 01:20:41 pm by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #108 on: July 25, 2014, 02:05:06 pm »

Bart:
It is possible that, among Keys cubic splines, there is nothing particularly great about RobidouxSoft, Robidoux and RobidouxSharp when used as EWA filter kernels. Maybe, maybe not.
Really: Set c to any value between 0 and .5 (and possibly beyond), or equivalently set b to any value between 1 and 0 (and possibly beyond).
The Robidoux* have c values chosen using reasonable criterions. However, this does not mean that there is not one with a different parameter that is "better".
P.S. OK, OK, OK, a number of independent sources have confirmed that EWA Robidoux is quite good at downsampling, and not all of them are relatives of students. So it probably does not suck. Maybe the newer RobidouxSoft and RobidouxSharp don't suck either. And maybe there is a magical c value just waiting to be discovered.
« Last Edit: July 25, 2014, 02:20:04 pm by NicolasRobidoux »
Logged

Pictus

  • Full Member
  • ***
  • Offline Offline
  • Posts: 216
    • Retouching
Re: A free high quality resampling tool for ImageMagick users
« Reply #109 on: July 26, 2014, 12:47:43 am »

RobidouxSoft + deconvolution is TOP for down-sampling!
Bye Bye Cornelius Lanczos...  ;D

Here to get the right taste for the amount of sharpness and some experiments, the output
is now a PSD with 3 layers, one soft, one sharp and the last is a sharp with Canny Edge Detection.
Experimenting the Canny to help tame down some halos...  

BTW,  ImageMagick 7 beta is at http://www.imagemagick.org/download/binaries/
UPDATE: Scripts not working and the command Convert is now Magick.
« Last Edit: July 27, 2014, 02:25:22 pm by Pictus »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8913
Re: A free high quality resampling tool for ImageMagick users
« Reply #111 on: July 26, 2014, 05:11:01 am »

RobidouxSoft + deconvolution is TOP for down-sampling!
Bye Bye Cornelius Lanczos...  ;D

Hi,

'RobidouxSoft' (with sharpening) is very good, in combination with deconvolution/sharpening. The reason I tried it was due to it's low halo generation and reasonably good resistance to generating aliasing artifacts (typical risk with down-sampling). The low tendency to produce halos was welcome, because simple deconvolution/sharpening tends to create or increase halos.

As Nicolas said, 'RobidouxSoft' is but one of a series of possible filters in the 'Keys Cubic spline' filter family (which takes 2 parameters 'B' and 'C' to define it's behavior), with the most probable candidates along the 2C+B=1 line (see the earlier posted diagram in reply #98), basically ranging from blurred to sharp, while avoiding blocking and aliasing artifacts as much as possible in such a trade-off.

However, when we consider Nicolas' suggestion to mitigate the typical dark side of edge undershoot halo of e.g. a 'Lanczos2' down-sample with a partially linear gamma adjusted blend of two deconvolutions, also looks very promising. What makes 'Lanczos2' interesting is that it naturally exhibits an even better aliasing suppression than 'RobidouxSoft' (which is indeed blurry and needs a lot of sharpening which restores some aliasing). That's why I am currently experimenting with the 'best' settings to tame the undershoot halo which is further exaggerated by deconvolution/sharpening.

So don't say goodbye to Cornelius yet ... ;)

Cheers,
Bart

« Last Edit: July 26, 2014, 05:13:44 am by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8913
Re: A free high quality resampling tool for ImageMagick users
« Reply #112 on: July 26, 2014, 06:26:10 am »

http://www.clarkvision.com/articles/image-restoration2

Yes, I'm a supporter of the Richardson-Lucy deconvolution capabilities in a (photon-shot) noisy image. On very low noise images, a Van Cittert deconvolution does even better in a fewer number of iterations.

However, ImageMagick unfortunately doesn't have such an option/function, so the best would be to eliminate all sharpening, use a somewhat blurry (down-sampling) filter, and post-process with another application. RL deconvolution also removes some of the upsampling blur (but may reveal residual aliasing and blocking). So I consider still using something like a blurry Keys Cubic spline for a '0' sharpening amount setting, even if I ultimately use something else for amounts larger than absolute zero.

Cheers,
Bart
Logged
== If you do what you did, you'll get what you got. ==

Jack Hogan

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 798
    • Hikes -more than strolls- with my dog
Re: A free high quality resampling tool for ImageMagick users
« Reply #113 on: July 26, 2014, 08:57:00 am »

Hi Bart,  wonderful stuff.

I unfortunately :)  cannot give feedback on the visuals because I will basically have phone only access over the next three weeks.  Thanks for the tutorial up thread,  very informative.

Jack
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #114 on: July 26, 2014, 10:59:19 am »

Bart:
I've not tested it, and I hope it does what I want, but this is what I suggested earlier: Use the luminance gamma blending trick at the deconvolution stage.
convert input.png -depth 16 -set colorspace sRGB -colorspace RGB \
 -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 800x800 \
 \( -clone 0 -gamma 3 -define convolve:scale=^75%%,100 -morphology Convolve DoG:0,0,0.5007503035749775 -gamma .3333333333333333333 \) \
 \( -clone 0  -define convolve:scale=^75%%,100 -morphology Convolve DoG:0,0,0.5007503035749775 \) \
 \( -clone 2 -colorspace gray -auto-level \) \
 -delete 0 \
 -compose over -composite \
 -set colorspace RGB -colorspace sRGB -depth 8 output.png

Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #115 on: July 26, 2014, 11:23:15 am »

...
BTW,  ImageMagick 7 beta is at http://www.imagemagick.org/download/binaries/
Pictus is pointing this out because ImageMagick 7 is HDRI (floating point) by default. This may mitigate rounding when, for example, doing radical gamma (although some of these operations are done with LUTs internally, in which case it does not matter so much; maybe should use -exec Pow 3 instead of -gamma .333333333333333333 etc).
« Last Edit: July 26, 2014, 11:25:33 am by NicolasRobidoux »
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8913
Re: A free high quality resampling tool for ImageMagick users
« Reply #116 on: July 26, 2014, 12:19:16 pm »

Bart:
I've not tested it, and I hope it does what I want, but this is what I suggested earlier: Use the luminance gamma blending trick at the deconvolution stage.

Yes, that's what I've been trying, but it doesn't work for some reason. It looks like convolving a clone doesn't work as expected, or something like that. I've been trying to find out what's wrong with that, but no success so far.

Cheers,
Bart
Logged
== If you do what you did, you'll get what you got. ==

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #117 on: July 26, 2014, 12:35:04 pm »

Maybe there is a need for more parentheses:
convert \( input.png -depth 16 -set colorspace sRGB -colorspace RGB \
 -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 800x800 \) \
 \( -clone 0 -gamma 3 -define convolve:scale=^75%%,100 -morphology Convolve DoG:0,0,0.5007503035749775 -gamma .3333333333333333333 \) \
 \( -clone 0  -define convolve:scale=^75%%,100 -morphology Convolve DoG:0,0,0.5007503035749775 \) \
 \( -clone 2 -colorspace gray -auto-level \) \
 -delete 0 \
 -compose over -composite \
 -set colorspace RGB -colorspace sRGB -depth 8 output.png
Also my command line is a bastard child of unixese and windowese.
P.S. I do get results that look fine. Just not sure if they are the way they are supposed to.
« Last Edit: July 26, 2014, 12:42:57 pm by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #118 on: July 26, 2014, 12:42:16 pm »

See Blending Kernel with the Identity Kernel at http://www.imagemagick.org/Usage/convolve. The command I've been using under linux has a different meaning in Windows because of the double percent. http://www.imagemagick.org/Usage/windows
« Last Edit: July 26, 2014, 12:44:52 pm by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #119 on: July 26, 2014, 12:53:32 pm »

Bart:
I am enclined to think there is a bug. Unless you are happy with using double double percent ("%%%%") in windows, I think that you may want to file something at http://www.imagemagick.org/discourse-server/viewforum.php?f=3. You'll get help, at least. If I had time I'd search myself through the list.
Logged
Pages: 1 ... 4 5 [6] 7 8 ... 24   Go Up