Log in

View Full Version : Mask stabilize problems


edcrfv94
9th July 2016, 12:45
I want to stabilize the Mask.
may my explaine and english not so well.

Like this:

x is pixels.

input = clip
thr=4
c2b = input.Trim(frame-2, -1)
c1b = input.Trim(frame-1, -1)
c1f = input.Trim(frame+1, -1)
c2f = input.Trim(frame+2, -1)
mask = input.maskfunction()
m2b = mask.Trim(frame-2, -1)
m1b = mask.Trim(frame-1, -1)
m1f = mask.Trim(frame+1, -1)
m2f = mask.Trim(frame+2, -1)
if absolute(input x - c1f x ) < thr
then mask=max(mask x ,m1f x)
if absolute(input x - c1b x ) < thr
then mask=max(mask x,m1b x)
if absolute(input x - c2f x ) < thr
then mask=max(mask x,m1f x)
if absolute(input x - c2b x ) < thr
then mask=max(mask x,m1b x)

also maybe min will have better result.

feisty2
9th July 2016, 13:56
x y - abs thr < x y max x ?

wonkey_monkey
9th July 2016, 19:30
x y - abs thr < x y max x ?

Not quite, I think. He means to compare the original (i.e. non mask) input frames with past and future frames, and to decide from that whether or not to max the masked versions of the same frames.

So more like:

x y - abs thr w z max w ?

Where w and z represent the masked versions of clips x and y (which themselves will be the same clip but offset in time).

I expect masktools would be up to the job but might need intermediate clips to store a result. y8_rpn can do it in one pass once the mask clip and offset versions are generated. Do you (edcrfv94) have a particular clip you want to apply this too?

if absolute(input x - c1f x ) < thr

Did you plan for this to apply to the y channel only? Or in full colour?

edcrfv94
10th July 2016, 04:09
I don't know how to accomplish this.

Some ideas.But I want the mask more stabilize.

function kf_MaskStabilize(clip c, clip m, int "radius", float "thr", string "mode", int "now")
{
radius = Default(radius, 6 )
thr = Default(thr, 2.0 )
mode = default(mode, "max" )
now = Default(now, 1 )

cb = c.selectevery(1, -now)
cf = c.selectevery(1, now)

mb = m.selectevery(1, -now)
mf = m.selectevery(1, now)

f = mt_lutxy(c, cf, "x y - abs "+string(thr)+" < 255 0 ?", y=3, u=1, v=1) # (abs(x-y) < thr) ? 255 : 0
mfc = mt_logic(m, mf, mode, y=3, u=1, v=1)
m = mt_merge(m, mfc, f, y=3, u=1, v=1)

b = mt_lutxy(c, cb, "x y - abs "+string(thr)+" < 255 0 ?", y=3, u=1, v=1) # (abs(x-y) < thr) ? 255 : 0
mbc = mt_logic(m, mb, mode, y=3, u=1, v=1)
m = mt_merge(m, mbc, b, y=3, u=1, v=1)

return (now >= radius) ? m : kf_MaskStabilize(c, m, radius=radius, now=now+1, thr=thr, mode=mode)
}