proper scaling of the Jinc filter for EWA use

Discuss digital image processing techniques and algorithms. We encourage its application to ImageMagick but you can discuss any software solutions here.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: proper scaling of the Jinc filter for EWA use

Post by imaggie »

Yes, I think gamma is relevant. I was suggesting this to Fred in recent days w.r.t. deblur et al.

Gamma is a non-linear transformation and so it will have an affect on the result. I would expect this to affect colour balance more than ringing/blurring.

Is there some kind of statistic that IM could pull of the images to assess if it is preserving the palette or altering it?
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

imaggie wrote:...
Is there some kind of statistic that IM could pull of the images to assess if it is preserving the palette or altering it?
Give a spin to nip2: http://www.vips.ecs.soton.ac.uk.
Last edited by NicolasRobidoux on 2012-01-03T09:04:05-07:00, edited 1 time in total.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: proper scaling of the Jinc filter for EWA use

Post by imaggie »

Hi Nicola,

if you have time could you look at this post I sent to the bugs forum?

Your expertise in maths may help clarify what IM is or isn't doing and whether it is correct.
http://imagemagick.org/discourse-server ... =3&t=20102

If fft is in some way producing less than rigorous results it would almost certainly affect EWA though maybe not to an extent where it would be strikingly obvious.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

imaggie wrote:...
If fft is in some way producing less than rigorous results it would almost certainly affect EWA though maybe not to an extent where it would be strikingly obvious.
Sorry: Need to get back to masters thesis supervision -> I don't have time to dive into code I've not touched. (This being said, I sure will use FFT at some point so I'd love bugs to be fixed.)
Maybe you want to compare with the results you get with nip2/vips? (Don't use bleeding edge 7.27: odd-numbered means unstable, and John Cupitt's getting ready for a major VIPS API change. In fact, so is Anthony for ImageMagick, but I know that bugs are occasionally slipping by the VIPS API change.)

(Oops! I should have posted this reply in the Bugs thread.)
Last edited by NicolasRobidoux on 2012-04-30T11:02:07-07:00, edited 1 time in total.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: proper scaling of the Jinc filter for EWA use

Post by imaggie »

Thanks for the vips link (needs a www. BTW) .

I was not expecting you to dig the code just some thoughts on the DFT but if you're busy , 'nuff said.

Sorry I was forgetting that jinc is a convolution kernel in the EWA context. No DFT. So irrelevant to this thread.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

I'm going to have a look at the girl in red. Here is the code (having renamed the image original.png). I added EWA Robidoux and EWA RobidouxSharp for good measure.

Code: Select all

convert original.* -filter LanczosSharp -distort resize 800% LanczosSharp.png

convert original.* -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.9891028367558475 -define filter:lobes=3 -distort resize 800% newLanczosSharp.png

convert original.* -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=.9264075766146 -define filter:lobes=3 -distort Resize 800% JincJinc3blur3overr3.png

convert original.* -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.88549061701764 -define filter:lobes=3 -distort Resize 800% JincJinc3blur0p88549061701764.png

convert original.* -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=3 -resize 800% oSincSinc3.png

convert original.* -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.943159799432847711 -define filter:lobes=4 -distort Resize 800% JincJinc4blur4overr4.png

convert original.* -define filter:filter=Jinc -define filter:window=Jinc -define filter:blur=0.88451002338585141 -define filter:lobes=4 -distort Resize 800% JincJinc4blur0p88451002338585141.png

convert original.* -define filter:filter=Sinc -define filter:window=Sinc -define filter:lobes=4 -resize 800% oSincSinc4.png

convert original.* -define filter:c=.3689927438004929 -filter Cubic -distort Resize 800% RobidouxSharp.png

convert original.* -distort Resize 800% Robidoux.png
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

I definitely like the idea of optimizing, not in terms of no-op, but in terms of minimizing the maximum possible overshoot/undershoot anywhere when upsampling. Definitely on the to do list.
User avatar
fmw42
Posts: 25562
Joined: 2007-07-02T17:14:51-07:00
Authentication code: 1152
Location: Sunnyvale, California, USA

Re: proper scaling of the Jinc filter for EWA use

Post by fmw42 »

I was just about to send you the girl in red, though my version is smaller. It is nice to know where it came from as I had no idea. Here is one more image that might be interesting, but again I have no idea about the copyrights.

Image
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

Nothing really jumps at me with the girl in red. Except maybe that EWA Robidoux is pretty good if you don't mind some aliasing. And that (new)LanczosSharp, again, is nicely antialiased without overly offensive halo. But the sharpened 3-lobe EWA work well too. (I've not looked at it a ton. I want to try asian_lady.jpg which seems, at least on my Samsung screen, to have more natural tonal balance at original resolution.)

The nice thing about the girl in red is that it does not appear to have been sharpened.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

With asian_lady.jpg, you have to contend with obvious JPEG artifacts. So, EWA Lanczos (and (new)LanczosSharp) win, by virtue of having the strongest antialiasing. EWA Robidoux looks good too. And EWA Quadratic http://imagemagick.org/discourse-server ... 22&t=19820 actually gives the most pleasing result:

Code: Select all

convert original.* -filter Quadratic -distort Resize 800% Quadratic.png
Better than orthogonal Mitchell-Netravali (too aliased)

Code: Select all

convert original.* -filter Mitchell -resize 800% oMitchell.png
and orthogonal and EWA Cubic (too soft, the EWA being less so---no surprise here)

Code: Select all

convert original.* -filter Cubic -resize 800% oCubic.png
convert original.* -filter Cubic -distort Resize 800% Cubic.png
P.S. EWA "JincJinc3blurr3over3" is also quite good. Sharp without being annoyingly jaggied or haloed. Probably better than EWA Robidoux.
Last edited by NicolasRobidoux on 2012-01-04T08:52:21-07:00, edited 2 times in total.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

It looks to me like the girl in red is linear RGB, which is why think look a bit strange when shown in most viewers, which tend to assume sRGB.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

The one thing that has been left out so far, and which is more important for many people, is downsampling (reducing size).

USM (unsharp mask) appears to be a fairly standard final step. So, the sharpened EWAs may be better than the less sharpened ones.

I also know that a client decided on EWA Robidoux over several other methods (I'll try to track them down) based on the visual opinions of an internal panel. This being said, they apply rather strong JPEG compression to the result, so maximum sharpness is less desirable in their particular situation.

P.S.
The methods compared for producing thumbnails and small size images were:
  • Orthogonal cubic, quadratic and triangle
  • EWA Robidoux, Lanczos and LanczosSharp
No USM was applied at the end result. The downsampling result went straight to JPEG compression.

The finalists were Robidoux and LanczosSharp (the current version, not the "new" version, which sits between the current LanczosSharp and then plain (Jinc) Lanczos).

And the eventual winner was EWA Robidoux.

I certainly am not saying that this is a complete comparison. But it does give an indication of what works well. In particular, it suggests that, at least with heavy JPEG compression and not particularly high quality input images, the maximally sharpened EWAs are most likely overkill. The "balanced" ones when the input is not overly sharp and the output is not destructively compressed much? Dunno.
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: proper scaling of the Jinc filter for EWA use

Post by imaggie »

Code: Select all

        lanczos3=" lz=zz/4.0;  (abs(lz)<1) ? sinc(zz) / sinc(lz) :  white"
Just a quick aside. After much head banging I finally realised that to do the same thing in a deblur context, where the jinc or sinc is in the denominator , you need to divide by the window function not multiply.

Seems embarrassingly obvious now but I thought I'd throw it out in case it saves anyone else making the same mistake.
NicolasRobidoux
Posts: 1944
Joined: 2010-08-28T11:16:00-07:00
Authentication code: 8675308
Location: Montreal, Canada

Re: proper scaling of the Jinc filter for EWA use

Post by NicolasRobidoux »

@Imaggie: Unlike Fred Weinhaus, I know nothing about lens correction.

Is the assumption you're working under that the "scene" was blurred with some convolution (which you model with what kernel) to which you want to want to apply the "inverse convolution" to undo the "damage" as much as possible?
imaggie
Posts: 88
Joined: 2011-12-19T04:15:36-07:00
Authentication code: 8675308

Re: proper scaling of the Jinc filter for EWA use

Post by imaggie »

This is not lens correction, it's motion blur and focussing error. ( If you're interested in that, look at GIMP's lens "distortion" , which can be used with negative values as a lens corrections. IIRC, it's a matrix op rather than convo ).

very briefly, motion blur is a convolution with a line segment, poor optical focusing with a circular disc. Removing such defects is done by deconvolution: division by sinc/jinc respectively , which is why I chipped in here. The two tasks have many similarities.

I instantly saw the similarity when I saw the ringing in Fred's cameradeblur script's output. Having worked a bit on scaling in Gimp with lanczos , I thought I could simply apply the same here to get an improvement.

After leading myself ( and Fred ) astray for a couple of weeks it just clicked today that the window should be acting the other way round when the sinc/jinc is in the denominator. Now it has started to produce the results I expected two weeks ago.

I'm going to tidy the script , which is currently in tatters, and then some of the more subtle windows that you have produced here will probably get I try.

I'm convinced there is a close parallel , though it is not truely symmetrical since in deblur it is common to add in a bit of noise to avoid the ill-conditioned division by a functions with zeros.

It's taken me a hell of a lot more time than I intended but I've learnt a lot on the way and the results , though not earth-shattering will bring a useful improvement to the output.
Post Reply