DeFlicker - mean intensity stabilizer
Plugin for Avisynth 2.5
Version 0.4 - August 16, 2004
Copyright (C)2004 Alexander G. Balakhnin (aka Fizick).
http://bag.hotmail.ru
DeFlicker plugin can remove old film intensity flicker by temporal mean luma smoothing.
Also it can correct blinding of automatic gain control after flashes.
The luma stabilizing not only improves visual impression, but can help to following noise reduction.
Technical details
I use simplified
AURORA method of intensity flicker correction, from book:
Restoration of Archived Film and Video
Van Roosmalen, Peter Michael Bruce
Thesis Delft University of Technology - with ref. - with Summary in Dutch
Printed by Universal Press, Veenendaal
Cover photo: Philip Broos
ISBN 90-901-2792-5
Copyright © 1999 by P.M.B. van Roosmalen
(A project named AURORA was initiated in 1995, stimulated by the European Union ACTS program.
The acronym AURORA stands for AUtomated Restoration of ORiginal film and video Archives.)
The book file: "Restoration of
Archived Film and Video 1999.pdf" may be found in Internet.
The method used statistical degradation model for multiplicative and additive intensity flicker.
Filter analyze the evolution of mean intensity and its variation for frames in series.
Than it try to remove flicker, i.e. to smooth inter-frame mean luma deviation.
The filter works by partial compensation of current frame contrast and intensity
to the values as in previous frames . This estimation and compensation
is propagated from some distant base frame to current, as evolution process.
For stability, the compensation is not full. When filter detects scenechange (as big mean luma or variation difference),
the new base frame is set to current.
My simplifications in current version: filter is applied to whole frame (without
regions, globally)
motion is not used, etc.
The filter is similar to Antiflicker plugin by Donald Graft, but use different smoothing method.
The Antiflicker filter with window method is very good for pure periodic flicker, if window size may be properly set.
If not, Antiflicker may or over-smooths the clips, or not remove all flicker. Timeline random access is not supported.
The VirtualDub Deflick plugin use same method, works in 2 pass and ... is for VirtualDub.
The Defliker may works more delicate, with controlled smoothing, and works in 1 pass. Of course, not perfectly.
Probably, similar propagation method is used in new MSU-Deflicker plugin for VirtualDub.
Some comments about filter name - yes, the name is similar to Antilicker for Avisynth by D.Graft,
Antiflicker for VirtualDub by D.Graft (sometimes named as "Deflicker", but with filename Deflick.vdf) ,
Deflick-Prepare/Process by Alessandro Malanca, and MSU-Deflicker .
But I decide to complicate this some more :-)
Parameters of DeFlicker:
1 - input clip
percent (0.0 to 100.0, default=85) - influence of previous frame mean luma
(in percent) for temporal luma smoothing
lag (integer, default=25) - max distance to base frame for process of mean luma
estimation and compensation
noise (0 to 255, default=10) - luma noise std deviation (due to motion etc)
scene (0 to 255, default=40) - threshold for new scene (mean luma difference, or
std variations doubled difference)
lmin (0 to 255, default=0) - output luma min
lmax (0 to 255, default=255) - output luma max
border (0 to ?, default=0) - border width at all edges (in pixels), which
not used for estimation
info (default=false) - show info and borders on frame
debug (default=false) - produce debug info for debugview utility.
Using for flicker removing
When amateur films (16 or 18 or 24 fps) is transferred to video (25 or 30 fps)
by simple projection method, the very big intensity flicker is produced.
Even if special (per-frame) transfer apparatus is used, some flicker also exists
due to non-steady (old !) film optical properties.
The default parameters set must be quite good. But you may tune its.
Load video clip, set "info" parameter to true, analyze info (frames luma difference etc),
and set appropriate scene parameter (or others).
Simple sample script:
Avisource("input.avi")
loadplugin("deflicker.dll")
converttoYV12()
DeFlicker(scene=30)
Using for correction of blinding of automatic gain control
All modern camcorders have automatic gain control with some rise and fall times.
After sudden intensity changes (due to scene change or some flashes), the gain become small,
then smoothly restored to normal. Some frames is recorded as too dark.
I can propose some restoration method (may be not original), with deflicker filter.
But it must be applied not forward in time, but backward, reverse
(with estimation and compensation from future frames to current one).
It can be done with using of Avisynth command "Reverse" ,
but in my filter it can be done simply by setting Lag to negative values.
While dark frames (after flash) is processed, the filter will not use any flashed frame for luma smoothing.
At flashed frame, the filter must detect a scene change, also as at first frame before it.
Combining using
The best results for films restoration within Avithynth probably may be achieved, for example, with a sequence:
1.Color, brightness correction (mostly insensitive to luma variation)
2. Global motion compensation (DePan - insensitive to luma variation)
3. Mean intensity stabilizer (Deflicker - sensitive to global motion (however and to local too) )
4. Local motion compensator (MVTools - sensitive to luma variation)
5. Temporal spots removing (DeSpot - sensitive to luma variation)
6 Temporal noise reduction (RemoveDirt, Dust, etc - sensitive to luma variation)
7 Spatial smoothing (Vaguedenoiser, etc - insensitive to luma variation)
8 Global motion stabilizing (DepanCompensate - insensitive to luma variation)
9 Coding
Note 1. It is listed only to show the DeFlicker place.
Note 2. I still did not complete that sequense for my films :-)
Features and limitations of current version
1. Works only in YV12 and YUY2 color format.
2. Directly works only with progressive clips (films).
For interlaced sources, you may use Avisynth functions SeparateFields and Weave.
3. Not very good scenechange detector in current version.
4. Now (since v.0.4) is needed in Integer SSE CPU (Pentium3, Athlon)
5. Tested with Avisynth 2.5.3, 2.5.5.
License
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
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.
Please consider to make some donation to be registered user.
Compiling
I use free MS VC++ Toolkit 2003 with MS Platform SDK.
Use make file "makefile" with command:
nmake
(note: copy lost nmake.exe and
cvtres.exe from Platform SDK directory Bin\win64 to Bin ).
Version changes:
Version 0.1, June 3, 2004 - not public (beta!).
Version 0.2, June 5, 2004 - add reverse mode, info (still beta!).
Version 0.3, June 6, 2004 - add show border in info mode (still beta!).
Version 0.4, August 16, 2004 - add YUY2 support (still beta!), some speed
increase (ISSE optimized).