Author V. C. Mohan
29 Dec 2016

F2QSharp function operates in frequency domain and requires for 32 bit avisynth+ FFTw3 32 bit dll or for 64 bit avisynth+ FFTw3 64 bit dll, to be in the path.

Given the estimate of blur present, F2QSharp function tries to sharpen the image through frequency domain inversion.

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

All 3 color (planes) of RGB formats and planar YUV444 if opted (set uv as true) are processed. Otherwise only luma (Y) is processed.

Inverting in frequency domain can lead to instabilities and to counter this white noise is added, which while stabilising reduces effectiveness and so need to experiment and compromised. The radius of designed inversion filter in spatial domain can be specified. 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 exhaustively to arrive at optimum scaling parameter 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.

Sharpening larger blur can produce noticeable ringing especially at edges of image. Cropping result may be a solution.
As the exact blurring PSF was known in the examples, the results look good. In real life blurring PSF is not known and so inversion likely to fail.

The text file to read for user input psf must conform strictly to following :
1.Must have number 1 in first line.
2. Second line first integer is number of values present in each row. The second value on this line is number of rows. A maximum of 16 X 16 rows and columns can only be specified,
Third line onwards PSF values in rows and columns. The values are separated by space. Entries are in floating point.

F2QSharp is thread safe. SetFilterMTMode("F2QSharp", MT_NICE_FILTER).

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 or PSF given in a text file psf string "line" for linear, "focus" for out of focus or "file" "line"
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
scaling to be applied post processing scale float 0.01 to 1000000 1.0
Radius of filter in spatial domain, as %age of smaller of the frame dimensions fr float 0.01 to 39.99 10
Full path and name of text file in which PSF is given. txt string a valid file name must be specified for psf = "file" option none

#Usage examples. These also demonstrate the artifacts produced and need to select proper scale value:-

f2Qs = F2QSharp(F2Qb,psf = "file", x = 6, y = 2, uv = true,wn = 0.05,scale = 0.4, fr = 20, txt = "C:\avi_plugins\FQPlus\blurr.txt")
### effect of amount of motion blur
## using F2QBLUR as input
F2QSharp(line = true,x = 2, y = 2fr = 20,wn = 0.05,scale = 0.45)
F2QSharp(line = true,x = 8, y = 4,fr = 30,wn = 0.05,scale = 0.375)

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

###effect of filter radius
F2QBlur( line = false, x=8,y = 0)
F2QSharp(line = false,x = 8, y = 0,fr = 20,wn = 0.08,scale = 0.45)
F2QSharp(line = false,x = 8, y = 0,fr = 39,wn = 0.08,scale = 0.45)
F2QSharp(fqb8,line = false,x = 8, y = 0,fr = 60,wn = 0.08,scale = 0.45)
FR8 = F2QSharp(fqb8,line = false,x = 8, y = 0,fr = 80,wn = 0.08,scale = 0.45)
st1 = stackvertical(last, fr2,fr4)
st2 = stackvertical(fqb8, fr6,fr8)

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 = F2QBlur( line = false, x=2,y = 0)
fqb4 = F2QBlur( line = false, x=4,y = 0)
fqb8 = F2QBlur( line = false, x=8,y = 0)
fqb16 = F2QBlur( line = false, x=16,y = 0)

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

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

Degree of defocus of input
Left input Right restored image. scale was kept constant
### effect of white noise value wn

Top left Original, Top right blurred input, scale kept constant

### example of an unstable(?) situation
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.
Example text file:
6 6
0 0 0 0 0.15 1.0
0 0 0 0.15 1.0 0.15
0 0 0.15 1.0 0.15 0
0 0.15 1.0 0.15 0 0
0.15 1.0 0.15 0 0 0
1.0 0.15 0 0 0 0 
To my index page down load plugin To Avisynth