Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules. |
13th February 2011, 00:45 | #1 | Link |
Registered User
Join Date: Feb 2009
Posts: 48
|
Local Deflicker
I've made local deflicker based on Didée idea (I took it from this post http://forum.doom9.org/showthread.ph...ight=Deflicker)
This deflicker can deflick part of frame. Usage very simple. You run it as follows Code:
dest=dest.LDeflicker() Code:
#based on Didée idea from this post http://forum.doom9.org/showthread.php?t=149465&highlight=Deflicker function LDeflicker(clip o, int "lumatg1", int "lumatg2", int "blury", int "blurc", int "lumatl1") { lumatg1 = default(lumatg1,100) #luma treshold for first pass of soften in GlobalDeflicker lumatg2 = default(lumatg2,lumatg1/2) #luma treshold for second pass of soften in GlobalDeflicker blury = default(blury,115/4) # blur strength for luma in LocalDeflicker blurc = default(blurc,115/4) # blur strength for chroma in LocalDeflicker lumatl1 = default(lumatl1,4) #luma treshold for first pass of soften res=o.GlobalDeflicker(lumatg1, lumatg2) res=res.LocalDeflicker(blury, blurc, lumatl1) return res } # ============================================================================= # Local Deflicker # It affects only part of frame # ============================================================================= function LocalDeflicker(clip o,int "blury", int "blurc", int "lumat1") { res=o # Motion search super=res.MSuper(rfilter=4) prefiltered = medianblurt( res , radiusy=1 , radiusu=0 , radiusv=0 , temporalradius=3 , mc=false , calcborder=true) superfilt = prefiltered.MSuper(rfilter=4) lambdav=1000 backward_vec1 = MAnalyse(superfilt, isb=true, delta=1, search=4, searchparam=2, lambda=lambdav) forward_vec1 = MAnalyse(superfilt, isb=false, delta=1, search=4, searchparam=2, lambda=lambdav) thSCDv=500 backward_comp1 = MFlow(res, super, backward_vec1, thSCD1=thSCDv) forward_comp1 = MFlow(res, super, forward_vec1, thSCD1=thSCDv) res=interleave(forward_comp1, res, backward_comp1) # Source bluring screen = res.gaussianblur(varY=blury, varC=blurc, border=3) #.greyscale # Source deflickering and debanding screenTS = screen.Soften2(lumat1).GradFun2DBmod(thr=1.5,mask=true,mode=3,temp=100,str=4,adapt=-1,radius=3,range=30) # Find the difference in luma between source and deflickered clip calmed = res.mt_makediff(mt_makediff(screen,screenTS),U=2,V=2) # Simple brightness mask for the range that actually is concerned masky = res.mt_lut("x 32 < x 16 - 16 * x 204 > 255 204 x - abs 255 30 / * - 255 ? ?").removegrain(11,-1) # Merge-in the deflickered result by that mask final_dumb = res.mt_merge(calmed,masky,U=2,V=2).SelectEvery(3,1) # We will not process frames when scene schanges o_curr = o p_curr = final_dumb final_dumb=SCSelect(o_curr , o_curr , o_curr , p_curr, dfactor=2.0) return final_dumb } # ============================================================================= # Global defliker # It affects whole frame # ============================================================================= function GlobalDeflicker(clip o, int "lumat1", int "lumat2") { lumat1 = default(lumat1,100) #luma treshold for first pass of soften lumat2 = default(lumat2,lumat1/2) #luma treshold for second pass of soften res=o # Average brightness calculating for the whole frame screen = mt_lutf(res,res,mode="average",yexpr="x",U=1,V=1) #.greyscale # Deflickering for intermaedite clip screenTS = screen.Soften1(lumat1,lumat2) # Find the difference in luma between source and deflickered clip calmed = res.mt_makediff(mt_makediff(screen,screenTS),U=2,V=2) # Simple brightness mask for the range that actually is concerned masky = res.mt_lut("x 32 < x 16 - 16 * x 204 > 255 204 x - abs 255 30 / * - 255 ? ?").removegrain(11,-1) # Merge-in the deflickered result by that mask final_dumb = res.mt_merge(calmed,masky,U=2,V=2) return final_dumb } function Soften1(clip clp, int "luma1", int "luma2") { res = clp luma1 = default(luma1, 8) luma2 = default(luma1, luma1/2) # Luma averaging between 1 and 3 frames # TemporalSoften(clip, int radius, int luma_threshold, int chroma_threshold, int "scenechange", int "mode") res = clp.temporalsoften( 1, luma1, 0, 18, 2) res = res.merge(clp,0.249) res = res.temporalsoften( 3, luma2, 0, 9, 2) return res } function Soften2(clip clp, int "luma1") { res = clp res = medianblurt( res, radiusy=luma1 , radiusu=0 , radiusv=0 , temporalradius=4 , mc=false , calcborder=true , markscenechange=false) return res } ===========
Possible artefacts that script can produce: - tracking in scenes with fast motion. The reason is in probably incorrect prefiltering for motion search and insufficient motion compensation. I've tried to get rid tracking on fast scenes with MMask from MVtools2 but with no success. - banding on smooth sources. This is due to preliminary blurring in LocalDeflicker function (screen variable). There is source clip in lossless format (about 79Mb) http://www.mediafire.com/?7dhb66xphha6whh PS. I am newbie. Edit1: 20110227 - Added scene change detection (thanks to Didée); - Changed some blurring parameters (they are located in very beginning of script. You can play with them); - Motion estimation is calculated now on prefiltered clip for more accuracy - border=3 in LocalDeflicker. Edit2: 20110228 - Changed functions naming
__________________
CPU: Core 2 Quad q9505 RAM: 4G OS: Windows 7 64 Video: Nvidia Geforce 460 GTX VP4 AviSynth: 2.5.8 Last edited by prokhozhijj; 28th February 2011 at 14:47. |
14th February 2011, 00:32 | #3 | Link |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
It's part of the VariableBlur plugin.
|
16th February 2011, 01:02 | #5 | Link |
Leader of Dual-Duality
Join Date: Aug 2010
Location: America
Posts: 134
|
I want to give this a shot just give me a couple minutes
__________________
I'm Mr.Fixit and I feel good, fixin all the sources in the neighborhood My New filter is in the works, and will be out soon |
18th February 2011, 06:41 | #7 | Link | |
Registered User
Join Date: Feb 2009
Posts: 48
|
Quote:
Try to play with temporalradius=4 in DedeeSoften2 function. May be it helps.
__________________
CPU: Core 2 Quad q9505 RAM: 4G OS: Windows 7 64 Video: Nvidia Geforce 460 GTX VP4 AviSynth: 2.5.8 |
|
18th February 2011, 17:17 | #8 | Link |
Registered User
Join Date: Sep 2007
Location: Europe
Posts: 602
|
Setting that to "0" does solve the problem, but it also seems that it kills the flicker correction - I'll need to do more thorough tests when I have time. It's often quite hard to tell if flicker has been fixed unless it's seriously bad.
|
18th February 2011, 21:21 | #9 | Link | |
Registered User
Join Date: Feb 2009
Posts: 48
|
Quote:
You can test if deflicker is still in effect if you compare screen and screenTS clips in LocalDeflicker function. screen is the clip before deflickering, and screetTS - after. EDIT1. It looks like I understood where the problem is. If we can split somehow original clip on separate scenes and feed every scene to LocalDeflicker function then glowing artefact on scenes border will disappear. But for now I don't know how to do it better.
__________________
CPU: Core 2 Quad q9505 RAM: 4G OS: Windows 7 64 Video: Nvidia Geforce 460 GTX VP4 AviSynth: 2.5.8 Last edited by prokhozhijj; 18th February 2011 at 21:51. |
|
25th February 2011, 16:04 | #11 | Link |
Registered User
Join Date: Sep 2007
Location: Europe
Posts: 602
|
OK, scratch that. I'd really love to be able to use the entire DeDeeDeflicker() command, but can't because of the fact that it causes artefacting on the first and last frames of a scene.
Is there any way of writing a script which detects the scene changes, so we can turn the filter off on these frames? Or better yet, incorporate it into the function so we can fix the issue? |
25th February 2011, 17:08 | #12 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
__________________
- We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!) |
26th February 2011, 18:45 | #13 | Link |
Registered User
Join Date: Sep 2007
Location: Europe
Posts: 602
|
Thanks DiDee!
Suggestion: I found that using the function causes the edges of the frame to be shadowed, even if all borders are cropped off prior to applying the deflicker. Changing border=0 to border=3 in the GaussianBlur function fixes this (it's part of the LocalDeflicker function). I changed Code:
# Source bluring screen = res.gaussianblur(varY=blury,varC=blurc,border=0) #.greyscale Code:
# Source bluring screen = res.gaussianblur(varY=blury,varC=blurc,border=3) #.greyscale The remaining problem is that banding is now visible. If you Alter the LocalDeflicker function to return "screen" instead of "final_dumb" and pull the brightness up a little, we can see that the blurred image has horrible contouring which gets merged into the final deflickered output. I don't have a solution for this and sadly can't share the example clip... but imagine a scene from a black and white clip with a black background and a girl lit (appearing white) in front of it. On the deflickered clip, the flicker is gone (yay!) but there is now a sort of pulsating contoured glow around her head and body. Last edited by Lyris; 26th February 2011 at 19:15. |
26th February 2011, 21:00 | #14 | Link |
Registered User
Join Date: Sep 2007
Location: Europe
Posts: 602
|
Example images (from credits):
Before deflicker Uploaded with ImageShack.us After deflicker Result of "return screen" showing contours exist at this stage edit: I tried patching Gradfun2dbmod into the script - messy, I'd rather avoid banding in the first place than try to clean it up later... but it didn't do much good. It almost eliminated contouring in the "return screen", but not in the final result. Dark areas in the video still have a "tree rings" look to them. Last edited by Lyris; 27th February 2011 at 01:32. |
27th February 2011, 18:30 | #16 | Link |
Registered User
Join Date: Sep 2007
Location: Europe
Posts: 602
|
Thanks for the latest update. Do we have any better way to remove the banding other than throwing grain into the affected areas? This is not good for compression.
It still also creates artefacting which almost makes the film look like it is water damaged... it's frustrating because other than these two issues, it makes a huge improvement. before after Can you tell me, is there any way to use an effective single-frame (Global) deflicker? I've tried running GlobalDeflicker on its own but it doesn't do a lot of good. For some reason, #ing out the LocalDeflicker part of the "DeDeeDeflicker" function makes the flicker worse. Last edited by Lyris; 27th February 2011 at 18:35. |
27th February 2011, 21:47 | #17 | Link | ||
Registered User
Join Date: Feb 2009
Posts: 48
|
Quote:
EDIT1: http://forum.doom9.org/showthread.ph...18#post1386418 in this post some expert says you can not get a clear video without banding. I am just blur a frame (screen variable) before deflickering it. So that is the reason of banding. Please try to move GradFun2DBmod(thr=1.5,mask=true,mode=3,temp=100,str=4,adapt=-1,radius=3,range=150) from screenTS to screen in LocalDeflicker. And also try to play with "range" and "mode" parameters. Maybe it helps. I've not changed my mind to find a better solution. But I am not sure if I can. Quote:
Of course you can use something else instead of GlobalDeflicker function. I've tried all deflickers I could find. But Didée's deflicker was one of the best in this area. So I've used it in my Deflicker.
__________________
CPU: Core 2 Quad q9505 RAM: 4G OS: Windows 7 64 Video: Nvidia Geforce 460 GTX VP4 AviSynth: 2.5.8 Last edited by prokhozhijj; 28th February 2011 at 11:09. |
||
27th February 2011, 23:01 | #18 | Link |
Registered User
Join Date: Sep 2007
Location: Europe
Posts: 602
|
Still no success, the banding stays... I'm only beginning to get my feet wet with actual function making/altering too, so if anyone else can weigh in, I'd really appreciate it...
The other deflicker filters I've tried don't really have much effect. Is this consistent with other people's findings? |
27th February 2011, 23:12 | #19 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
There are several open traps in this function, and most of the issues are coming up when the filtering stumbles into one of the traps.
- the prefiltering for Soften2 function is way too rough. TemporalMedian with radius=3 will create enough artifacts on motion to fool the motion search - compensation for Soften2 is insufficient. With +/-1 compensations, you're only "safeguarding" a temporal radius of 1. Maybe 2, with some good will. But actually Soften2 is using a temporal radius of 4. In this combination, all the MVTools stuff is mostly a waste of time. -- specifically, MedianBlurT with radius=4 is very slow. In combination with Motion Compensation, it is *ridiculously* slow. (For yet unknown reasons....) - In the context in which they're used, the spatial parts of MedianBlur might do both harm and good. Possibly more harm. Related to the next point: - It doesn't exactly help that ontop of the flicker, the source is noisy/grainy. This might interfere with some of the blurring operations. But that's a task for closer examination. It's difficult to give specific "change this, change that" advice. I'd recommend to start from scratch, and think more closely about the implications of the used operations. * * * * BTW, who is this "Dedee" guy? I'd like to talk to him.
__________________
- We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!) |
28th February 2011, 00:36 | #20 | Link | ||||
Registered User
Join Date: Feb 2009
Posts: 48
|
Quote:
Quote:
Quote:
Quote:
* * * * Well. I thought that if I am using your algorithm then I need to keep this fact in new deflicker. But this mention can be removed from source at any time if you have objections.
__________________
CPU: Core 2 Quad q9505 RAM: 4G OS: Windows 7 64 Video: Nvidia Geforce 460 GTX VP4 AviSynth: 2.5.8 Last edited by prokhozhijj; 28th February 2011 at 01:06. |
||||
Thread Tools | Search this Thread |
Display Modes | |
|
|