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

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

NicolasRobidoux

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

I'll try two things: use -set instead of -define. And only set/define the property once (I did it inside every parenthesis for safety and because I don't remember how things are passed around under IM6).
« Last Edit: July 26, 2014, 01:01:51 pm by NicolasRobidoux »
Logged

NicolasRobidoux

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

Reading the documentation, I need to put single quotes around the specification in linux, but you need to use double quotes in Windows. Bastard command line indeed :(
Logged

NicolasRobidoux

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

Unixese (IM6 Q16: running this on OSX, not linux) that seems to work:
convert input.png -depth 16 -set colorspace sRGB -colorspace RGB \
 -define filter:c=0.1601886205085204 -filter Cubic -distort Resize 800x800 \
 \( -clone 0 -gamma 3 -set option:convolve:scale '^75%%,100' -morphology Convolve DoG:0,0,0.5007503035749775 -gamma .3333333333333333333 \) \
 \( -clone 0  -set option: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 new.png
Watch out for the double quotes: they are ImageMagick's, not the conversion of linux single quotes to Windows double quotes.
« Last Edit: July 26, 2014, 01:31:38 pm by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #123 on: July 26, 2014, 01:38:40 pm »

For comparison, here is the result of downsampling with the bilinear filter through linear light.
convert input.png -depth 16 -set colorspace sRGB -colorspace RGB \
 -filter Triangle -resize 800x800 \
 -set colorspace RGB -colorspace sRGB -depth 8 BilinearLinearRGB.png
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #124 on: July 26, 2014, 01:49:33 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

Hi Nicolas,

It is working, I missed a '^'  . I have yet to analyse if it makes a significant enough difference, and I'm also investigating something else. Another thing is that I also check the results for aliasing, with the Rings-target down-sampled to 200x200 of the original. A simple Lanczos2 down-sample looks similar/better than a sharpened 'RobidouxSoft', unless I can constrain the sharpening halo further. A Bi-linear/Triangle filter looks slick, until one looks at the aliasing performance ..., it's also anout those pesky trade-offs between the four quadrants in the Keys Cubic study.

Cheers,
Bart

P.S. I'm getting better at translating between Windowese and Linuxese.
« Last Edit: July 26, 2014, 01:52:34 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 #125 on: July 26, 2014, 01:50:21 pm »

Also had a look at the fly downsampled with RobidouxSharp through linear RGB (no more and no less) and it looks quite good too.
Will have to look at more results and candidate methods. But indeed linear light is a harsh mistress.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #126 on: July 26, 2014, 03:37:29 pm »

These are just three examples out of many possibilities, but RobidouxSharp through linear RGB looks best of the three to me.
Logged

NicolasRobidoux

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

I also checked His Holiness. RobidouxSharp through linear RGB does look good here too. Not that there can't be something else better of course.
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8914
Re: A free high quality resampling tool for ImageMagick users
« Reply #128 on: July 26, 2014, 06:13:02 pm »

These are just three examples out of many possibilities, but RobidouxSharp through linear RGB looks best of the three to me.

Yes, it is sharp, but check with the Rings target, and you may prefer another filter ..., especially if you want to be able and control sharpening, yet limit the risk of generating aliasing artifacts.

I've done my initial analysis of the 'RobidouxSoft' filter and it is an improvement to deconvolve in a blended linear light scenario, compared to the earlier non-blended approach. It suffers less from dark edge side undershoots, and holds up decently with aliasing torture tests (Rings target). More normal subject matter may survive other filters, but I prefer to avoid unpleasant surprises.

For the time being (which may only last a little while), I'll adjust the down-sampling optimized method to this improved method in the next release of the Windows Batch script file version. I have one more optimization to do before releasing that Version 1.1.3, and that is the deconvolution radius which is likely to be slightly different in different gamma spaces. I've also increased the deconvolution kernel's support from 5x5 to 7x7 by adjusting the DoG parameters:
DoG:0,0,0.5007503035749775
to
DoG:3,0,0.5007503035749775
. This should allow to increase the precision to 1 in 16-bit numbers. Maybe overkill, but why drop a few bits when they come almost for free?

The difference will be a slightly slower speed of execution (each pixel will be composed of a weighted average sum of a 49 pixel area instead of a 25 pixel area), and the new blended algorithm will do this twice instead of once, but since we're talking about a smaller image size after down-sampling, the toll will remain tolerable for most applications that require optimal quality (TANSTAAFL).

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 #129 on: July 27, 2014, 02:46:33 am »

Bart:
I am a bit concerned that the Rings target being greyscale allows one to differenciate schemes on the basis of types of aliasing that are not the most important. I am way more concerned with colour moire (and tonal drift).
Does it make sense to use a Rings target which uses another colour than white as "1"? The reason for this suggestion is that once you use nonlinear schemes, you need to worry about "colour separation".
In other words, it's not single colour channel aliasing that worries more the most, it's the interference between "independent" aliasing in different colour channels.
Ideally, a monochrome (but not greyscale) Rings image should still be monochrome after resampling. (Of course, monochrome is a bit ambiguous from a perceptual viewpoint but something with proportional RGB channels in linear RGB should work.)
I am not sure, but I think such a test would have killed sigmoidization right off the bat.
P.S. Of course such a target is going to hurt one's eyes, at least when there is color separation. That's kind of the point.
« Last Edit: July 27, 2014, 05:58:05 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #130 on: July 27, 2014, 05:09:30 am »

...it is an improvement to deconvolve in a blended linear light scenario, compared to the earlier non-blended approach. It suffers less from dark edge side undershoots, and holds up decently with aliasing torture tests (Rings target). More normal subject matter may survive other filters, but I prefer to avoid unpleasant surprises...
\o/
Logged

Bart_van_der_Wolf

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

Bart:
I am a bit concerned that the Rings target being greyscale allows one to differenciate schemes on the basis of types of aliasing that are not the most important. I am way more concerned with colour moire (and tonal drift).
Does it make sense to use a Rings target which uses another colour than white as "1"? The reason for this suggestion is that once you use nonlinear schemes, you need to worry about "colour separation".

I'm not exactly sure what you mean. If there is no luminance aliasing, and we resample in linear light, how could there be color aliasing? Maybe you have a specific example in mind to spark an idea or a better torture test (I know that faceted insect eyes are hard).

Quote
In other words, it's not single colour channel aliasing that worries more the most, it's the interference between "independent" aliasing in different colour channels.
Ideally, a monochrome (but not greyscale) Rings image should still be monochrome after resampling. (Of course, monochrome is a bit ambiguous from a perceptual viewpoint...)
I am not sure, but I think such a test would have killed sigmoidization right off the bat.

This Rings image is in 16-bit RGB, with an Adobe RGB profile embedded, it's monochrome, not greyscale. I can easily make a version that has a slightly lower contrast (not too low because that will reduce the visibility of low contrast aliases), to avoid clipping.

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 #132 on: July 27, 2014, 05:18:36 am »

Bart: I'm being vague because I'm not 100% sure of what I mean.
(How to appear smarter than you are: Keep it vague and let other people figure it out. Then take credit.)
-----
Colorspace and gamma conversions are nonlinear. Luminance weighted gamma blending is nonlinear. Once you do something nonlinearly, you risk "separating colors".
Such effects are hidden if you go through a toolchain with an image in which the channel values are the same, and you are doing things in colour spaces in which every channel is treated identically. To see some of the side effects of nonlinearity, you need different values in individual color channels (assuming you are using colour spaces that treat various channels the same way, like linear RGB, sRGB, Adobe RGB, gamma obtained from linear RGB, XYZ, etc, but not LCh, HSL etc if processed sanely).
« Last Edit: July 27, 2014, 10:08:47 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #133 on: July 27, 2014, 05:52:03 am »

Bart:
I may be using the wrong terminology. What I mean is that I'd find more informative the results of processing a rings image that is not "black and white", for example in which "white" is replaced (in 16 bit linear RGB) by [21845,65535,43690], and when producing the "new Rings" test image (in linear light) everything is kept proportional. At least, it would make a better torture test IMHO.
« Last Edit: July 27, 2014, 05:54:02 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #134 on: July 27, 2014, 06:17:47 am »

Bart:
I meant something sort of like this: http://web.cs.laurentian.ca/nrobidoux/misc/RingsAlt.png.
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 ...
(or importing using the embedded profile)?
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.
« Last Edit: July 27, 2014, 10:06:48 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #135 on: July 27, 2014, 06:28:31 am »

Bart:
Am I missing something: When I look at your 1000x1000 Rings original test image, importing it carefully into my favorite open source image manipulation GUI (NIP2), I see aliasing North, South, East and West (but not in the corners). In the original.
???
« Last Edit: July 27, 2014, 06:31:56 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 #136 on: July 27, 2014, 06:39:19 am »

Bart:
Am I missing something: When I look at your 1000x1000 Rings original test image, importing it carefully into my favorite open source image manipulation GUI (NIP2), I see aliasing North, South, East and West (but not in the corners). In the original.
???

Probably caused by gamma differences due to your viewing angle towards your display (anything not perpendicular would cause that). If you're using an LCD display, try moving your head up/down/left right. Do you still see it?

Of course, display zoom must be at 100%, also graphics card settings (larger fonts) may influence how some applications display the real zoom factor.

Cheers,
Bart
« Last Edit: July 27, 2014, 06:43:29 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 #137 on: July 27, 2014, 07:08:45 am »

Probably caused by gamma differences due to your viewing angle towards your display (anything not perpendicular would cause that). If you're using an LCD display, try moving your head up/down/left right. Do you still see it?

Of course, display zoom must be at 100%, also graphics card settings (larger fonts) may influence how some applications display the real zoom factor.

Cheers,
Bart
It's not viewing angle. It does make sense that this may be a rendering effect. The OSX Preview tool (viewing on the laptop screen) is no better (but shows things at a different size than NIP2 even when requesting original size). I'll let this go for now.
P.S. On my MacBook Pro laptop, I see some aliasing when enlarged with (hopefully: linux tool shoved into OSX) as neutral an open source viewer as I know. Hmmm. But this is not calibrated monitor, so who knows.
« Last Edit: July 27, 2014, 10:04:30 am by NicolasRobidoux »
Logged

NicolasRobidoux

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

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

Bart_van_der_Wolf

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

I have analyzed the DoG radius settings again, because for down-sampling in linear light and (de)convolution, they are now used in Linear and gamma space. The differences are not huge, but we might as wel use the marginally better radii (even less risk of halo creation). I've also changed the kernel support size from 5x5 to 7x7 as I indicated earlier.

Here are the relevant code lines, in Windowese Batch script file dialect:
( -clone 0 -gamma 3 -define convolve:scale=^75%%,100 -morphology Convolve DoG:3,0,0.4981063336734057 -gamma 0.3333333333333333333 ) ^
 ( -clone 0 -define convolve:scale=^75%%,100 -morphology Convolve DoG:3,0,0.4806768770037563 ) ^

I also (for the time being) changed the resampling method used when an amount of '0' sharpening is selected. Instead of a 'RobidouxSoft' Cubic spline with a zero amount of sharpening, it switches to a Quadratic Bi-linear (Triangle filter, in linear light resampling. While boring and soft, Bi-linear does have a bit more tendency towards generating aliasing (e.g. compared to an amount of '1'), so I may change this '0' amount behavior.

Attached is the updated complete Windows Batch script file.

Cheers,
Bart

P.S. Small edit to the code was implemented, better '0' amount sharpening results.
« Last Edit: July 27, 2014, 08:00:37 am by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==
Pages: 1 ... 5 6 [7] 8 9 ... 24   Go Up