F2QSharp


Author V. C. Mohan
17 May 2021

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. As these dll s are not thread safe this function operates in MT_SERIALIZED state.

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 by using a hamming function reduces ringing at expense of sharpening. These two operators have effect on processed amplitude of the image, experiment 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.

7

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 frad integer 10 to 50 30
Whether hamming function to be used ham boolean true / false true
Whether u,v planes to be sharpened uv boolean true / false false
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 parameters:-
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 using hamming window. Left top input, right blurred using
F2QBlur(psf = "focus",x = 18,y =8, uv = true)
#left bottom with 
F2QSharp(F2Qb,psf = "focus",x = 18,y =8, uv = false,wn = 0.05,scale = 0.4, fr = 20, ham = true)
#On bottom right with
F2QSharp(F2Qb,psf = "focus",x = 18,y =8, uv = false,wn = 0.05,scale = 0.4, fr = 20, ham = false)

Example text file:
1
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