View Single Post
Old 13th April 2013, 17:59   #7  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
How does this grab ya.

Code:
Avisource("D:\avs\1955 Football 02.avi").Trim(0,-10)
ConvertToYV24()

Function CenteredMovingAve(clip c,int r) {
    Assert(r>0,"MovingAve: r cannot be zero")
    c   c2=0    killaudio()
    WW=width HH=height Frames=FrameCount
    GScript("""
        Even = !RT_BitTST(r,0)
        if(Even) {r=r-1}                                        # Make ALWAYS odd
        r=r/2                                                   # make radius
        for(n=0,Frames-1) {
            ras=0
            For(y=0,hh-1) {
                ave=0.0 div=0.0
                if(Even && y-(r+1) >= 0) {                    # do even
                    a = RT_YPlaneMax(n=n,y=y-(r+1),h=1) 
                    ave = ave + 0.5 * a 
                    div = div + 0.5 
                }
                For(off= -r, r) {
                    row=y+off
                    if(row>=0 && row<HH) {
                        a = RT_YPlaneMax(n=n,y=row,h=1) 
                        ave = ave + a
                        div=div+1.0
                    }   
                }
                if(Even && y+(r+1) < HH) {                    # do even
                    a = RT_YPlaneMax(n=n,y=y+(r+1),h=1) 
                    ave = ave + 0.5 * a 
                    div = div + 0.5
                }
                ave=ave / div
                color=Int(ave+0.5)
                scanline=c.BlankClip(Color_YUV=$8080+$10000*color,width=48,height=1,length=1)
                ras=(IsClip(ras)) ? ras++scanline : scanline
            }
            ras=ras.WeaveRows(HH)
            c2=(IsClip(c2)) ? c2++ras : ras
            RT_Debug(String(n)+"] of ",string(Frames))
        }
    """)
    return c2
}

ORG=Last
S=RT_Timer()
DIAG=CenteredMovingAve(ORG,24)
E=RT_Timer()
StackHorizontal(ORG,DIAG)
ConvertToRGB32()
RT_Debug("Time=",String(E-S))
Return Last
Its real slow, ~ 22 secs per frame with r==24, 1.8 secs @ r==1,7 secs @ r=7.

I've attempted to implement EVEN R.

EDIT:
Quote:
first row has no average
have not implemented like that, but could easily.

OOps, fixed (r/2+1) should be (r/2)

OOPS, Take 3. Hope I got it right this time.

Take 4, minor mod
__________________
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; 14th April 2013 at 18:22.
StainlessS is offline   Reply With Quote