Log in

View Full Version : TV station logo away scripts


ppera2
14th June 2005, 15:38
I will give here couple AVS scripts for logo removal (masking):

Following script is for removing 2 logos - one (logoaw) without mask, what is good in case of reactangle, full logo (this is near to top, right on pictures) and other (logoawm) for not full logos (near to bottom, left on pics).
Of course, you need to prepare AVI clip from captured video for it. Best with Virtual Dub: copy frame where logo is on black background to clipboard, then go in some paint program like paint Shop Pro, and convert it to B/W. Need to add 1-2 pixels to contures, and save it as bitmap (2 color, Black and White only)
Then make 1 frame AVI from it with Virtual Dub, RGB uncompressed.

Here is the script:
-----------------------------------------------------
function logoaw(clip)
# Works with YUY2, YV12, RGB
#For good results Avisynth 2.56 required!
{

#Position & size & Opacity - enter here values by logo position and size

Xp = 388 # Pos of left top
Yp = 40 # Pos of left bottom
X = 72 # Width
Y = 46 # Height
Op = 1 # Max opacity, it means that covers (replaces)


ybot = Yp + Y
xright = Xp + X

#Now we cut 2 horiz. lines above logo, and 2 lines below
top = clip.Crop(Xp, Yp-2, X, 2)
bot = clip.Crop(Xp, ybot, X, 2)

#Here cut 2 vertical lines left, and 2 lines right.
left = clip.Crop(Xp-2, Yp, 2, Y)
right = clip.Crop(xright, Yp, 2, Y)

#Join top & bottom, blur it little horizontal, much vertical, and resize to logo dimens.
logoh = StackVertical(top, bot).Blur(0.3, 1.50).BilinearResize(X, Y)
#Join left & right, blur it much horizontal, little vertical, and resize to logo dimens.
logov = StackHorizontal(left, right).Blur( 1.50, 0.3).BilinearResize(X, Y)

#Blend 2 previous clips
logob = Overlay(logoh, logov, mode = "blend", opacity = 0.5)

#Finally put it in source video
clip = Overlay(clip, logob, mode = "blend", opacity = Op, x = Xp, y = Yp )
return clip
}


function logoawm(clip)
Same as above, except that masking is supported
{

#Position & size & Opacity - enter here values by logo position and size

Xp = 16
Yp = 464
X = 52
Y = 70
Op = 1

masklogo=AVISource("H:\12LogoRGB.avi") #Size must match with X, Y - otherwise resize!
# Masklogo clip must be B/W RGB!
# Black is transparent, white means that there logob clip will be blended

ybot = Yp + Y
xright = Xp + X


top = clip.Crop(Xp, Yp-2, X, 2)
bot = clip.Crop(Xp, ybot, X, 2)

left = clip.Crop(Xp-2, Yp, 2, Y)
right = clip.Crop(xright, Yp, 2, Y)

logoh = StackVertical(top, bot).Blur(0.3, 1.50).BilinearResize(X, Y)
logov = StackHorizontal(left, right).Blur( 1.50, 0.3).BilinearResize(X, Y)

#Blend in ratio 1:1
logob = Overlay(logoh, logov, mode = "blend", opacity = 0.5)

#Put in source video. Mask determines what will be covered, what not
clip = Overlay(clip, logob, mode = "blend", opacity = Op, x = Xp, y = Yp, mask = masklogo )
return clip
}

# SOURCE
clip=SegmentedAviSource("H:\Capture3.avi")


clip=clip.logoaw()
clip=clip.logoawm().BilinearResize(480,360)

return clip

---------------------------------

Other script is only for YUY2, and no masking. Benefit is higher speed.
Again, I put removal for 2 logos. Of course, you can remove second, if only one is there...


Fast logoremoval, no mask
------------------------------------------------
function delogo(clip)
{

#Position & size & Opacity - enter here values by logo position and size

Xp = 388 # Pos of left top
Yp = 40 # Pos of left bottom
X = 72 # Width
Y = 46 # Height
Op = 255 # Max opacity, it means that covers (replaces)


ybot = Yp + Y
xright = Xp + X

#By need: - works only with YUY2 colorspace
#clip = clip.ConvertToYUY2()

#Now we cut 2 lines above logo, and 2 lines below
top = clip.Crop(Xp, Yp-2, X, 2)
bot = clip.Crop(Xp, ybot, X, 2)

#Here cut 4 vertical lines left, and 4 lines right. Must be dividable by 4 in YUY2
# (AVS 2.55)
left = clip.Crop(Xp-4, Yp, 4, Y)
right = clip.Crop(xright, Yp, 4, Y)

#Join top & bottom, blur it little horizontal, much vertical and resize to logo dimens.
logoh = StackVertical(top, bot).Blur(0.3, 1.50).BilinearResize(X, Y)

#Join left & right, blur it much horizontal, little vertical and resize to logo dimens.
logov = StackHorizontal(left, right).Blur( 1.50, 0.3).BilinearResize(X, Y)

#Blend 2 previous clips
logob = Layer(logoh, logov, "fast" )

#Finally put it in source video
clip = clip.Layer(logob, "add", Op, Xp, Yp)
return clip
}


#Second delogo works same. It is optional for case of 2 logo

function delogo2(clip)
{

#Position & size & Opacity - enter here values by logo position and size

Xp = 20
Yp = 460
X = 48
Y = 72
Op = 255


ybot = Yp + Y
xright = Xp + X

top = clip.Crop(Xp, Yp-2, X, 2)
bot = clip.Crop(Xp, ybot, X, 2)

left = clip.Crop(Xp-4, Yp, 4, Y)
right = clip.Crop(xright, Yp, 4, Y)

logoh = StackVertical(top, bot).Blur(0.3, 1.50).BilinearResize(X, Y)
logov = StackHorizontal(left, right).Blur( 1.50, 0.3).BilinearResize(X, Y)


logob = Layer(logoh, logov, "fast" )

clip = clip.Layer(logob, "add", Op, Xp, Yp)
return clip

}

# SOURCE
clip=SegmentedAviSource("H:\Capture3.avi", pixel_type="yuy2")
#(example is for Mjpeg capture)

clip=clip.delogo()
clip=clip.delogo2().BilinearResize(480,360)

return clip
------------------------------------------------


Notes: You need new AVS 2.56 (get it at avisynt2.org) for correct blur and crop in all colorspaces.

Speed: as I tested, at average capture conversion fast script slows it some 5% (with 2 logo removal), while 'universal' slows about 20% (2 logo too).

Source

http://img280.echo.cx/img280/1559/source3cx.jpg

Reactangle delogo & masked delogo:

http://img280.echo.cx/img280/5776/reactmask6qj.jpg

Wilbert
14th June 2005, 15:54
Do you want me to approve the attachment?

edit: i removed your attachments, since it's not necessary any more.

ppera2
14th June 2005, 16:15
Do you want me to approve the attachment?

Of course :cool:
Even better would be if I could put pictures right in post...
(I tried with some free hosts, but it works not)

frank
14th June 2005, 16:34
Then use that:
http://www.imageshack.us/
Worked for me.