My try to remove rainbows.
If you want to tweak this filter, you're welcome.
Default values work good.
Code:
# FadeDeRainbow v0.32
# 2014-08-14
# Requirements:
# mvtools 2.5.11.3 or mvtools 2.6.0.5 from Dither Tools or newer
# masktools2-a48 or TurboPascal's masktool2 or newer
# Progressive video
Function FadeDeRainbow(clip c, int "thsad", int "diff", int "th", bool "show")
{
thsad = default(thsad,3000) # thsad value for MDegrain, derainbowing strength
diff = default(diff,3) # Range: 0-127, Difference between degrained and original.
# If you set it too high, it inpands mask, therefore it can't remove rainbows.
show = default(show,false) # shows mask
th = default(th,10) # threshold for chubbyrain2's mask
frame = c.framecount-1
bif = c.bifrost(interlaced=false)
bif
ma=scriptclip("""
c=last
prev_frame=current_frame<>0 ? current_frame-1 : 0
u=UToY8()
v=VToY8()
m1=mt_lutxy(u,getframe(u,prev_frame),"x y - 2 - 255 * y x - 2 - 255 * |u")
m2=mt_lutxy(v,getframe(v,prev_frame),"x y - 2 - 255 * y x - 2 - 255 * |u")
mask=mt_logic(m1,m2,"or").pointresize(c.width,c.height)
mask.ConvertToYV12()
""")
uc = c.UToY8().mt_convolution(horizontal="1",vertical="1 -2 1")
vc = c.VToY8().mt_convolution(horizontal="1",vertical="1 -2 1")
mc = mt_lutxy(uc,vc,"x y + "+string(th)+" > 256 0 ?").pointresize(c.width,c.height).mt_expand()
uo = bif.UToY8()
vo = bif.VToY8()
super = bif.MSuper(sharp=2,rfilter=1)
bv2 = super.Manalyse(isb=true,delta=2,overlap=8,blksize=16,truemotion=false)
bv1 = super.Manalyse(isb=true,delta=1,overlap=8,blksize=16,truemotion=false)
fv1 = super.Manalyse(isb=false,delta=1,overlap=8,blksize=16,truemotion=false)
fv2 = super.Manalyse(isb=false,delta=2,overlap=8,blksize=16,truemotion=false)
deg = MDegrain2(bif,super,bv1,fv1,bv2,fv2,thsad=thsad,plane=3)
ud = deg.UToY8()
vd = deg.VToY8()
diff = string(diff)
m1 = mt_lutxy(uo,ud,"x y - "+diff+" - 255 * y x - "+diff+" - 255 * |u")
m2 = mt_lutxy(vo,vd,"x y - "+diff+" - 255 * y x - "+diff+" - 255 * |u")
mb = mt_logic(m1,m2,"or").pointresize(c.width,c.height)
mask = mt_logic(mt_logic(ma,mb,"and"),mc,"and")
norainbow = Overlay(bif,deg,mask=mask)
return !show ? norainbow : mask
}
Function getFrame(clip c, int frameNum)
{
return frameNum<>0 ? c.trim(frameNum,frameNum) : c.trim(frameNum,-1)
}
Changelog:
v0.32: 2014-08-14
- Minor tweak
v0.31: 2014-06-28
- Little speed up
v0.3: 2014-05-09
- Took chubbyrain2's masking
- Uses 2 times low memory
- Added
Bifrost()
- Fixed chroma ghost bug... i hope
- Removed
interlaced parameter which caused weird artifact
v0.24: 2014-04-20
- Changed default
thsad value
v0.23: 2014-04-19
- Calls 2 resize functions instead of 8.
- If mask is too big make it black mask, because rainbows don't appear in big area.
v0.22: 2014-04-03
- Replaced
subtract() with
mt_lutxy()
v0.21: 2014-03-13
- minor bug fix
v0.2: 2014-03-11
- added
interlaced parameter
- minor tweak
v0.1: 2014-03-09
- Initial Release