Thread: MVTools-pfmod
View Single Post
Old 18th November 2019, 19:05   #525  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Mod to VectorTest script as per Pinterf observation.
Code:
Function VectorTest(Int "Delta",Float "Time",Int "MaskT",Int "BlkSz",Int "XStep",Bool "Align",Bool "HFlip",String "CS") {
/*
    VectorTest(), An MvTools2::MFlowInter folly. by StainlessS @ Doom9 : https://forum.doom9.org/showthread.php?t=175373

    Req AVS+ or GSCript, GRunt, MvTools2, RT_Stats v1.43+
    Avs v2.58, Avs/+ v2.60.

    Delta, Default 1.     As for MvTools2
    Time,  Default 50.0,  As for MvTools2
    MaskT, Default 3,     As for MvTools2::MMask(kind=MASK_TYPE), 0=Motion, 1=Sad, 2=Occlusion, 3=Horizontal, 4=Vertical, 5=ColorMap
    BlkSz, Default 4,     As for MvTools2
    XStep, Default 8,     Motion per frame of synthesized clip.
    Align, Default True,  Aligns forward vector frame n+Delta to n. False show frame n of forward vector.
    HFlip, Default False, False, Animate from Right to Left, else Left to Right.
                          (Right to Left is less confusing, same direction that the frames come in from).
    CS,                   Avs v2.5 defaults "YV12" else "Y8".

    Returns RGB32 clip.
*/
    Function MTyp(Int n) {Return " Type="+Select(n,"Motion","Sad","Occlusion","Horizontal","Vertical","ColorMap")}
    myName="VectorTest: "
    IsAvsPlus=(FindStr(UCase(versionString),"AVISYNTH+")!=0)    HasGScript=RT_FunctionExist("GScript")
    HasGrunt=RT_FunctionExist("GScriptclip")                    HasMvTools2=RT_FunctionExist("MSuper")  Is26=VersionNumber>=2.6
    Assert(IsAvsPlus||HasGscript,myName+"Essential AVS+ or GScript installed")
    Assert(HasGrunt,myName+"Essential GRunt installed")         Assert(HasMvTools2,myName+"Essential MvTools2 installed")
    Delta=Default(Delta,1)  Time=Default(Time,50.0)             MaskT=Default(MaskT,3)    BlkSz=DefaulT(BlkSz,4)
    XStep=Default(XStep,8)  Align=Default(Align,True)           HFlip=Default(HFlip,False)
    CS=Default(CS,Is26?"Y8":"YV12")
    OLap=(BlkSz>=4)?BlkSz/2:RT_Undefined
#    OLap=RT_Undefined
    FuncS="""
        Function Fn(clip c,Int Delta,Float Time,Int XStep,Bool Align,Bool HFlip,String mType) {
            c    n=current_frame
            Hit=(Height-20)/5
            if(Align) {
                Steps=640/XStep
                x=((n+1)*XStep) + (Delta*XStep/2)
                x=Min(x,(Steps-1)*XStep)
                x=HFlip?x:639-x
                cF=RT_YPlaneMin(n=n,x=x,y=Round(2.5*Hit)+20,w=1,h=1)-128
                cB=RT_YPlaneMin(n=n,x=x,y=Round(3.5*Hit)+20,w=1,h=1)-128
                Z=c.BlankClip(width=1,height=1,Color=$FFFFFF,Length=1)
                OverLay(Z,x=x,y=Round(2.5*Hit)+20)
                OverLay(Z,x=x,y=Round(3.5*Hit)+20)
                Subtitle(RT_String("@x=%d FGrey=128%+d : BGrey=128%+d",x,cF,cB))
            } else {
                Subtitle("Align=False, Colors NOT shown")
            }
            Subtitle(String(n,"SRC[n=%.0f] (1st interp srcS)")                      , Y=0.5*Hit+20,Align=5)
            Subtitle(String(n+Delta,"SRC[n+Delta=%.0f] (2nd interp srcE)")          , Y=1.5*Hit+20,Align=5)
            (Align)
              \ ? Subtitle(String(n+Delta,"FVEC[n+DELTA=%.0f]")+mType+ " (Aligned)" , Y=2.5*Hit+20,Align=5)
              \ : Subtitle(String(n,"FVEC[n=%.0f]")+mType                           , Y=2.5*Hit+20,Align=5)
            Subtitle(String(n,"BVEC[n=%.0f]")+mType                                 , Y=3.5*Hit+20,Align=5)
            Subtitle(string(n+Delta*Time/100.0,"MFlowInter Predicted @ [%.2f]")     , Y=4.5*Hit+20,Align=5)
            Return Last
        }
        Wid=640 Hit=64  Steps=Wid/XStep
        White=BlankClip(width=WID,height=HIT,Length=1,Color=$FFFFFF,Pixel_type=CS)  Black=White.BlankClip  srcS=Black.BlankClip(Length=0)
        For(i=1,Steps-1) { W=White.Crop(0,0,i*XStep,0)  K=Black.Crop(0,0,Wid-W.Width,0)  Frm=StackHorizontal(K,W) srcS=srcS++Frm }
        srcS=(HFlip)?srcS.FlipHorizontal:srcS
        srcE=SrcS.Loop(0,0,Delta-1)                                # Delete Delta frames, end interp src
        super=srcS.MSuper(pel=2,hpad=16,vpad=16)
        fvec =MAnalyse(super, isb=false, blksize=BlkSz, overlap=OLap, delta=Delta, truemotion=true)
        bvec =MAnalyse(super, isb=true,  blksize=BlkSz, overlap=OLap, delta=Delta, truemotion=true)
        inter=srcS.MFlowInter(super, bvec,fvec, time=Time)
        mbv=srcS.MMask(bvec,kind=MaskT)
        mfv=srcS.MMask(fvec,kind=MaskT)

        return StackVertical(MShow(super,fvec).SubTitle("MShow fvec"),MShow(super,bvec).SubTitle("MShow bvec"))    ### RETURN EARLY

        mfv=(Align)?mfv.Loop(0,0,Delta-1):mfv                      # Align, Delete DELTA frames from start, align n+delta with n
        DIR=(HFlip) ? " : ---->" : " : <----"
        TXT=SrcS.BlankClip(Height=20,Length=1,Color=$404040)
        StackVertical(TXT,srcS,SrcE,MFV,MBV,Inter)
        mType=mTyp(MaskT)
        ARGS = "Delta,Time,XStep,Align,HFlip,MType"
        Last.GScriptClip("Fn(last, "+ARGS+")", local=true, args=ARGS)
        TXT=TXT.Subtitle(String(Delta,"Delta=%.0f")+String(Time," : Time=%.2f")+
            \ String(BLKSZ," : BLKSZ=%.0f")+String(XSTEP," : XSTEP=%.0f")+" : ALIGN="+String(ALIGN)+" : HFlip="+String(HFlip)+DIR)
        return StackVertical(TXT,Last)
    """
    IsAvsPlus?Eval(FuncS):GScript(FuncS)
    Return Last.ConvertToRGB32
}

# 0=Motion, 1=Sad, 2=Occlusion, 3=Horizontal, 4=Vertical, 5=ColorMap

VectorTest(Delta=2,MaskT=2,HFlip=false,BlkSz=8,Align=True)
frame 41 [EDIT: BVEC looks correct-ish, but is it twice as wide as it should be ???, maybe white moving left, and black moving right, sort of ]


frame 42


frame 43


frame 44


frame 45 [EDIT: BVEC looks correct-ish, but is it twice as wide as it should be ???, maybe white moving left, and black moving right, sort of ]


'curiouser and curiouser' cried Alice.

EDIT: Frame 41 (top one) cropped and point resized a bit
Code:
Crop(288,112,34,-14)
PointResize(width*16,height*16)
__________________
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; 18th November 2019 at 21:09.
StainlessS is offline   Reply With Quote