Pages: 1 ... 6 7 [8] 9 10 ... 24   Go Down

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

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #140 on: July 27, 2014, 07:46:19 am »

May I suggest
-filter Quadratic -distort Resize
instead of
-filter Triangle -resize
? (Untested.)
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #141 on: July 27, 2014, 07:48:07 am »

Bart:
Indeed, when I move my head the aliasing changes!

That shows how critical it is! It's fighting with the regular pixel grid of the LCD display, and even a tiny amount of gamma change will show. The presumably 8-bit/channel display driver does not help either. I'm glad it wasn't something else, because the pixels also have maximum contrast, which is not exactly how the theoretical non-discretely quantized / analog pattern would look.

Cheers,
Bart
« Last Edit: July 27, 2014, 08:02:39 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: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #142 on: July 27, 2014, 08:01:20 am »

May I suggest
-filter Quadratic -distort Resize
instead of
-filter Triangle -resize
? (Untested.)

Yes! It behaves better on preventing aliasing, is only marginally blurrier, and as far as halo generation is concerned, there is none.
I've re-packed the ZIP archive with the code changed, kept the same version (1.1.3), and adjusted my earlier post.

Cheers,
Bart
« Last Edit: July 27, 2014, 09:24:44 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 #143 on: July 27, 2014, 09:12:08 am »

Yes! It behaves better on preventing aliasing, is only marginally blurrier, and as far as halo generation is concerned, there are none...
In the tensor (orthogonal = -resize, not -distort Resize) world, quadratic B-spline smoothing is the "forgotten middle child" in the chain of B-splines obtained by successive box filtering on a unitorm grid:
Box, bilinear (linear splines, called Triangle in ImageMagick), quadratic B-spline smoothing (Quadratic), B-spline smoothing (cubic as people normally assume, called Spline in ImageMagick), ...
In libvips, NIP2, and the Masters thesis of my former student Chantal Racette, there is a related interpolatory scheme called VSQBS (Vertex Split followed by Quadratic B-Spline smoothing), which is sharper, more aliased, and also 100% halo-free, like the standard (ImageMagick) version.
Of course we're using it in a cylindrical way here so that story does not quite apply, but still: A good, simple and cheap, halo free scheme.
An important fact about it: The key disc has radius 1.5. That's .5 less than BC-cubic methods (and .5 more than the Triangle filter.)
« Last Edit: July 27, 2014, 11:36:58 am by NicolasRobidoux »
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #144 on: July 27, 2014, 09:48:02 am »

On the subject of quantifying the halo suppression performance, and sharpness; I've attached the target I use for that purpose. The Slanted edge allows to use the procedure discussed here.

It allows to analyze a 10x oversampled edge profile with a reasonably high contrast. One could use a lower contrast version to specifically target certain brighness ranges, but as it is it gives a good impression of how e.g. roof tops against sky edge transitions would be rendered, and how sharpening affects the resolution and / or acutance.

To keep track of the overall tonality (linearity versus gamma, or sigmoidal tone curve changes), the step-wedge was added, and it also allow to see how the orthogonal (lower contrast) stepped increments of edges are handled. Small edge halos created by down-sampling halos enforce the "Mach band effect" that also human vision uses to improve pattern recognition.

Cheers,
Bart
« Last Edit: July 27, 2014, 04:11:44 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: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #145 on: July 27, 2014, 10:22:00 am »

Note: When you do your torture tests, do you take into account that this AdobeRGB (as opposed to sRGB) by doing something like
convert -set colorspace RGB -gamma 0.4547069271758437 ... -set colorspace RGB -gamma 2.19921875 ...
(and possibly using the embedded profile)?

ImageMagick will happily accept it if one overrides (ignores) any embedded profile. It can also make use of it, but for our tests I let it ignore it, and just assume it's sRGB, let it linearize and then do stuff, and revert it to sRGB. I finally re-assign (not convert) the original profile that was temporarily saved.

I do understand that for a fully color-managed test one would need to start with a formal profile conversion, but not all sample images have a profile attached, so one then would assume it's sRGB, but it might be something else. Also, since most tests use monochrome targets, the color part (illuminant, color primaries, black-point) is not critical at all, we're mainly looking at the dominant Luminance component. The proof of the pudding is of course with real color image content, but that works pretty much as expected, especially with linear gamma blending, although the gamma conversions do worry me a bit but they are for a large part only temporary, and blended with a (more) linear component.

I think that a color version of some of the test targets, or very good stress-test images (like the Dalai Lama image) would ensure that an 'sRGB assignment- Linearize - do stuff - convert back to sRGB' will be acceptable in most cases. After all, we are trying to change as few pixels as possible, only remove some or add some ... and who knows what colors are correct there. We can only assume.

It would be a different thing if we wanted to change the entire image's tone curve, boosting shadows and controlling highlights. That would lead to contrast and brightness changes that can (and perceptually should) also change colors.
 
Quote
The reason is that if you do conversions that assume it is an sRGB image at the input stage, this may introduce mild aliasing right there.
P.S.Of course importing with the profile should work too.

Yes, and that is possible when the input images are in fact profiled. One can then use the ImageMagick '-profile' option to assign, or convert from the original profile through the conversions and back to the original profile. But that would for the moment complicate the code a little, with probably few differences in the end (QED).

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 #146 on: July 27, 2014, 10:33:27 am »

...The Slanted edge allows to use the procedure discussed here...
Cool!
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #147 on: July 27, 2014, 10:38:51 am »

Bart:
The reason I am concerned about pretending that Adobe RGB is the same as sRGB, or vice versa, is not about primaries or even gamma discrepancies. It's about the fact that sRGB has a linear segment near 0 before turning into a gamma space :( Adobe RGB is a "pure" gamma space :)
This worry is erased if an accurate enough conversion to some linear light is done.
-----
I do agree that most likely this has insignificant impact given that we do round trips.
« Last Edit: July 27, 2014, 11:39:31 am by NicolasRobidoux »
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #148 on: July 27, 2014, 10:58:35 am »

Cool!

I think so, but I'm biased ...

It does assume photographic source images which can apparently often be characterized by having a Gaussian blur profile (due to multiple blur sources usually adding to a Gaussian distribution, see the central limit theorem). This doesn't allow a good fit to modeling halo overshoots, but it can approximate the underlying blur source (which I used to determine the optimal DoG radii).

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

Les Sparks

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 305
    • http://www.ncsparks.com
Re: A free high quality resampling tool for ImageMagick users
« Reply #149 on: July 27, 2014, 03:10:28 pm »

Bart and Nicolas
Thank you for this interesting and informative discussion--some of which is over my head. I've tried the tool and find it does produce great results.
Thanks again.
Les
Logged

Pictus

  • Full Member
  • ***
  • Offline Offline
  • Posts: 216
    • Retouching
Re: A free high quality resampling tool for ImageMagick users
« Reply #150 on: July 27, 2014, 03:55:27 pm »

The script is now stunning, thank you!
I was thinking...
It is possible to have default values if we just click enter?

BTW, ImageMagick 7 beta have HDRI, but will not work for the script.
http://www.imagemagick.org/discourse-server/viewtopic.php?t=22934
Logged

NicolasRobidoux

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

The script is now stunning, thank you!
I was thinking...
It is possible to have default values if we just click enter?

BTW, ImageMagick 7 beta have HDRI, but will not work for the script.
http://www.imagemagick.org/discourse-server/viewtopic.php?t=22934
Pictus: The command line syntax of 7 is different (but I would think this does not matter here) but most importantly, because results are not clamped to 0,65535 between operations, I would guess that one needs to clamp results before passing things through gamma. (Also, last I checked, IM 7, for some reason, did not work smoothly for me. Maybe there is a bug in the latest beta that was not there before.) I'll look into this when I have a minute...
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #152 on: July 27, 2014, 04:31:55 pm »

Bart and Nicolas
Thank you for this interesting and informative discussion--some of which is over my head. I've tried the tool and find it does produce great results.
Thanks again.

Hi Les,

You're welcome.

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

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #153 on: July 27, 2014, 04:41:23 pm »

The script is now stunning, thank you!
I was thinking...
It is possible to have default values if we just click enter?

Hi,

I'll see what I can do. I'll have to figure out which 'errorlevels' are generated on empty input, after that it should be easy.

EDIT: I think I've solved it, just needs some more testing to make it 'monkey proof'.

Quote
BTW, ImageMagick 7 beta have HDRI, but will not work for the script.
http://www.imagemagick.org/discourse-server/viewtopic.php?t=22934

Because '7' is a Beta version and might not be stable, I have not yet investigated which commands and options have changed. I'd hate to think my own code is faulty and waste time looking for bugs when it may be just fine.

Cheers,
Bart
« Last Edit: July 27, 2014, 07:16:13 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 #154 on: July 28, 2014, 07:33:14 am »

Wish:
Users: Instead of just giving thumbs up or thumbs down, could you describe what you like or don't like, and specify which of the three main options you use, and possibly the context of your use?
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #155 on: July 28, 2014, 09:54:03 am »

Okay, attached is version 1.1.4, this time I've only done some cosmetic script changes, like implementing a Default response input that can be accepted by just hitting the <Enter> key. It unfortunately doesn't show those defaults when just hitting the <Enter> key (unless I create a lot more verbose input text), but it  always uses the same ones. I've chosen the default inputs to be: 800x800 as output size 'fit within' maxima, choose the optimized Down-sampling algorithm, and use a sharpening Amount of 100.

These default choices are based on a common requirement for most photographers, to produce web publishing output from large input image files. If one has predominantly different default requirements, they are relatively simple to change in the Batch script file, and of course different keyboard input can always be given to override the default choices for the image at hand.

I plan on working some more on Profile conversions (if applicable) and output compression quality (currently produces uncompromised but large minimum compression amount output, in case one needs to work some more on the image and re-compress with as little loss as possible). But these are more icing on the cake, and I have some other things that I want to address as well (like really prevent clipping when extreme sharpening is required, and optimizing the up-sampling quality). I am already working on those as well.

An interesting tidbit; one can also use a negative sharpening amount with the 'optimized for down-sampling' algorithm, which will obviously does the reverse of sharpening, it will blur the finest detail/edges.

Actually, this could also be a consideration for upsampling where we want to use a sharpness preserving filter method, but want to reduce some edge halo overshoots with a targeted blur. The difficulty is that, in contrast with down-sampling to less than 50% of the original size, the upsampling (blur) radius to use is variable. Also, blurring will not be restricted to edges (unless an edge mask is used), but will also affect smoother regions with the same size detail as the filter. Those pesky trade-offs again ...

Another thing that tends to produce a high level of control with upsampling is, to enlarge to a larger than required size, and sharpen that upon down-sampling to the final size. Of course that will require more memory (larger convolution kernels), and thus takes longer to execute, in addition to the parameter tweaking requirement depending on size (might be a simple function of size, don't know, just thinking aloud).

Some operations, in particular convolutions on large image sizes, could be sped up by performing them as FFT operations in the frequency domain instead of the spatial domain. However, that quickly makes working in floating point precision a requirement rather than an option (and it claims much more application/operational memory, also since image sizes internally scale to integer powers of 2 with padding). A Q16 version of ImageMagick may lose too much precision, although I haven't tested how severe the lost is for our type of operations. Too much stuff to do, can't do it all.

Cheers,
Bart
« Last Edit: July 28, 2014, 10:17:34 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: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #156 on: July 28, 2014, 10:20:15 am »

Wish:
Users: Instead of just giving thumbs up or thumbs down, could you describe what you like or don't like, and specify which of the three main options you use, and possibly the context of your use?

+1

Also would be interesting to know if someone has ported the script to a Mac OS (LinUnixese dialect) version.

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

JRSmit

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 922
    • Jan R. Smit Fine Art Printing Specialist
Re: A free high quality resampling tool for ImageMagick users
« Reply #157 on: July 28, 2014, 02:09:41 pm »

Wish:
Users: Instead of just giving thumbs up or thumbs down, could you describe what you like or don't like, and specify which of the three main options you use, and possibly the context of your use?
my holiday period is about to end and will return home in 2 days. I have been following this with great interest. What version of IM do i need to install?  I am a windows 7 64bit user.
I do have a few images i would love to see upressed.
Logged
Fine art photography: janrsmit.com
Fine Art Printing Specialist: www.fineartprintingspecialist.nl


Jan R. Smit

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #158 on: July 28, 2014, 02:39:49 pm »

my holiday period is about to end and will return home in 2 days. I have been following this with great interest. What version of IM do i need to install?  I am a windows 7 64bit user.
I do have a few images i would love to see upressed.

Hi Jan,

http://www.imagemagick.org/script/binary-releases.php#windows leads to a list of available installers of the current ImageMagick Version 6. I usually install the latest (ImageMagick-6.8.9-6-Q16-x64-dll.exe as of this writing) 16-bit x64 DLL version at the top of that list.

The current upsampling method is quite nice for all sorts of subjects (I just used it to upsample a small graphic chart, which also came out fine), and it may be hard to improve, but we'll try to. It doesn't try to invent detail, like e.g. 'Perfect Resize', but rather stay true to the data that it gets fed (good input quality helps, otherwise it will faithfully enlarge the artifacts that are already there). It manages to maneuver through the minefield of creating new artifacts, carefully avoiding the various traps it encounters.

Enjoy.

Cheers,
Bart

« Last Edit: July 28, 2014, 04:32:46 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 #159 on: July 28, 2014, 03:28:48 pm »

Bart:
There is a possible improvement of the tuning of the EWA Lanczos 3 deblur that I've been thinking of trying out for a long time but never found the time to do carefully.
It goes like this:
Create a synthetic image which is light gray on the left and dark gray on the right, with a perfectly sharp vertical interface between the two.
Now, for all deblurs between the LanczosRadius one and the LanczosSharp one, enlarge this image a lot (128 times, say) with the corresponding EWA Lanczos (with -define filter:blur=value, where value ranges roughtly from .91 to 1).
Crop the result so boundary effects don't matter, and measure the largest undershoot (or overshoot).
Question: Which deblurs are local minimizers? (There may be more than one.)
A similar question concerns the second overshoot (or undershoot).
I expect, without having any solid basis for it, that there is a local minimizer at, roughly, .94 or .95.
-----
There is also a similar optimization that is linked to how I determined that the Keys spline are optimal, among BC-splines, for EWA resampling. It has to do with affine gradients as closely as possible, a very attractive property from a numerical analysis viewpoing. I'll keep that in mind.
The tricky thing is that infinite deblur is most likely the global winner in both cases. It's really local minimizers I'm looking for.
« Last Edit: July 28, 2014, 03:35:25 pm by NicolasRobidoux »
Logged
Pages: 1 ... 6 7 [8] 9 10 ... 24   Go Up