Log in

View Full Version : AVS Function for deleting alpha-logos


DarkZeros
29th January 2009, 01:54
I wrote this small avs script based on masktools functions, to remove translucent logos from videos.
#LoadPlugin("mt_masktools.dll")

function AlphaDeLogo(clip original,string blacklogo_path,string whitelogo_path, float adjust, float blackadjust, float whiteadjust)
{
logo_black = ImageSource(blacklogo_path,0, FrameCount(original), FrameRate(original)).ConvertToYV12()
logo_white = ImageSource(whitelogo_path,0, FrameCount(original), FrameRate(original)).ConvertToYV12()
mediumlevel = mt_lutxy(logo_black,logo_white,expr="x "+string(blackadjust)+" * y "+string(whiteadjust)+" * + 2 /")
diff = mt_lutxy(logo_black,logo_white,expr="y "+string(whiteadjust)+" * x "+string(blackadjust)+" * - "+string(adjust)+" *")
normalized = mt_lutxy(original,mediumlevel,expr="x y - 128 +")
corrected = mt_lutxy(normalized,diff,expr="x 128 - y 256 / / 128 +")
return corrected
}


Its use is simple.
-Create a black image with the logo, and another one white.
Just pick them from the video and delete any other non-black or non-white object. (You can use "paint" for it)
Here there is an example of how should it look like:
http://forum.doom9.org/attachment.php?attachmentid=9356&stc=1&d=1233189870
Of corse, the files MUST be the same size as the video.

Then call the avs function:
AlphaDeLogo(last,"b.bmp","w.bmp",1,1,1)
The 3 values:
adjust, blackadjust and whiteadjust are to fine adjust the filter intensity. I recomed to let black and white adjust at 1, and only touch the adjust level [range 1-1.5]

Here some examples with a bad catched logo ("blocked" input):
http://forum.doom9.org/attachment.php?attachmentid=9358&stc=1&d=1233189897

And here some more, this time with a better logo input to the filter, and with some "delogo" repair in the borders:
http://forum.doom9.org/attachment.php?attachmentid=9357&stc=1&d=1233189897

I hope someone find it usefull.

mikeytown2
1st February 2009, 10:54
Just wondering the Toon logo is all white, thus only the black part is used, which might be why it doesn't work as well... What if you had it use 3 backgrounds (RBG or ...)?

IanB
1st February 2009, 21:33
For reference some maths about this processLet I = Input pixel
Let L = Logo pixel
Let a = alpha
then O = Output pixel

The original adding logo process is :- O = I*(1-a) + L*a

Solving this for I gives :- I = (O-L*a) / (1-a)

Let Ob = Black frame logo pixel

Black frame analysis, i.e. with I=0
Ob = 0*(1-a) + L*a
= L*a

Let Ow = White frame logo pixel

White frame analysis, i.e. with I=1
Ow = 1*(1-a) + L*a
= 1-a + Ob
1-a = Ow - Ob