DeKafka

From Avisynth wiki
Jump to: navigation, search

As outlined at my own wiki, this fairly simple filter washes away those bugging logos from broadcast clips.

Note this version works with any format, but there will be a RGB32 conversion.

function dekafka(clip clip, int Xstart, int Ystart, int X, int Y, int Amount)
{
  ytop = Ystart
  ybot = Ystart + Y
  xleft = Xstart
  xright = Xstart + X
  topline = clip.Crop(Xstart, ytop-2, X, 2)
  bottomline = clip.Crop(Xstart, ybot, X, 2)
  leftline = clip.Crop(xleft-2, ytop, 2, Y)
  rightline = clip.Crop(xright, ytop, 2, Y)
  logosrc_hor = StackVertical(topline, bottomline).Blur(0, 1.58).BilinearResize(X, Y)
  logosrc_ver = StackHorizontal(leftline, rightline).Blur(1.58, 0).BilinearResize(X, Y)
  Amount2 = (Y>=2*X) ? 255 : 128*Y/X
  # Amount2 is small if X >> Y => logoscr_hor is dominant
  logosrc = Layer(logosrc_hor, logosrc_ver, "add", Amount2)
  clip = clip.Layer(logosrc, "add", Amount, Xstart, Ystart)
  return clip
}

The version above simply replaces logo in position Xstart, Ystart, size X,Y, with a blurred box.

For better results, take a screenshot of the logo, convert to a black and white bitmap with photo editing software (Paint will do), open the bitmap in VirtualDub, save as a single frame AVI, and use the version of function below:

function dekafka(clip clip, clip logo1FrameAVI, int Xstart, int Ystart, int X, int Y, int Amount)
{
ytop = Ystart
ybot = Ystart + Y
xleft = Xstart
xright = Xstart + X
topline    = clip.Crop(Xstart,ytop-2,X,2)
bottomline = clip.Crop(Xstart,ybot  ,X,2)
leftline  = clip.Crop(xleft-2, ytop, 2, Y)
rightline = clip.Crop(xright,  ytop, 2, Y)
blurbox_hor = StackVertical  (topline, bottomline).Blur(0, 1.58).BilinearResize(X, Y)
blurbox_ver = StackHorizontal(leftline, rightline).Blur(1.58, 0).BilinearResize(X, Y)
amountYoverX = (Y>=2*X) ? 255 : 128*Y/X # AmountYoverX is small if X >> Y => blurbox_hor is dominant
blurbox  = Layer(blurbox_hor, blurbox_ver, "add", amountYoverX)
logosnap = logo1frameAVI.BilinearResize(X,Y).ConvertToRGB32()
logomask = Mask(blurbox, logosnap)
clip = clip.Layer(logomask,"add",Amount,Xstart,Ystart)
return clip
}
clip = clip.dekafka(logo1FrameAVI,Xpos,Ypos,Width,Height,Amount)

Tip: even using the second version of the function, don't expect the results to be perfect. There will typically be some residual 'ghost' logo, appearing particularly when the screen area around the logo is busy. Some may find setting the layering amount parameter (Amount) to a value less than the maximum of 256 gives better results. A value of 216 for example will have the effect of greatly toning down the logo rather than trying to completely remove it.

Personal tools