View Single Post
Old 30th September 2018, 20:26   #29  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Anybody wanna test this out, my eyes dont see any difference (crap eyes).

Duplicity2_v2.02_Beta LINK REMOVED

Have implemented FillDrops modes.

Code:
    Function Duplicity2(clip c,"Mode"=0,Float "ThG"=1.0,Float "ThB"=ThG, Int "ThP"=64,Float "IgP"=0.0,Int "ThK"=7,
        \ Int "MaxDupLen"=9,Int "LagMax"=MaxDupLen,Int "MaxInterp"=Min(9,MaxDupLen),
        \ int "BlkW"=64,int "BlkH"=BlkW,int "OLapX"=BlkW/2,Int "OLapY=BlkH/2",
        \ Int "X"=0,Int "Y"=0,Int"W"=0,Int "H"=0,Float "CW"=0.0,Bool "ChromaI"=False,Bool "AltScan"=False,
        \ Int "SPad"=16, Int "SSharp"=1, Int "SRFilter"=4,                             [* MSuper          *]
        \ Int "ABlkSize"=16, Int "AOverlap"=4,   Int "ASearch"=3,Int "ADct"=0,         [* MAnalyse        *]
        \ Int "RBlkSize"=8,  Int "ROverlap"=2,   Int "RthSAD"=100,                     [* MRecalculate    *]
        \ Float "Iml"=200.0, Bool "IBlend"=True, Int "IthSCD1"=400, Int "IthSCD2"=130, [* MFlowInter      *]
        \ Int "OthSCD1"=400,Int "OthSCD2"=130,                                         [* Dupe Detect Override @ Scene Change *]
        \ String "OverRide"="",String "Frames"="Frames.txt",Bool "Ranges"=True,Bool "FrameAsRange"=False,
        \ Bool "Show"=True,Bool "Verb"=True,Bool "ShowBlk"=True,Bool "Dim"=True,Bool "ShowDot"=False,
        \ Int "FillDrops"=0
        \ )

...


        FillDrops,    Default 0 (OFF). [Valid only for Mode=2, Interpolate]
                      0) Standard precalculated Interpolation clips mode. (Fastest)
                      1) Standard Interpolated clip mode, except for N_Dupes==1, where Precalculated FillDrops clip method.
                      2) FillDrops Interpolated mode, except for N_Dupes==1, where Precalculated FillDrops clip.
                      3) Pure FillDrops mode where all Interpolation clips created during frameserving. (Slowest).
Gavino explanation of FillDrops mode with Delta=1.
https://forum.doom9.org/showthread.p...78#post1409378
Quote:
You're right, the function certainly does work, and now I see why.
What happens is that if a duplicate is found at frame n, it interpolates between n and n+1, since delta=1.
At first sight, this is wrong, but since frame n is a duplicate of frame n-1, it is equivalent to the desired interpolation between n-1 and n+1, so the final result comes out OK. (Whether by accident or by design, I'm not sure. )
And Also here:- https://forum.doom9.org/showthread.p...54#post1409954
Quote:
Originally Posted by Gavino View Post
Didée's explanation is the same as mine (but clearer!), and would suggest that the delta=2 approach cannot be improved upon. Your results are therefore puzzling and invite further explanation, which I believe I have found.

By looking at the source code, I have discovered that for occlusion areas, MVFlowInter also uses information from the two further surrounding frames (current-delta and current+2*delta).
So the diagram becomes, when interpolating between C and C+d,
Code:
       ----> <----
    C-d     C     C+d     C+2d
             ---->   <----
It is this additional information that will be more accurate when delta=1, explaining your findings and making your two-stage approach a better one. Well done.


Just to clarify further my remark about ConditionalFilter, what I am saying is this.
In ConditionalFilter(c1, c2, c3, "...", "...", "..."), 'last' is always set to the value of 'c1' before the expression strings are evaluated (on each frame). Therefore your code
Code:
  goodframes = ConditionalFilter(clip, trim(clip,1,0), clip, \
               "(YDifferenceFromPrevious(clip)/YDifferenceFromPrevious(loop(clip,2,0,0))) * \
               (YDifferenceToNext(clip)/YDifferenceToNext(trim(clip,1,0)))", "greaterthan", "bad_thresh")
can be replaced by
Code:
  goodframes = ConditionalFilter(c, trim(c,1,0), c, \
               "(YDifferenceFromPrevious()/YDifferenceFromPrevious(loop(2,0,0))) * \
               (YDifferenceToNext()/YDifferenceToNext(trim(1,0)))", "greaterthan", "bad_thresh")
and similarly for 'fixed', with the global variable being removed.
Using a global variable for this purpose in a function is in general a bad idea as the function will not work if called more than once.
Above in BLUE what I mean by FillDrops mode, allows extra data from additional frames where occlusions occur, and so better quality interpolation. The FillDrops=3 mode, we also trim out all dupes and so even better quality than original FillDrops method should be expected.
For the stuff about extra data from additional frames where occlusions occur, because in the filldrop original method the n-1 frame is the frame that n is a duplicate of, and so part of the extra data (where occlusions) comes from n-1 (dupe) and so is no better than using n,
the only extra info comes from n+2. For our Filldrops mode=3, all dupes are trimmed out (no matter what length, 0-9) and interpolation using frames either side of dupe sequence, so we expect even better than original FillDrops method.

We can only pre-create Interpolated FillDrops clips (created before framesering starts) where number of consecutive dupes==1.
N_dupes==1 pre-calc clip used for FillDrops modes 1 and 2 (exactly same as in FillDrops script), but for FillDrops mode==3,
then duplicates are trimmed out (for identical to FillDrops mode with delta=1, the frame of which the single dupe is a copy, is not trimmed out
and so takes some small part in result, whereas for FillDrops mode=3, all dupes trimmed out and so play NO PART in result).

Code:
                        # FillDrops Mode==2 and longer than single dupe (For single dupe, fix with precalc clip I10@@@ above)
                        # OR, FillDrops==3 and all length dupes interpolated Slow FillDrops method
                        # NOTE, FillDrops mode uses DELTA=1, and NO SHIFT,
                        fillMax=3
                        LS=Max(SStart-fillMax,0)  RS=SStart+Count     # Range limit for trim (cannot eg trim prior frame 0)
                        LCnt=SStart-LS      RCnt=Min(c.FrameCount-RS,fillMax)
                        Tmp_c = c.Trim(LS,-LCnt) + c.Trim(RS,-RCnt)     # Dupes trimmed out, with ideally two frames before & two after.
                        Prefilt=Tmp_c.RemoveGrain(22)
                        Super=Tmp_c.MSuper(hpad=SPad@@@,vpad=SPad@@@,levels=1,sharp=SSharp@@@,rfilter=SRFilter@@@)
                        Superfilt=Prefilt.MSuper(hpad=SPad@@@,vpad=SPad@@@,sharp=SSharp@@@,rfilter=SRFilter@@@)
                        bv=Superfilt.MAnalyse(isb=true  ,blksize=ABlkSize@@@,overlap=AOverLap@@@,search=ASearch@@@,delta=1,dct=ADct@@@)
                        fv=Superfilt.MAnalyse(isb=False ,blksize=ABlkSize@@@,overlap=AOverLap@@@,search=ASearch@@@,delta=1,dct=ADct@@@)
                        if(RBlkSize@@@>0) {
                            bv=Super.MRecalculate(bv,blksize=RBlkSize@@@,overlap=ROverLap@@@,thSAD=RthSAD@@@)
                            fv=Super.MRecalculate(fv,blksize=RBlkSize@@@,overlap=ROverLap@@@,thSAD=RthSAD@@@)
                        }
                        Tmp_I=Tmp_c.MFlowInter(Super,bv,fv,time=100.0*(Index+1)/(Count+1),ml=Iml@@@,blend=IBlend@@@,thSCD1=IthSCD1@@@,thSCD2=IthSCD2@@@)
                        Tmp_I.Trim(LCnt-1,-1)  # NO SHIFT, fixed frame @ LCnt-1 ie same as Left PreDupe frame
@Zorr, in part, is what you asked in this thread:- https://forum.doom9.org/showthread.php?t=175373

@John Meyer, The N_Dupes==1, for both FillDrops modes=1 and 2, then should be (I think) identical result to your filldrops method.
For N_Dupes > 1 and FillDrops mode=2, or any N_dupes>0 and FillDrops mode==3, then all dupes trimmed out and play no part in
interpolation, so perhaps even better than original FillDrops where result affected by single dupe.


Also John, any chance you could post all yiou know about the FillDrops weirdness, I have a clip where there seems to be 2 dropped frames(big jump)
and then some time later (some times immediately after) there are two dupes,
ALSO, sometimes single frame dropped, and single dupe some time later.
Is there a maximum distance between drops, max number of dropped, max number of dupes etc, any info/rules that you may have observed, thanx.

EDIT: Included in zip, shows difference (where Mode=2) between two Filldrops modes.
Code:
#Import("Duplicity2.Avs")

FN="d:\HAR.AVI"
AviSource(FN)
#########
Mode=2              # 0=Write Frames only : 1=Replace Dupes with Exact Dupes : 2= Interpolate/Blend Duplicates.
MaxDupLen=9         # Max detected, if more then is considered static sequence not duplicate)
MaxInterp=9         # Max Interpolated frames when Mode=2 (More than MaxInterp & less or equal to MaxDupLen then uses Blend mode)
ThG=1.0             # Primary Frame Global Detect
ThB=1.5             # Block Detect
ThP=64              # Pixel Count Detect
Show=True
ShowDot=false
ShowBlk=True
VERB=True
FillDropsA=1         # For A clip only
FillDropsB=3         # For B clip only (return default if STACK4=False)
###
STACK4=True
ORG=Last

A=ORG.Duplicity2(Mode=Mode,ThG=ThG,ThB=ThB,ThP=ThP,
        \ MaxDupLen=MaxDupLen,MaxInterp=MaxInterp,
       \ CW=0.0,ChromaI=False,AltScan=False,
        \ Ranges=True,FrameAsRange=False,
        \ Show=Show,Verb=VERB,ShowBlk=ShowBlk,ShowDot=ShowDot,FillDrops=FillDropsA
        \ )

B=ORG.Duplicity2(Mode=Mode,ThG=ThG,ThB=ThB,ThP=ThP,
        \ MaxDupLen=MaxDupLen,MaxInterp=MaxInterp,
       \ CW=0.0,ChromaI=False,AltScan=False,
        \ Ranges=True,FrameAsRange=False,
        \ Show=Show,Verb=VERB,ShowBlk=ShowBlk,ShowDot=ShowDot,FillDrops=FillDropsB
        \ )

D1=Subtract(A,B).Levels(125,1,127,0,255,coring=false)
LFT=StackVertical(A,B)
RGT=StackVertical(ORG,D1)
Return STACK4?StackHorizontal(LFT,RGT):B
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 30th December 2018 at 13:20.
StainlessS is offline   Reply With Quote