DeFreq

Interference frequency remover

Plugin for Avisynth 2.5
Version 0.7 - April 28, 2006
Copyright (C)2004-2006 Alexander G. Balakhnin aka Fizick.
http://avisynth.org.ru

DeFreq is a filter that can remove some interfering frequencies from video frames.

It can be used for removal of regular vertical, horizontal or inclined stripes from some analog TV captures without any image quality decreasing.

Sample image with filter's work

Stack vertical:

1 - TV source with interference (cropped);
2 - Defreq v.0.6 show and info mode (2 search windows);
3 - Cleaned output;
4 - Input-output difference.

Technical info

DeFreq uses Fast Fourier Transform method for frequency selecting and removing.

It is a spatial filter, and works as a follows:

  1. get frequency spectrum by forward FFT transform of frame image;
  2. search some defined spectrum window (windows) for local peak (maximum, extremum, most intense frequency);
  3. remove from spectrum a frequency at this sharp peak and some similar by amplitude neighbors in search window;
  4. optional remove highest frequencies by low pass Butterworth filter (for blurring, smoothing);
  5. get output frame by inverse FFT transform of cleaned spectrum.

Function parameters

Defreq(clip, float "fx", float "fy", float "dx", float "dy", float "sharp", float "fx2", float "fy2", float "dx2", float "dy2", float "sharp2", float "fx3", float "fy3", float "dx3", float "dy3", float "sharp3", float "fx4", float "fy4", float "dx4", float "dy4", float "sharp4", float "cutx", float "cuty", int "plane", int "show", bool "info", bool "measure")

first parameter - input clip
fx - window center frequency x-component for local peak search (float percent from 0.0 to 100.0, default= 10.0)
fy - window center frequency y-component for local peak search (float percent from -100.0 to 100.0, default= -10.0)
dx - half-width of search window, (float percent, default =1.5).
dy - half-height of search window, (float percent, default =2.0).
sharp - threshold of the peak to background relation (in search window) for cleaning (float, default=50.0)
fx2 - second window center frequency x-component for local peak search (float percent from 0.0 to 100.0, default=0 - disabled)
fy2 - second window center frequency y-component for local peak search (float percent from -100.0 to 100.0, default=0 - disabled)
dx2 - half-width of second search window, (float percent, default =1.5).
dy2 - half-height of second search window, (float percent, default =2.0).
sharp2 - threshold of the peak to background relation (in second window)for cleaning (float, default=50.0)
fx3 - third window center frequency x-component for local peak search (float percent from 0.0 to 100.0, default=0 - disabled)
fy3 - third window center frequency y-component for local peak search (float percent from -100.0 to 100.0, default=0 - disabled)
dx3 - half-width of third search window, (float percent, default =1.5).
dy3 - half-height of third search window, (float percent, default =2.0).
sharp3 - threshold of the maximum frequency to background relation (in third window) for cleaning (float, default=50.0)
fx4 - fourth window center frequency x-component for local peak search (float percent from 0.0 to 100.0, default=0 - disabled)
fy4 - fourth window center frequency y-component for local peak search (float percent from -100.0 to 100.0, default=0 - disabled)
dx4 - half-width of fourth search window, (float percent, default =1.5).
dy4 - half-height of fourth search window, (float percent, default =2.0).
sharp4 - threshold of the peak to background relation (in fourth window) for cleaning (float, default=50.0)
cutx - frequency x-component cutoff for low pass filter (float percent from 0.0 to 300.0, default = 0, disabled)
cuty - frequency y-component cutoff for low pass filter (float percent from 0.0 to 300.0, default = 0, disabled)
plane - color plane to clean, 0-Y, 1-U, 2-V (default = 0)
show - show frequency spectrum surface and search windows (default = 0)
0 - normal processing;
1 - show current frame spectrum;
2 - show temporal average spectrum;
info - type found peaks info on frame (default = false)
measure - select fastest FFT method by speed measure (longer init stage) instead of simple estimation (default=true)

Features and limitations

  1. Works only in YV12 and YUY2 color format.
  2. Directly works with progressive clips. For interlaced sources, probably you must use SeparateFields etc.
  3. Tested with Avisynth v2.5.5-2.5.6.
  4. Defreq uses fast external FFTW library version 3 (http://www.fftw.org) as Windows binary DLL (compiled with gcc under MinGW by Alessio Massaro), which support for threads and have AMD K7 (3dNow!) support in addition to SSE/SSE2.It may be downloaded from ftp://ftp.fftw.org/pub/fftw/fftw3win32mingw.zip. You MUST put FFTW3.DLL file from this package to some directory in path (for example, system folder C:\WINNT\SYSTEM32). Defreq will NOT work without it!
  5. Not very fast, not assembler optimized.
  6. Since v.0.4, horizontal frequency is relative to spectrum image width (about half of plane width), from 0 to 100 %, and vertical frequency is relative to spectrum image half-height (plane height), from -100 to 100%.
  7. Since version 0.4, frequency values fx,fy, etc are independent from crop, but must be scaled after resize!

Simple sample script

Avisource("input.avi")
loadplugin("defreq.dll")
DeFreq(fx=30,fy=-40)

Attention! It is calling syntax example only. Unlike most another filters, there are NO good DeFreq parameter values for general use!
It will not clean anything (but slow down the processing), if its settings are not exactly correspondent to your picture.

How to use

You must temporary add show and info parameters, visually analyze frequency spectrum surface, and adjust parameters fx,fy to place rectangular search window at local peak of spectrum (bright spot or cross), which is correspondent to interference frequency.

Firstly look to generated sample frequency stripes at the right top corner, and try make them similar to your picture interference pattern (right bottom area). The sample stripe slope is dependent from fy/fx ratio, and the step between sample stripes is dependent from fx,fy absolute values (hint - you may use some AviSynth script parameter to preserve fy/fx ratio).

Then look to spectrum sufrace, and fine tune the search window position.
The small fxis near left edge of the spectrum image, and the large fx (up to 100) is near right edge.
Since v0.6, the large negative fy values is at bottom of the spectrum image, the large positive fy (up to 100) is at top of the spectrum image, the small fy is at middle of height.

Set fx=0 for strictly horizontal frequency interference stripes, or set fy=0 for strictly vertical stripes.

Mode show=2 make frequency spectrum peaks more visible by temporal averaging of frames power spectral density. Just play your video clip (preferrably dynamic scenes), and tune fx,fy.

You may tune other parameters to set sharpness threshold, color plane, add other search windows, add low pass filter.
Hint - "sharp" word is become UPPERCASE (in info mode), when peak with value above threshold is detected.

Additional info

The filter discussion is at http://forum.doom9.org/showthread.php?s=&threadid=82978

There are also similar new filters FanFilter and FQuiver (by vcmohan).

License

This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2 as published by
the Free Software Foundation.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.

Documentation is distributed under CreativeCommons BY-SA 3.0 license.

Please consider to make some donation.

Version changes:

Download DeFreq version 0.7

Return to main page