Pages: 1 2 [3] 4 5 ... 24   Go Down

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

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #40 on: July 20, 2014, 08:35:02 am »

So, what you were basically saying was: "Put this rings image through downsampling with the new methods and see what happens? You'll see that the "gamma 3 negative" version is worse than the other."?

Yep, although I realise it was not designed/optimized for downsampling in particular.

It's not bad, the Linear/Gamma3 variant is better than the Gamma 3/Gamma 3 variant though.
« Last Edit: July 20, 2014, 08:38:00 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 #41 on: July 20, 2014, 01:28:41 pm »

Based on the fact that the 1/8 downsampling of the rings image with the luminance-weighted blend of the results of resampling through linear RGB and gamma 2 beats the others (gamma 3 among others), from now on I'll probably stick to this has the central "experimental scheme".
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #42 on: July 20, 2014, 02:59:26 pm »

Based on the fact that the 1/8 downsampling of the rings image with the luminance-weighted blend of the results of resampling through linear RGB and gamma 2 beats the others (gamma 3 among others), from now on I'll probably stick to this has the central "experimental scheme".

Okay, so the initial scheme but with one linear, and one Gamma 2 adjusted linear, resampled layer, blended with a 'boring' luminance alpha mask, and a restoration to an sRGB gamma space. Seems like a good compromise for a flexible up/down-sample algorithm.

That would then be the following in Windows batch file dialect:
convert ( input.png -depth 16 -set colorspace sRGB -colorspace RGB ) ^
 ( -clone 0 -filter LanczosRadius -distort Resize 800%% ) ^
 ( -clone 0 -gamma 2 -filter LanczosRadius -distort Resize 800%% -gamma 0.5 ) ^
 ( -clone 1 -colorspace gray -auto-level ) ^
 ( -clone 2 -clone 1 -clone 3 -compose over -composite ) ^
  -delete 0-3 ^
  -set colorspace RGB -colorspace sRGB output.png

I'll also use that for further optimizations and tests.

Thanks,
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 #43 on: July 20, 2014, 03:08:38 pm »

Exactly, except that it can be made a bit shorter/fast/less memory hungry:
convert ( input.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 output.png
or, in unixese,
convert \( input.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 output.png
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #44 on: July 20, 2014, 04:02:05 pm »

Exactly, except that it can be made a bit shorter/fast/less memory hungry:

Great, especially for upsampling it can help to reduce memory requirements.

However, I did see (after differencing the file version results and boosting contrast) a tiny bit of difference in a few pixels near the borders.
I need to explore some more ...

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 #45 on: July 21, 2014, 04:49:49 am »

TTBOMK, ImageMagick does not analyse the pipeline to prevent "trivial conversions". Most likely, this is where the difference comes from: the data conversion/buffer copy should be the identity in infinite precision arithmetic/"perfect" memory management... but is not.
« Last Edit: July 21, 2014, 06:57:57 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #46 on: July 21, 2014, 11:22:02 am »

Fred Weinhaus has added a number of results to http://www.imagemagick.org/discourse-server/viewtopic.php?f=22&t=25935#p113483.
He turned the final results to 8 bit so they don't take so much space by adding -depth 8 just before the output file name.
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #47 on: July 21, 2014, 01:30:21 pm »

Fred Weinhaus has added a number of results to http://www.imagemagick.org/discourse-server/viewtopic.php?f=22&t=25935#p113483.
He turned the final results to 8 bit so they don't take so much space by adding -depth 8 just before the output file name.

That gives a nice impression. The Gamma 3 variants are not bad on these crops, but the amount of aliasing they introduce is not clear from the posted examples. Maybe adding a small version corner crop of the Rings (Zoneplate) target, will help in getting that alternate side of the coin across. If needed, I have a 16-b/ch PNG version (AdobeRGB profile embedded, therefore Gamma 2.2) of the Rings target available.

I've also implemented the new linear+Gamma 2 blend as default resampling method, with your more efficient code version, in my Windows Batch script file tool (attached). I've also added the option to downsample in linear gamma (with/without sharpening), which currently just uses a single layer resampling with the LanczosRadius filter. The added sharpening will create halos, but they are perceptually invisible for web-publishing when viewed at 100% zoom. I'm still optimizing that, because I want to restrict clipping that may also result.

Cheers,
Bart
« Last Edit: July 21, 2014, 02:02:50 pm by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==

Pictus

  • Full Member
  • ***
  • Offline Offline
  • Posts: 216
    • Retouching
Re: A free high quality resampling tool for ImageMagick users
« Reply #48 on: July 21, 2014, 05:49:12 pm »

WoW!
Excellent script!!
Thanks!!!

BTW, does anybody have a Windows x64 ImageMagick compiled with HDRI and OpenCL enabled?
Logged

Jack Hogan

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 797
    • Hikes -more than strolls- with my dog
Re: A free high quality resampling tool for ImageMagick users
« Reply #49 on: July 21, 2014, 06:14:02 pm »

I've also added the option to downsample in linear gamma (with/without sharpening), which currently just uses a single layer resampling with the LanczosRadius filter. The added sharpening will create halos, but they are perceptually invisible for web-publishing when viewed at 100% zoom. I'm still optimizing that, because I want to restrict clipping that may also result.

Excellent, Bart, now downsampling too.

1) May I ask how the sharpening works?  Is it final-size appropriate?
2) Does it make sense to capture sharpen before a 2-3x downsampling?

Thank you.
Jack
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #50 on: July 21, 2014, 06:22:06 pm »

WoW!
Excellent script!!
Thanks!!!

Hi,

You're welcome. To show a bit more of what it's about, I've attached a sample of the down-sampling quality as it is right now. I've used the well known Lighthouse image from the PhotoCD sampler CD, and reduced the full resolution to 25%, with sharpening (make sure you watch it at real 100% zoom resolution, by downloading it). Aliasing is very well controlled, fully automatic.

Quote
BTW, does anybody have a Windows x64 ImageMagick compiled with HDRI and OpenCL enabled?

Unfortunately not me. The Q16 version does keep all 8 cores on my computer busy, but precision is limited to 16-bits per channel data round offs.

Cheers,
Bart
« Last Edit: July 21, 2014, 07:37:46 pm by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #51 on: July 21, 2014, 07:12:56 pm »

Excellent, Bart, now downsampling too.

1) May I ask how the sharpening works?  Is it final-size appropriate?

Hi Jack,

Yes, the down-sampling is a little better than with the algorithm that Nicolas suggested, but that algorithm isn't all that bad at down-sampling either (it's just better at up-sampling).

It assumes that you started with a decent image. Then down-sampling will effectively result in oversampled detail (more than 1 input pixel per output pixel, preferably more than 2) , which is guaranteed to be the case below 50% of the original size. That automatically means that the highest possible spatial frequencies in the image are at the Nyquist frequency. What follows is that we need to use a proper resampling filter, of which ImageMagick offers several, for down-sampling in order to avoid aliasing artifacts.

When we can assume that the finest detail is reasonably bandwidth limited (by the filtering) before down-sampling, we can in principle use the same generic post-sharpening for all down-sampled images to mitigate the blur that is inherent in (proper) down-sampling. Deconvolution is a detail restoration procedure, and a simple non-iterative version of it is High-pass sharpening. Given the purpose of web-publishing, one can 'exaggerate a little', which is subject to taste.

The High-pass implementation I chose, was aimed at doing it's best at the extreme detail case, so it would not be too obvious (less efficient) in lower detail situations, such as between 50-100% of the original size (or larger). The code line:
-define convolve:scale=^65%%,100 -morphology Convolve DoG:0,0,0.45
will add an amount of 65% of the High-pass effect of a 0.45 sigma pixel radius Difference of Gaussians relative to an impulse signal filter. One can vary the amount of 65% to taste by changing the code, or choose a larger radius by changing the radius.

So, yes it is final size appropriate, especially below 50% of the original size, while assuming 'normal' viewing distances.

Quote
2) Does it make sense to capture sharpen before a 2-3x downsampling?
No it doesn't, that is, assuming we are talking about Capture sharpening. It might even hurt (by increasing aliasing) when using lower quality resampling filters than the ones offered by ImageMagick. However, with Creative 'sharpening' we usually address larger spatial frequencies and local contrast, which would affect tonality or local contrast more than actual sharpness, and thus would still affect the down-scaled image.

Cheers,
Bart
« Last Edit: July 21, 2014, 08:37:56 pm 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 #52 on: July 22, 2014, 03:41:10 am »

Quick notes (gotta run):
1) I am pretty sure that it used to be possible to get HDRI Windows binaries of IM by downloading ImageMagick 7 instead of 6 from the main IM site. Not sure these are maintained anymore. I also vaguely remember astrophysics guys putting out some HDRI versions as well. (Fuzzy pre-coffee memory.)
2) Bart: For downsampling, could you test EWA LanczosSharpest 4 (with halo reduction)?
Logged

Jack Hogan

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 797
    • Hikes -more than strolls- with my dog
Re: A free high quality resampling tool for ImageMagick users
« Reply #53 on: July 22, 2014, 03:56:43 am »

Hi Jack,

Yes, the down-sampling is a little better than with the algorithm that Nicolas suggested, but that algorithm isn't all that bad at down-sampling either (it's just better at up-sampling).

It assumes that you started with a decent image. Then down-sampling will effectively result in oversampled detail (more than 1 input pixel per output pixel, preferably more than 2) , which is guaranteed to be the case below 50% of the original size. That automatically means that the highest possible spatial frequencies in the image are at the Nyquist frequency. What follows is that we need to use a proper resampling filter, of which ImageMagick offers several, for down-sampling in order to avoid aliasing artifacts.

When we can assume that the finest detail is reasonably bandwidth limited (by the filtering) before down-sampling, we can in principle use the same generic post-sharpening for all down-sampled images to mitigate the blur that is inherent in (proper) down-sampling. Deconvolution is a detail restoration procedure, and a simple non-iterative version of it is High-pass sharpening. Given the purpose of web-publishing, one can 'exaggerate a little', which is subject to taste.

The High-pass implementation I chose, was aimed at doing it's best at the extreme detail case, so it would not be too obvious (less efficient) in lower detail situations, such as between 50-100% of the original size (or larger). The code line:
-define convolve:scale=^65%%,100 -morphology Convolve DoG:0,0,0.45
will add an amount of 65% of the High-pass effect of a 0.45 sigma pixel radius Difference of Gaussians relative to an impulse signal filter. One can vary the amount of 65% to taste by changing the code, or choose a larger radius by changing the radius.

So, yes it is final size appropriate, especially below 50% of the original size, while assuming 'normal' viewing distances.
No it doesn't, that is, assuming we are talking about Capture sharpening. It might even hurt (by increasing aliasing) when using lower quality resampling filters than the ones offered by ImageMagick. However, with Creative 'sharpening' we usually address larger spatial frequencies and local contrast, which would affect tonality or local contrast more than actual sharpness, and thus would still affect the down-scaled image.

Cheers,
Bart

Excellent, thank you, that 's one fine looking downsized lighthouse.   This is truly useful stuff for all those times (and it's most of the time in my case) that we fine tune the full-rez image but save it without printing, downsizing a copy of it to HDTV size for posting or emailing instead.

One note that may help others: the batch file at first did not work on my Win7 system apparently because MS-DOS was getting confused as to which 'convert' command to use, Imagemagick's or its own.  Inserting the following line just below '@echo off' fixed it:

set PATH=x:...\ImageMagick;%PATH%

with x:...\ImageMagick the full path of where the ImageMagick executables are located on your computer.  Note that %PATH% needs to be AFTER the path to ImageMagick.

Jack
« Last Edit: July 22, 2014, 05:01:12 am by Jack Hogan »
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #54 on: July 22, 2014, 04:02:58 am »

2) Bart: For downsampling, could you test EWA LanczosSharpest 4 (with halo reduction)?

Will do. Changing the filter is easy, although it will probably require tweaking of the sharpening parameters.

UPDATE, based on:
-filter Lanczos -define filter:lobes=4 -define filter:blur=0.88451002338585141
Okay, my first comparisons reveal small differences. Some I like, some I don't. It's a trade-off, as usual.

What I like is that it does indeed produce marginally sharper results, however it also produces a slightly more pronounced halo and a tiny bit of ringing. The halo is not a surprise, since a Lanczos windowed Sinc will produce a more pronounced first lobe as the support size is increased. This will allow to get a slight improvement for an unsharpened downsample, so I may change the no-sharpening downsample to use this filter. The ringing is too minor to be noticed at normal display viewing distances.

However, subsequent sharpening might start to boost the ringing as well, so I'll probably leave the LanczosRadius filter in place there (until I find an even better filter for additional sharpening).

Cheers,
Bart
« Last Edit: July 22, 2014, 05:31:05 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 #55 on: July 22, 2014, 06:31:03 am »

Bart: Double checking: You know that LanczosSharpest 4 is meant to be used with -distort Resize, yes?
Otherwise, this matches my experience. The upsampled noise power spectrum plot you showed for it in http://www.luminous-landscape.com/forum/index.php?topic=77949.20 is pretty impressive and it did well in the tests of my former student Adam Turcotte web.cs.laurentian.ca/nrobidoux/misc/AdamTurcotteMastersThesis.pdf so I was hoping your results would not match my rough opinion :)
Also, I thought to tell you that it probably should be used to get rid of the final sharpening step, but it sounds like you figured this out pretty quickly.
« Last Edit: July 22, 2014, 06:39:47 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #56 on: July 22, 2014, 06:36:09 am »

If you add final sharpening, I would be very tempted to use the now "standard" EWA LanczosSharp, overcoming the softness with post-sharpening.
It's amazingly good at anti-aliasing.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #57 on: July 22, 2014, 06:37:59 am »

Note that, to the best of my recollection, the lighthouse original is quite strongly sharpened.
In an ideal toolchain, you don't sharpen before downsampling.
P.S. If this is what you used to evaluate EWA LanczosSharpest 4, this pre-sharpening may have skewed the evaluation.
« Last Edit: July 22, 2014, 06:52:13 am by NicolasRobidoux »
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #58 on: July 22, 2014, 06:38:13 am »

Excellent, thank you, that 's one fine looking downsized lighthouse.   This is truly useful stuff for all those times (and it's most of the time in my case) that we fine tune the full-rez image but save it without printing, downsizing a copy of it to HDTV size for posting or emailing instead.

Jack, that's correct, and given the high quality of the ImageMagick filter implementation, I wouldn't worry about prior Capture sharpening or not, ImageMagick will probably handle it just fine, either way. Of course, proper Capture sharpening doesn't introduce halos either, but that's a different topic.

Quote
One note that may help others: the batch file at first did not work on my Win7 system apparently because MS-DOS was getting confused as to which 'convert' command to use, Imagemagick's or its own.  Inserting the following line just below '@echo off' fixed it:

set PATH=x:...\ImageMagick;%PATH%

with x:...\ImageMagick the full path of where the ImageMagick executables are located on your computer.  Note that %PATH% needs to be AFTER the path to ImageMagick.

Indeed, however, if one allows the ImageMagick installer to do it (see third attachment), that is already taken care of as it prefixes the new Path to Imagemagick to the existing startup file. The drawback of using that option is that new installations will keep prefixing new paths to the PATH environment variable, so one needs to occasionally edit the older locations out (always tricky, so don't make mistakes).

The drawback of your suggestion, is that one needs to edit the batch script file(s) one uses to point to the correct path, each time a new version is installed. Also, the path is expanded each time the script is run until restating the computer (could be solved by saving the old path as a variable (e.g. SET OLDPATH=%PATH%) at the start, and restoring it at the end of the script). So, it's up to the users how they want to tackle this.

Cheers,
Bart


The Windows specific 'convert' topic is documented here in considerable detail.
« Last Edit: July 22, 2014, 06:43:28 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: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #59 on: July 22, 2014, 06:41:58 am »

Bart: Double checking: You know that LanczosSharpest 4 is meant to be used with -distort Resize, yes?

Yes. Thanks for verifying.

Quote
Also, I thought to tell you that it probably should be used to get rid of the final sharpening step, but it sounds like you figured this out pretty quickly.

Just like chaos, trade-offs are a fact of life ;)

Cheers,
Bart
Logged
== If you do what you did, you'll get what you got. ==
Pages: 1 2 [3] 4 5 ... 24   Go Up