yup
20th June 2007, 10:11
Hi folk!
During last time I try write script for remove impulse noise from captured video. Script below:
LoadPlugin("mt_masktools.dll") # v2.0a30
#SetMemoryMax(256)
AVISource("seldv2.avi")
Crop(16,16,-16,-16)
AssumeBFF()
ConvertToYV12(interlaced=true)
fields=SeparateFields()
backward_vec = fields.MVAnalyse(isb = true, delta = 2, pel = 2, overlap=4, sharp=2, idx = 1,dct=1, chroma=false)
forward_vec = fields.MVAnalyse(isb = false, delta = 2, pel = 2, overlap=4, sharp=2, idx = 1,dct=1, chroma=false)
filtered=fields.MVDegrain1(backward_vec,forward_vec,thSAD=400,idx=1)
backward_vecf = filtered.MVAnalyse(blksize=8, isb = true, delta = 2, pel = 2, overlap=4, sharp=2, idx = 2,dct=1, chroma=false)
forward_vecf = filtered.MVAnalyse(blksize=8, isb = false, delta = 2, pel = 2, overlap=4, sharp=2, idx = 2,dct=1, chroma=false)
fc = fields.MVFlow(forward_vecf, idx=3, thSCD1=10000)
bc = fields.MVFlow(backward_vecf, idx=3, thSCD1=10000)
mask_backward=filtered.MVMask(backward_vecf, kind=2, ml=50)
mask_forward=filtered.MVMask(forward_vecf, kind=2, ml=50)
mask_backward = mt_binarize(mask_backward,threshold=254)
mask_forward = mt_binarize(mask_forward,threshold=254)
mask_totor= mt_logic(mask_backward, mask_forward, mode="or")
mask_totand= mt_logic(mask_backward, mask_forward, mode="and")
masksdi=SDIPixelMask(bc, fields, fc,25, 0.8) # define your thresholds here
#masksdi=mt_expand(masksdi)
interleave(bc,filtered,fc)
ml3dex(Y=3,U=0, V=0)
fml3dex=SelectEvery(3,1)
fsdi=mt_merge(fields,fml3dex,masksdi)
mt_merge(fsdi,fields,mask_totand)
StackVertical(fsdi, fields)
#Weave()
#AddBorders(16,16,16,16)
# Thanks to gzarkadas for this function set
# this is for Abs(p - f) or Abs(p - b)
Function absdiff(clip c1, clip c2) { return mt_lutxy(c1, c2, "x y - abs") }
# this build the expression for the SDI function
Function SDI_RPN(string expr_d1, string expr_d2, string expr_t1, string expr_t2) {
_d1 = expr_d1 + " "
_d2 = expr_d2 + " "
_t1 = expr_t1 + " "
_t2 = expr_t2 + " "
return _d1 + _t1 + "> " + _d2 + _t1 + "> | 1.0 " \
+ _d1 + _d2 + "- " + _d1 + _d2 + "+ / abs - 0.0 ? " \
+ _t2 + "> 1.0 " + _d1 + _t1 + "> " + _d2 + _t1 + "> | 1.0 " \
+ _d1 + _d2 + "- " + _d1 + _d2 + "+ / abs - 0.0 ? "
}
# this creates the mask
Function SDIPixelMask(clip prev, clip curr, clip next, float t1, float t2) {
c_d1 = absdiff(curr, next)
c_d2 = absdiff(curr, prev)
# since SDI returns 0..1 we multiply with 255
mask = mt_lutxy(c_d1, c_d2, SDI_RPN("x", "y", String(t1), String(t2)) + " 255 *")
return mask
}
http://imgplace.com/directory/dir4530/1182329489_5174.png (http://www.imgplace.com)
Now script work better, but problem with some block where estimate fast motion (see top picture women without part of forefinger). I use 2 mask, one SDI (Spike Detection Index) for find impulse noise and mask_tot for occlusion in both directions.
May be need use one more additional mask for this region, but why?
Please advice.
With kind regards yup.
During last time I try write script for remove impulse noise from captured video. Script below:
LoadPlugin("mt_masktools.dll") # v2.0a30
#SetMemoryMax(256)
AVISource("seldv2.avi")
Crop(16,16,-16,-16)
AssumeBFF()
ConvertToYV12(interlaced=true)
fields=SeparateFields()
backward_vec = fields.MVAnalyse(isb = true, delta = 2, pel = 2, overlap=4, sharp=2, idx = 1,dct=1, chroma=false)
forward_vec = fields.MVAnalyse(isb = false, delta = 2, pel = 2, overlap=4, sharp=2, idx = 1,dct=1, chroma=false)
filtered=fields.MVDegrain1(backward_vec,forward_vec,thSAD=400,idx=1)
backward_vecf = filtered.MVAnalyse(blksize=8, isb = true, delta = 2, pel = 2, overlap=4, sharp=2, idx = 2,dct=1, chroma=false)
forward_vecf = filtered.MVAnalyse(blksize=8, isb = false, delta = 2, pel = 2, overlap=4, sharp=2, idx = 2,dct=1, chroma=false)
fc = fields.MVFlow(forward_vecf, idx=3, thSCD1=10000)
bc = fields.MVFlow(backward_vecf, idx=3, thSCD1=10000)
mask_backward=filtered.MVMask(backward_vecf, kind=2, ml=50)
mask_forward=filtered.MVMask(forward_vecf, kind=2, ml=50)
mask_backward = mt_binarize(mask_backward,threshold=254)
mask_forward = mt_binarize(mask_forward,threshold=254)
mask_totor= mt_logic(mask_backward, mask_forward, mode="or")
mask_totand= mt_logic(mask_backward, mask_forward, mode="and")
masksdi=SDIPixelMask(bc, fields, fc,25, 0.8) # define your thresholds here
#masksdi=mt_expand(masksdi)
interleave(bc,filtered,fc)
ml3dex(Y=3,U=0, V=0)
fml3dex=SelectEvery(3,1)
fsdi=mt_merge(fields,fml3dex,masksdi)
mt_merge(fsdi,fields,mask_totand)
StackVertical(fsdi, fields)
#Weave()
#AddBorders(16,16,16,16)
# Thanks to gzarkadas for this function set
# this is for Abs(p - f) or Abs(p - b)
Function absdiff(clip c1, clip c2) { return mt_lutxy(c1, c2, "x y - abs") }
# this build the expression for the SDI function
Function SDI_RPN(string expr_d1, string expr_d2, string expr_t1, string expr_t2) {
_d1 = expr_d1 + " "
_d2 = expr_d2 + " "
_t1 = expr_t1 + " "
_t2 = expr_t2 + " "
return _d1 + _t1 + "> " + _d2 + _t1 + "> | 1.0 " \
+ _d1 + _d2 + "- " + _d1 + _d2 + "+ / abs - 0.0 ? " \
+ _t2 + "> 1.0 " + _d1 + _t1 + "> " + _d2 + _t1 + "> | 1.0 " \
+ _d1 + _d2 + "- " + _d1 + _d2 + "+ / abs - 0.0 ? "
}
# this creates the mask
Function SDIPixelMask(clip prev, clip curr, clip next, float t1, float t2) {
c_d1 = absdiff(curr, next)
c_d2 = absdiff(curr, prev)
# since SDI returns 0..1 we multiply with 255
mask = mt_lutxy(c_d1, c_d2, SDI_RPN("x", "y", String(t1), String(t2)) + " 255 *")
return mask
}
http://imgplace.com/directory/dir4530/1182329489_5174.png (http://www.imgplace.com)
Now script work better, but problem with some block where estimate fast motion (see top picture women without part of forefinger). I use 2 mask, one SDI (Spike Detection Index) for find impulse noise and mask_tot for occlusion in both directions.
May be need use one more additional mask for this region, but why?
Please advice.
With kind regards yup.