Pages: 1 ... 21 22 [23] 24   Go Down

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

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #440 on: March 28, 2015, 06:30:37 am »

Jack: One thing your report makes clear (suggests, really...), is that Photoshop's bicubic is a good, balanced, scheme. (What a surprise.)

Hi Nicolas,

That's why it's been a default in Photoshop and other image editors for so long, but Mitchell Netravali may be better though. However, it was the poor down-sampling quality (aliasing, blocking ringing, you name it, artifacts) that encouraged me into further investigations. A down-sampling of my windmill image exposes some of the shortcomings in real images, and CGI targets prove its weaknesses.

The EWA approach already helps keeping a natural look and suppress certain artifacts, linear gamma color blending helps (although with some brightening of high spatial frequencies), your gamma conversions help to mitigate the formation of halos. IMHO that all produces superior image quality compared to bicubic (of which Photoshop's is a specific tweaked version).

The brightening of the higher spatial frequency content by the way, can be helpful in inkjet output, which tends to darken high spatial frequencies due to ink diffusion. But I'd prefer a bit more control for e.g. web publishing which doesn't darken those frequencies. I may sign up for the ImageMagick discourse server to ask for some assistance in getting my Blend-if tweak implemented, which might be just what the doctor ordered QED...

Cheers,
Bart
« Last Edit: March 28, 2015, 08:33:52 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 #441 on: March 28, 2015, 06:30:47 am »

To use Bart's script with linear light input and output, get rid of "-set colorspace sRGB -colorspace RGB" and "-set colorspace RGB -colorspace sRGB ^". The first command says "tag the input as being sRGB, and convert it to linear RGB with sRGB primaries" and the second says "tag the result so far as being linear RGB with sRGB primaries, and convert it to sRGB". This does not need to be done since your input is in linear light, and you want to output to the same linear light.
« Last Edit: March 28, 2015, 06:59:22 am by NicolasRobidoux »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #442 on: March 28, 2015, 06:37:23 am »

...(although with some brightening of high spatial frequencies)...
Unfortunately, this is no small matter. Then, again, balancing artifacts is a ... balancing act. (Switch to gamma 2 instead of 3?) I agree with everything else you have to say about the scheme. (Although I'm really not sure about filtering "softer" than post-sharpening. It makes sense. I'm just not sure it's better overall than just downsampling with a filter that has the desired sharpness from the get go.)
P.S. Thank you Bart.
« Last Edit: March 28, 2015, 08:33:45 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 #443 on: March 28, 2015, 07:44:26 am »

Since I have the stuff out, it's easy enough to do one more. Here is 'downsample' with 50% sharpening for reference





Thanks Jack, that shows that when comparing 1%, 50% and 100%, the deconvolution 'amount' that gets mixed in with the original offers a nice range of control. Technically, the 100% will lead to a bit of over-correction halo which may be reduced by changing the Gaussian Radius of the DoG.

When you select a 'Sharpening amount' less than zero (effectively a Gaussian blur), e.g. "-1", you'll be offered an optional deconvolution on the already gamma blending down-sampled image. The Blur width, or radius of blur, can be increased to boost lower spatial frequencies more than the default sharpening radius would. Values between the minimum of 1.0 and 1.28 create a more narrow Gaussian that boosts higher spatial frequencies, above 1.28 it will boost lower spatial frequencies. Since that becomes more a creative sharpening than exact restoration, one needs to experiment with the required amount.

Cheers,
Bart

P.S. One can modify the conditional jump to the optional deconvolution after the ':downsample' instructions to allways add additional convolution if one want to combine the standard radius deconvolution with an additional boost of other spatial frequencies.

Just change:
REM Experimental
IF /i %sharpAmount% LEQ 0 GOTO addDeconv

to:
GOTO addDeconv
« Last Edit: March 28, 2015, 08:29:15 am by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==

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 #444 on: March 28, 2015, 09:11:03 am »

Hi Jack,

Yes, a slanted edge can reveal lots of useful information which is why I use it a lot, but it doesn't give a complete picture. It e.g. can only suggest that aliasing is possible (or not), but it doesn't know if the original subject had enough contrast to even have a modulation that can cause aliasing. A high contrast edge will survive, but say tiny detail (and small features in digital imaging by definition equal low MTF modulation) may suffer enough loss of contrast due to (re)sampling to become unrecoverable, even with deconvolution. Think about detail with 1% subject contrast (still detectabe by humans), and an MTF response of 10%. That would render the detail at 0.1% modulation, which might be below the quantization/noise threshold.

The MTF view also doesn't reveal the sensitivity for the generation of blocking artifacts or ringing artifacts. Especially the EWA types of resampling (-distort Resize) behave in a very 'organic' way, which avoids some of these types of artifacts much better than tensor type of resampling (-resize). The traditional tensor type of resampling has a higher diagonal resolution, which is nice, but it does cause trouble when we start to push things to the limit. That's why I additionally test with a zoneplate (rings) target, and a star target, and challenging images such as my windmil sample image.

The D800e edge crop does have a bit of a ragged, zipper like, edge structure which is something to be wary about, but I don't think it is too much of an issue for downsampling to 25% or less of the original size. Still, for more objective tests I'd prefer to base my conclusions on a really smooth and sharp edge. One can even compare edges with different contrast, to better judge some (unwanted) effects for really high spatial detail. I can easily generate such edges if needed, at any required angle, but the ISO standard uses an arctan(0.1)=5.71 degrees angle so that's what I usually make (a 1/10 pixel slope is also easy for analysis of CGI versions, camera shots are usually rotated slightly and their slope must be measured).

True, but again watch out for bicubic's (poor) blocking and ringing behavior, therefore also other tests are required.

Yes, but keep in mind that lower contrast small detail will have low MTF to begin with, so down-sampling will only reduce the chance of it having a meaningful modulation after down-sampling. Which is also why I use deconvolution sharpening without too much hesitation. Some of the noise is probably unrecoverable already, while still meaningful detail modulation will be boosted.

That's the choice I made after studying the other artifacts. It seems to be better to down-sample a bit soft and deconvolve, than to down-sample sharp and blur/convolve. The sharper down-sampling generates to many compromise artifacts, and resampling generally requires a bit of sharpening to restore some resampling losses but that's not good when there already are artifacts present.

 
Just a small addition, 50% is a neutral 1 iteration deconvolution, 100% is default because it adds a bit of extra sharpening that often is visually pleasing.

Keep the earlier comments in mind. Lower contrast detail may already be lost, so the potentially risky boost of aliasing prone spatial frequencies may be relatively harmless. Also check for other artifacts, the rings target is cruel enough to reveal such poor behavior in 2D. Gamma effects also play a big role in generating or suppressing artifacts.

Cheers,
Bart

Thanks Bart, I appreciate your comments.  I think one of the key take-aways for me from this exercise was realizing that the original MTF curve is multiplied by the inverse of the magnification factor (4 X in this case, with the 25% downsampling we've been doing above) when plotted on the same scale as the downsized MTFs.  Therefore what really matters as far as final image spatial resolution information is concerned is the portion of the original MTF curve that is closest to the origin.  That portion of the curve is more easily associated with what photographers would call 'contrast', rather than 'sharpness', in the original image.  

I had explored this subject here in a different context in the past but only now get the connection  :)

Jack
« Last Edit: March 28, 2015, 09:22:42 am by Jack Hogan »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #445 on: March 29, 2015, 05:03:29 am »

Jack: Comparing the MTF derived from an actual photograph with the MTF after resampling is worthwhile. Thank you.
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 #446 on: March 29, 2015, 04:15:52 pm »

Mon plaisir.
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #447 on: April 03, 2015, 04:58:51 am »

Jack:
Would you be kind enough to the do another set of graphs, ideally showing the output of Robidoux, Mitchell and RobidouxSharp, along with (PS) Bicubic and of course the scaled "raw MTF", and focusing on what happens up to Nyquist (so you may want to raise the "x-axis"). I'm mostly interested in how things are tracked at lowish frequency.
P.S. Have you noticed that Bicubic crosses the Nyquist frequency pretty much at half of the scaled "original" MTF? It's probably not totally coincidental.
« Last Edit: April 03, 2015, 05:02:47 am by NicolasRobidoux »
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 #448 on: April 03, 2015, 11:36:50 am »

Jack:
Would you be kind enough to the do another set of graphs, ideally showing the output of Robidoux, Mitchell and RobidouxSharp, along with (PS) Bicubic and of course the scaled "raw MTF", and focusing on what happens up to Nyquist (so you may want to raise the "x-axis"). I'm mostly interested in how things are tracked at lowish frequency.
P.S. Have you noticed that Bicubic crosses the Nyquist frequency pretty much at half of the scaled "original" MTF? It's probably not totally coincidental.

Sure Nicolas.  The blue lines are Robidouxs and red is Mitchell.  I've noticed that CS5's implementation of bicubic is 'sharper' than Matlab's (which I understand uses the original Key values) so I've show it as the red dots.  Interestingly it tracks Mitchell almost all the way.







Keep in mind that this edge was captured with a camera without an AA filter.

Jack
« Last Edit: April 03, 2015, 11:41:47 am by Jack Hogan »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #449 on: April 04, 2015, 03:25:02 am »

Thank you Jack. It's interesting to see Bicubic overshoot the "original" MTF at .15 cycles/pixel. It's also interesting to see the sharpest filters show a "kink" in the MTF at about .05 (although the original has this strange flat line which ends with a corner, so it could be an echo of that somehow).
Also note that I agree with Bart that the "slanted wedge" is not isotropic enough a situation to tell "everything". It's too close to a separable situation, so issues that arise from the use of a separable (= tensor = orthogonal) filter are pretty much swept under the carpet.
-----
Of course I'm most interested in photographs taken without an AA filter.
-----
I am pretty sure that if the "resampling with adaptive gamma blending" approach is to work best, blending the linear and gamma versions of a RGB channel based on its own value instead of luminance/luma (which is a cross-channel measure) is better overall. In other words, the R channel is resampled based on R values, and only R values, instead of having it depend on the luminance (or luma).
No time to update the comparisions/code, unfortunately.
« Last Edit: April 04, 2015, 03:34:18 am by NicolasRobidoux »
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 #450 on: April 04, 2015, 05:43:32 am »

Thank you Jack. It's interesting to see Bicubic overshoot the "original" MTF at .15 cycles/pixel. It's also interesting to see the sharpest filters show a "kink" in the MTF at about .05 (although the original has this strange flat line which ends with a corner, so it could be an echo of that somehow).

Yes it is, although perhaps what we are seeing is simply due to data quantization.  MTF Mapper computes and outputs MTF (SFR) data from 0 to 1 cycle/pixel in increments of 1/64th of a pixel, that's every 0.0156 cy/px. Because the image has been downscaled 4:1, if the x-axis in cy/px is referenced to the downsampled data, as in this case,  the original curve's needs to be multiplied by four; so it has 1/4 the number of data points on the same scale as downsampled data, only every 0.0625 cy/px.

Therefore for the original MTF curve the actual output is only at 0, 0.06, 0.125, 0.19, 0.25, etc. the dashed line being linear interpolation by matlab's plotting function.  And at those points CS5 bicubic seems to pretty well match it.  We are looking at these curves a little closer than they were meant to be looked at :)

Also note that I agree with Bart that the "slanted wedge" is not isotropic enough a situation to tell "everything". It's too close to a separable situation, so issues that arise from the use of a separable (= tensor = orthogonal) filter are pretty much swept under the carpet.

I see (stored away for future better understanding;-)

Jack
« Last Edit: April 04, 2015, 06:09:16 am by Jack Hogan »
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #451 on: April 26, 2015, 04:44:05 am »

Jack:
Actually, something that is more likely to have "swept things under the carpet" more than using the slanted edge is having downsampled by exactly 50%.
Any halfway (no pun intended) reasonable scheme does OK at 50%, at least visually (if one uses the "align corners" image geometry convention, which is pretty much the standard when downsampling). That is: 50% is the most friendly resampling ratio. There is more difference between schemes when other ratios are used.
« Last Edit: April 27, 2015, 03:35:13 am by NicolasRobidoux »
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 #452 on: April 27, 2015, 03:57:35 pm »

Jack:
Actually, something that is more likely to have "swept things under the carpet" more than using the slanted edge is having downsampled by exactly 50%.
Any halfway (no pun intended) reasonable scheme does OK at 50%, at least visually (if one uses the "align corners" image geometry convention, which is pretty much the standard when downsampling). That is: 50% is the most friendly resampling ratio. There is more difference between schemes when other ratios are used.

I believe I downsampled to 25% of the original.  How friendly is 50% of 50%?
Logged

NicolasRobidoux

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 280
Re: A free high quality resampling tool for ImageMagick users
« Reply #453 on: April 27, 2015, 04:02:31 pm »

I believe I downsampled to 25% of the original.  How friendly is 50% of 50%?
I thought I had read somewhere that you had downsampled in such a way that the total number of pixels after resizing was 25% of the original. In terms of ratios of side lengths, this corresponds to 50% (.5*.5=.25).
Do I remember wrong or misunderstand?
P.S. "The original is soaring at those lofty heights because one of its pixels corresponds to four of the others'." You meant sixteen?
P.S. Indeed, you did use 25% (side length ratio): The ImageMagick command is right there. You did mean sixteen.
25% is not quite as friendly as 50% (although it's still an integer ratio, which means that the convolution weights are exactly the same for every output pixel, just shifted, which may reduce aliasing).
« Last Edit: April 28, 2015, 08:34:34 am by NicolasRobidoux »
Logged

Pictus

  • Full Member
  • ***
  • Offline Offline
  • Posts: 216
    • Retouching
Re: A free high quality resampling tool for ImageMagick users
« Reply #454 on: May 01, 2016, 03:48:14 pm »

ImageMagick 7 with HDRI is out http://www.imagemagick.org/script/binary-releases.php
The script does not work anymore... :(
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #455 on: May 01, 2016, 05:10:56 pm »

ImageMagick 7 with HDRI is out http://www.imagemagick.org/script/binary-releases.php
The script does not work anymore... :(

Hi Pictus.

That's what I was afraid would be happening. Back to the drawingboard, when I have some time.

On the plus-side, the new version's binary distributions will also open up other possibilities, including floating point number calculations and operations in the Fourier (frequency) domain, not only the spatial domain.

Cheers,
Bart
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 #456 on: May 01, 2016, 07:05:45 pm »

Thanks BartvanderWolf.

Hehehehe...
New interesting stuff to play :)

BTW, changing the word "convert" to "magick" makes it work, but something strange happened...
I got purple catchlights with this photo https://dl.dropboxusercontent.com/u/4686872/TAM63_DOG_Pictus-FX.jpg
« Last Edit: October 14, 2016, 03:07:47 pm by Pictus »
Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #457 on: May 02, 2016, 03:58:35 am »

Thanks BartvanderWolf.

Hehehehe...
New interesting stuff to play :)

BTW, changing the word "convert" to "magic" makes it work, but something strange happened...
I got purple catchlights with this photo https://dl.dropboxusercontent.com/u/4686872/TAM63_DOG_Pictus-FX.jpg

Cute dog. Yes, issues will need to be traced to the differences in how the commands now work, in detail. That'll take some time for digging in the documentation, and testing different options or alternative methods.

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

alain

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 455
Re: A free high quality resampling tool for ImageMagick users
« Reply #458 on: September 11, 2016, 10:32:06 am »

Hi

A question:

After making a very good smaller size image, it's probably used on the web ;-)

Most of the time there's a need to make the images rather small in file size.

In the script "-sampling-factor 4:4:4' is used, but I read that this is not optimal from the moment that file size does matter.  I read that "4:2:0" would give better quality for the same file size.
Any suggestions?

Logged

Bart_van_der_Wolf

  • Sr. Member
  • ****
  • Offline Offline
  • Posts: 8911
Re: A free high quality resampling tool for ImageMagick users
« Reply #459 on: September 11, 2016, 11:11:44 am »

Hi

A question:

After making a very good smaller size image, it's probably used on the web ;-)

Most of the time there's a need to make the images rather small in file size.

In the script "-sampling-factor 4:4:4' is used, but I read that this is not optimal from the moment that file size does matter.  I read that "4:2:0" would give better quality for the same file size.
Any suggestions?

Hi Alain,

Feel free to change it for the purpose you use it for. The script can do both downsampling and upsampling, and attempts to preserve the highest quality (in case further processing will be done), which will also result in relatively large file sizes. Actually, 4:4:4 is higher quality, but also larger file size. So for web publishing, you could change it to 4:2:2, or 4:2:0, or 4:1:1, to conserve some file size and speed up the image transfer and page loading times.

Cheers,
Bart
« Last Edit: September 11, 2016, 11:15:32 am by BartvanderWolf »
Logged
== If you do what you did, you'll get what you got. ==
Pages: 1 ... 21 22 [23] 24   Go Up