FQRestore


Author V. C. Mohan
Last modified Date June 17, 2014

FQRestore function operates in frequency domain and requires libFFTw3f-3.dll or FFTw3.dll or fftw3f.dll available at Fizick's site, to be in the path.

Given the type and estimate of blur present, FQRestore function tries to deblur the image. Part of image ( either rectangular or oval) can be processed leaving the rest intact. The selected window can linearly move over length of clip. The dimensions of window however would remain same.

In case of oval window the coordinates to be specified or those of the superscribing rectangle.

In case of motion blur the line is assumed to be symmetric about origin, the end coordinates of blur line will be -x, -y and x,y. In case of out of focus blur the xcoordinate is the radius of blur.

While all 3 color planes of RGB formats are processed, in case of YUY2 and YV12 only Luma (Y) is restored.

Inverting in frequency domain can lead to instabilities and to counter this white noise is added, which while stabilising reduces effectiveness. The radius in spatial domain of the inversion operator can be controlled. This can provide some desirable reduction of ringing. These two operators have effect on processed amplitude of the image. Therefore it is essential to experiment exhaustily to arrive at optimum parameters for any particular situation.

For some situations for a particular set of parameters the result may be highly focussing in parts and in other parts amplitudes may be zero. One such condition is given in the examples. One must be careful about such situations.


For blur amounts over 3 ringing may be noticeable especially due to edges of image. Cropping result may be a solution.

Details of parameters
Description Name Type Limits Default
Input clip clip must have the fields separated none
Whether blur is linear as in motion blur or out of focus type line boolean true for motion blur, false for focus true
white noise to add wn float 0.0001 to 0.99 0.05
blur line right end x coordinate or radius of focus blur. Line assumed symmetric about origin x integer 2 to 1/8 frame width 6
blur line right end y coordinate. Line assumed symmetric about origin y integer - 1/8th to 1/8th frame height 2
left x coordinate of blur window lx integer 0 to frame width - 8* x 0
top y coordinate of blur window ty integer 0 to frame height - 8* absolute value of y 0
right x coordinate of blur window rx integer 8 * x to frame width - 1 width - 1
bottom y coordinate of blur window by integer 8* abs y to frame height -y height - 1
left x coordinate of blur window at end frame elx integer 0 to frame width - 8* x andensure window remains in frame lx
top y coordinate of blur window at end frame ety integer 0 to frame height - 8* absolute value of y and ensure window remains in frame ty
Whether window is oval or rectangular oval boolean true for oval, false for rectangular false
Radius of filter in spatial domain, as %age of smaller of the frame dimensions fr float 0.01 to 99.99 30
scaling of output scale float 0.000001 to 10000000 0.45

#Usage examples. These also demonstrate the artifacts produced and need to select proper scale value:-
### effect of amount of motion blur
## using FQBLUR as input
fqb2 = FQBlur( line = true, x=2,y = 2,oval = false)
fqb4 = FQBlur( line = true, x=4,y = 3,oval = false)
fqb8 = FQBlur( line = true, x=8,y = 4,oval = false)
fqb16 = FQBlur( line = true, x=16,y = 5,oval = false)


FR2 = FQRestore(fqb2,line = true,x = 2, y = 2,oval = false,fr = 20,wn = 0.05,scale = 0.45)
FR4 = FQRestore(fqb4,line = true,x = 4, y = 3,oval = false,fr = 30,wn = 0.05,scale = 0.4)
FR8 = FQRestore(fqb8,line = true,x = 8, y = 4,oval = false,fr = 30,wn = 0.05,scale = 0.375)
FR16 = FQRestore(fqb16,line = true,x = 16, y = 5,oval = false,fr = 40,wn = 0.05,scale = 0.35)

st1 = stackvertical(fqb2,fqb4,fqb8, fqb16)
st2 = stackvertical(fr2, fr4,fr8, fr16)
stackhorizontal(st1,st2)
return (last)


effect of amount of motion blur
below are results. Left is blurred image. Right restored image

###effect of filter radius
fqb8 = FQBlur( line = false, x=8,y = 0,oval = false)
FR2 = FQRestore(fqb8,line = false,x = 8, y = 0,oval = false,fr = 20,wn = 0.08,scale = 0.45)
FR4 = FQRestore(fqb8,line = false,x = 8, y = 0,oval = false,fr = 40,wn = 0.08,scale = 0.45)
FR6 = FQRestore(fqb8,line = false,x = 8, y = 0,oval = false,fr = 60,wn = 0.08,scale = 0.45)
FR8 = FQRestore(fqb8,line = false,x = 8, y = 0,oval = false,fr = 80,wn = 0.08,scale = 0.45)
st1 = stackvertical(last, fr2,fr4)
st2 = stackvertical(fqb8, fr6,fr8)
stackhorizontal(st1,st2)

effect of filter radius
below are results. top Left is original. top Right blurred image used as input for all. note amplitude variation.

# Degree of defocus of input
fqb2 = FQBlur( line = false, x=2,y = 0,oval = false)
fqb4 = FQBlur( line = false, x=4,y = 0,oval = false)
fqb8 = FQBlur( line = false, x=8,y = 0,oval = false)
fqb16 = FQBlur( line = false, x=16,y = 0,oval = false)

FR2 = FQRestore(fqb2,line = false,x = 2, y = 0,oval = false,fr = 20,wn = 0.08,scale = 0.45)
FR4 = FQRestore(fqb4,line = false,x = 4, y = 0,oval = false,fr = 20,wn = 0.08,scale = 0.45)
FR8 = FQRestore(fqb8,line = false,x = 8, y = 0,oval = false,fr = 20,wn = 0.08,scale = 0.45)
FR16 = FQRestore(fqb16,line = false,x = 16, y = 0,oval = false,fr = 20,wn = 0.08,scale = 0.45)

st1 = stackvertical(fqb2,fqb4,fqb8, fqb16)
st2 = stackvertical(fr2, fr4,fr8, fr16)
stackhorizontal(st1,st2)

Degree of defocus of input
Left input Right restored image. scale was kept constant
### effect of white noise value wn
fqb = FQBlur( line = false, x=4,y = 0,oval = false)

FR1 = FQRestore(fqb,line = false,x = 4, y = 0,oval = false,fr = 20,wn = 0.01,scale = 0.45)
FR2 = FQRestore(fqb,line = false,x = 4, y = 0,oval = false,fr = 20,wn = 0.02,scale = 0.45)
FR4 = FQRestore(fqb,line = false,x = 4, y = 0,oval = false,fr = 20,wn = 0.04,scale = 0.45)
FR8 = FQRestore(fqb,line = false,x = 4, y = 0,oval = false,fr = 20,wn = 0.08,scale = 0.45)
st1 = stackvertical(last,fr1, fr2)
st2 = stackvertical(fqb,fr4, fr8)
stackhorizontal(st1,st2)

effect of white noise value wn
Top left Original, Top right blurred input, scale kept constant

### example of an unstable(?) situation
FQBlur(tr, line = false, x=16,y = 5,oval = false)
fqb16 = crop(40,20,-40,-20)
FR16 = FQRestore(fqb16,line = false,x = 16, y = 5,fr = 33,wn = 0.01,scale = 0.095)
FR16a = FQRestore(fqb16,line = false,x = 16, y = 5,fr = 35,wn = 0.01,scale = 0.65)
FR16b = FQRestore(fqb16,line = false,x = 16, y = 5,fr = 37,wn = 0.01,scale = 0.25)
return (stackvertical(fqb16,fr16b,fr16a, fr16))

unstable(?) situation. Top large focus blurred input.Lower 3 processed with very small difference in parameter fr (Filter radius). Note to control amplitude scale value needed was highest for the central one.
To my index page down load plugin To Avisynth