Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion.

Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 15th December 2006, 05:36   #1  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,865
delogo new version

Something people always ask for, is an english translation of the german delogo guide. Finally I have translated and fully commented the script itself. You will still need the original virtualdub delogo guide.

Didee delogo: an avisynth script which imports and builds upon the delogo 1.32 virtualdub delogo filter.

Code:
function VD_DeLogo(clip clip, bool "on_frames", string "range", string "file_deblend", string "file_alpha", 
  \  string "file_color", string "file_repair", float "depth", float "power", int "par_X", int "par_Y", bool "interlaced")
{
  LoadVirtualdubPlugin("C:\Program Files\AviSynth 2.5\plugins\virtualdub\delogo.vdf", "_VD_DeLogo")
  X = round(10*depth)
  Y = round(10*power)
  # theoretically: z = 100*log10(par_X/par_Y), as approximation I took a minimax-approximation (calculated with Maple):
  v = - 48.96556825 + 63.18825967*par_X - 16.00966389*par_X*par_X + 2.473556539*par_X*par_X*par_X - .2133268695*par_X*par_X*par_X*par_X
    \  + .009456579673*par_X*par_X*par_X*par_X*par_X - .0001675297934*par_X*par_X*par_X*par_X*par_X*par_X
  w = - 48.96556825 + 63.18825967*par_X - 16.00966389*par_X*par_X + 2.473556539*par_X*par_X*par_X - .2133268695*par_X*par_X*par_X*par_X
    \  + .009456579673*par_X*par_X*par_X*par_X*par_X - .0001675297934*par_X*par_X*par_X*par_X*par_X*par_X
  z = round(v) - round(w)
  return clip._VD_DeLogo(default(on_frames,false)?1:0, default(range,""), default(file_deblend,""), default(file_alpha,""), 
    \  default(file_color,""), default(file_repair,""), default(X,15), default(Y,40), default(interlaced,false)?1:0, z)
}

#Finally, the english translation of Didee' delogo enhanced script for virtualdub delogo.
#from delogo~tmp3.avs, newer than version in Tutoriöser DeLogo-Guide.pdf
#pre-requisites: avisynth 2.56, your video, masktools, removegrain filters, bmp files as created with virtualdub delogo:
#save BMPs in same folder as your video, and named "XYZ_alpha.bmp", "XYZ_deblend.bmp", etc.
#The complete list of possible files:
#name+"_deblend.bmp", name+"_alpha.bmp", name+"_color.bmp", name+"_repair.bmp", and if Cmix/Lmix<>0.0, name+"_repair_c.bmp"
#and name2 such as "C:\Documents and Settings\username\My Documents\My Videos\extramask.bmp"
#some terms: "repair" means interpolated video, created by using outer edges and blurring them to cover logo area, sort of
#"deblend" means to remove a transparent logo by subtracting the logo pixels from the video
#the filter builds upon delogo 1.32 virtualdub filter which already does deblend and repair, but now you mix these two
#for better results.  Careful mask making in the original delogo is essential

#"clip" variable (clip): a video with logo which you want to remove
#"Lwidth" variable (int): the width of the logo area, until the nearest screen edge ie LOGO....| =8pixels
#"Lheight" variable (int): the height of the logo area .... You are selecting a rectangular one whole corner of the video
#"loc" variable (string): "LO“, "RO“, "LU“, "RU“, meaning location choice of Links Oben, Rechts Oben, Links Unten, Rechts Unten 
#  or Left Top, Right Top, Left Bottom, Right Bottom  
#  The logo can be located in four corners, from Left Top; (0,0) to Right Bottom; (clip.width-Lwidth,clip.height-Lheight)
#"name" variable (string): The naming prefix of the BMP files, i.e., ABC -> ABC_alpha.bmp, ABC_deblend.bmp, etc.
#"Cmix" variable (float, default 0.0): Chroma Mix.  Mixes varying amounts of logo's colormask.
#  If you use Cmix <> 0.0, then you must have "XYZ_repair_c.bmp".  The area should cover problematic areas, up to the full logo.
#  In this case, 0.4 to 1.0 for Cmix are recommended.
#"Lmix" variable (float, default 0.0): Luma Mix.  -1.0 to -3.0 is preferred.  Adds or subtracts a copy of the fully repaired logo.
#"name2" variable (string, default ""): possibility to deliver an additional mask, which is used to MaskedMerge() the filter's end result over the logo snip area ...
#  i.e. useful for hiding possible color changes from the RGB<-->YV12 conversion. 
#  (For this case, use a mask covering all of the logo, with a soft feathered edge beyond the logo.)
#  To use this 2nd masking, the variable "name2" *must* contain the "full/path/to/themask.bmp".
#"i" variable (bool, default false): set to True for interlaced footage
#"PP" variable (bool, default false): set to True for fixed postprocessing, rather crude. Use only if result can't be made stable by other means.
#"amount" variable (float, default 1.0): Amount of Postprocessing.  Not implemented in this version.

function delogo( clip clp, int Lwidth, int Lheight, string loc, string name, 
 \               float "Cmix", float "Lmix", string "name2", bool "i", bool "PP",float "amount") 
       {
         name2=default(name2,"")
         PP=default(PP,false)
         amount=default(amount,1.0)
         logomask=(name2=="")?clp:imagereader(name2).loop().trim(0,framecount(clp)).converttoyv12(matrix="PC.601")
        # return logomask.histogram(mode="levels")
         Lmix=default(Lmix,0.0)
         Cmix=default(Cmix,0.0)
         i=default(i,false)
         ox=clp.width
         oy=clp.height
         x1 = (LeftStr(loc,1)=="L")  ? 0 : ox-Lwidth
         y1 = (RightStr(loc,1)=="O") ? 0 : oy-Lheight
         logo = clp.crop(x1,y1,Lwidth,Lheight)
         row  = (x1==0) ? (y1==0) ? clp.crop(Lwidth,0,-0,Lheight) : clp.crop(Lwidth,oy-Lheight,-0,-0)
          \             : (y1==0) ? clp.crop(0,0,x1,Lheight) : clp.crop(0,oy-Lheight,x1,-0)
         rest =           (y1==0) ? clp.crop(0,Lheight,-0,-0): clp.crop(0,0,-0,oy-Lheight)
         ConvertToRGB(logo)
        # log1=VD_DeLogo(false, "", "ana2.bmp", "alpha-G3.bmp", "color-G3.bmp", "repair.bmp",  1.5, 3.0, 1, 1, i).ConvertToYV12()
         log1=VD_DeLogo(false, "", name+"_deblend.bmp", name+"_alpha.bmp", name+"_color.bmp", name+"_repair.bmp",  1.5, 3.0, 1, 1, i).ConvertToYV12()
         log2 = (Cmix==0.0 && Lmix==0.0)
          \   ? log1 : VD_DeLogo(false, "", name+"_deblend.bmp", name+"_alpha.bmp", name+"_color.bmp", name+"_repair_c.bmp",  2.5, 3.0, 1, 1, i).ConvertToYV12()
         LL=string(int(round(Lmix)))
         LL1=string(int(round(Lmix*100.0)))
        # log1.DEdgemask(0,255,0,255,"1 1 1 1 0 1 1 1 1",U=2,V=2)
        # log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 8 28 56 76 56 28 8 1")
         PP ? (i ? log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 0 28 0 76 0 28 0 1")
        \        : log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 8 28 56 76 56 28 8 1") )
        \   : log1
       #  log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 0 6 0 15 0 20 0 15 0 6 0 1")
         log1=Lmix<=1.0?log1:yv12lutxy(last,log1,yexpr="x y "+LL+" + > x "+LL+" - x y "+LL+" - < x "+LL+" + y ? ?",U=2,V=2)
         
         Cmix==0.0 ? log1 : MergeChroma(log1,log2,Cmix)
         Lmix==0.0 ? last
       \: Lmix >1.0 ? yv12lutxy(last,log2,yexpr="x y "+LL+" + > x "+LL+" - x y "+LL+" - < x "+LL+" + y ? ?",U=2,V=2)
       \:             yv12lutxy(last,log2,yexpr="x 100 "+LL1+" - * y "+LL1+" * + 100 /",U=2,V=2)
     #  \:             MergeLuma(last,log2,Lmix) ## -->"Access violation" ... yippieh ... müsse mache yv12lutxy ...

        # PP?yv12convolution("1 8 28 56 76 56 28 8 1","1 0 28 0 76 0 28 0 1",U=2,V=2):last
         PP?(i?separatefields.Removegrain(2).weave:removegrain(2)):last
         PP?temporalsoften(2,11,11,23,2).AddGrain(5,.0,.0):last
        # PP?repair(last.sharpen(1),last,mode=1,modeU=3):last
         name2==""?last:maskedmerge(logo,last,logomask.FitY2UV(),Y=3,U=3,V=3)
         
         row2 = (x1==0) ? stackhorizontal(last,row) : stackhorizontal(row,last)
         y1==0          ? stackvertical( row2,rest) : stackvertical( rest,row2)
         return last
         }

#ServeLogo.  Use this to produce a clip showing only logo.  Open in virtualdub, add delogo filter, and process from there.
#please use the same lwidth/lheight/corner parameters as above.
#do this: import("delogo.avs") mpeg2source(...) serverlogo(lwidth,lheight,"loc"), save as logoserve.avs, open in virtualdub, add filter
#delogo 1.32, use delogo guide to continue (configure, show preview, save analyze.bmp, color red parts.. etc.)
#once you've made your masks, save filenames as above, now new script: import("delogo.avs") (this file), mpeg2source(..),delogo(...),encode.
#requires avisynth 2.50+
#clip (clip): a video containing a logo to be removed
#Lwidth (int): the width of the logo
#Lheight(int): the height of the logo
#loc (string): The location of the logo. "LO“, "RO“, "LU“, "RU“ or Left Top, Right Top, Left Bottom, Right Bottom
#SnipSize (int, default 56): one out of every SnipSize frames will be returned
#avg (int, default 3): number of frames to average with temporalsoften. Useful for denoising the logo clip.
function ServeLogo( clip clp, int Lwidth, int Lheight, string loc, int "SnipSize", int "avg" )
       { SnipSize = default( SnipSize, 56 )
         avg      = default( avg,       3 )
         x1 = (LeftStr(loc,1)=="L")  ? 0 : clp.width-Lwidth
         y1 = (RightStr(loc,1)=="O") ? 0 : clp.height-Lheight
         clp.crop(x1,y1,Lwidth,Lheight)
         SelectRangeEvery( SnipSize, 1 )
         return TemporalSoften( avg,255,255,255,2 )
         }
jmac698 is offline   Reply With Quote
Old 15th December 2006, 11:34   #2  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,566
Now someone just has to clone him, so one can work on mcbob, one on the framerate changer, and another on this delogo. =p
foxyshadis is offline   Reply With Quote
Old 23rd December 2006, 13:27   #3  |  Link
manolito
Registered User
 
manolito's Avatar
 
Join Date: Sep 2003
Location: Berlin, Germany
Posts: 2,999
The values for Lwidth and Lheight have to be mod-4 since we are working in YV12. You can force mod-4 by adding two lines to the start of the Delogo and Servelogo functions:

Lwidth = Lwidth + (4 - (Lwidth % 4))
Lheight = Lheight + (4 - (Lheight % 4))

Question:
In his guide Didée points out that "as an old paranoid he mostly works with mod-8 values". Why? Is it safer, or is it faster?


And a quick note for users of LogoAway (still excellent for opaque logos using UGLARM mode): Didées trick to let the filter only work in the small logo area also works for LogoAway, and I constantly get a speed improvement of almost 40%.


Cheers
manolito
manolito is offline   Reply With Quote
Old 2nd January 2007, 01:57   #4  |  Link
ilpippo80
Registered User
 
Join Date: May 2005
Location: Neverland
Posts: 79
As I was playing with some logo removal filters, in a moment of craziness I decided to translate didee's german guide.
Well, I don't know German at all and my english is far from perfect, anyway with a couple of automatic translators and free online dictionaries (and a lot of time during these vacations) I obtained something meaningful... I marked the sentences that do not make much sense to me with a [?], I hope that someone who knows German could take a look to it...
Maybe this will be useful to someone, it was for me!

Pdf file: http://rapidshare.com/files/9826038/DeLogo-Eng.pdf.html
OpenOffice.org file: http://rapidshare.com/files/9825979/DeLogo-Eng.odt.html

Happy new year to everybody!
ilpippo80 is offline   Reply With Quote
Old 24th February 2007, 14:27   #5  |  Link
kastiauto
Registered User
 
Join Date: Nov 2005
Posts: 14
How can i use 2nd masking?
Code:
#"name2" variable (string, default "")
#  To use this 2nd masking, the variable "name2" *must* contain the "full/path/to/themask.bmp".
My script:
Code:
...
#Line 28
DeLogo( 136, 72, "RO", "LOGO", Cmix=1.0, Lmix=1.0, "C:\folder\secondmask.bmp" )
...
and I get error:
---------------------------
VirtualDub Error
---------------------------
Avisynth open failure:
Script error: Invalid arguments to function "DeLogo"
(C:\folder\video.avs, line 28)
---------------------------
OK
---------------------------
kastiauto is offline   Reply With Quote
Old 25th February 2007, 05:10   #6  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,566
You can't call an unnamed argument after named ones. (Well, even if it's possible, it's a really bad idea.) Put name2= in front of the path.
foxyshadis is offline   Reply With Quote
Old 26th February 2007, 11:06   #7  |  Link
kastiauto
Registered User
 
Join Date: Nov 2005
Posts: 14
Quote:
Originally Posted by foxyshadis View Post
Put name2= in front of the path.
Yeah, name2= was missing. Now it is working.
kastiauto is offline   Reply With Quote
Old 3rd March 2007, 14:45   #8  |  Link
spanky123
Registered User
 
Join Date: Oct 2006
Posts: 98
Been waiting a while for this.

Thankyou

=)
spanky123 is offline   Reply With Quote
Old 3rd March 2007, 15:16   #9  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,394
Note: the script posted by jmac698 is newer than the one that's listed in the PDF file.

Note2: In the script posted above, the "Lmix" parameter is explained wrongly. (It's probably my own fault: I myself had explained it wrongly one or two times, during explaining-from-memory, without looking at the actual script...)

Wrong:
Quote:
#"Lmix" variable (float, default 0.0): Luma Mix. -1.0 to -3.0 is preferred. Adds or subtracts a copy of the fully repaired logo.
Negative values for Lmix are not implemented at all.


Correct:

Lmix = 0.0 - 1.0 will mix the transparency-restauration with the repair-restauration by the according percentual amount. That's the old version - blurriness is increasing faster than artrefacts are disappearing.

Lmix > 1.0: Each pixel of the transparency restauration is shifted by this value towards the value of the according pixel of the repair-restauration. Works out better than the old version, since the leftover artefacts of transparency restauration mostly are of small value.

Recommended Lmix values are 2.0 to 4.0~6.0. The lower you can afford, the better.

Example: A pixel of transparency-restauration has value "100". Same Pixel of repair-restauration has value "140". With Lmix=0.5, the resulting pixel will be "120". With Lmix=3.0, the resulting pixel will be "103".
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
Didée is offline   Reply With Quote
Old 8th April 2007, 01:43   #10  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,865
delogo, version 2007-04-07

Code:
function VD_DeLogo(clip clip, bool "on_frames", string "range", string "file_deblend", string "file_alpha", 
  \  string "file_color", string "file_repair", float "depth", float "power", int "par_X", int "par_Y", bool "interlaced")
{
  LoadVirtualdubPlugin("C:\Program Files\AviSynth 2.5\plugins\virtualdub\delogo.vdf", "_VD_DeLogo")
  X = round(10*depth)
  Y = round(10*power)
  # theoretically: z = 100*log10(par_X/par_Y), as approximation I took a minimax-approximation (calculated with Maple):
  v = - 48.96556825 + 63.18825967*par_X - 16.00966389*par_X*par_X + 2.473556539*par_X*par_X*par_X - 

.2133268695*par_X*par_X*par_X*par_X
    \  + .009456579673*par_X*par_X*par_X*par_X*par_X - .0001675297934*par_X*par_X*par_X*par_X*par_X*par_X
  w = - 48.96556825 + 63.18825967*par_X - 16.00966389*par_X*par_X + 2.473556539*par_X*par_X*par_X - 

.2133268695*par_X*par_X*par_X*par_X
    \  + .009456579673*par_X*par_X*par_X*par_X*par_X - .0001675297934*par_X*par_X*par_X*par_X*par_X*par_X
  z = round(v) - round(w)
  return clip._VD_DeLogo(default(on_frames,false)?1:0, default(range,""), default(file_deblend,""), default(file_alpha,""), 
    \  default(file_color,""), default(file_repair,""), default(X,15), default(Y,40), default(interlaced,false)?1:0, z)
}

#Finally, the english translation of Didée's delogo enhanced script for virtualdub delogo.
#from delogo~tmp3.avs, newer than version in Tutoriöser DeLogo-Guide.pdf
#History:
#2006-12-15  First English translation by jmac698
#2007-04-07  Lwidth/LHeight mod4 improvement from manolito, Lmix clarification from Didée, doc updates from jmac698

#pre-requisites: avisynth 2.56+, your video, masktools, removegrain filters, bmp files as created with virtualdub delogo:
#save BMPs in same folder as your video, and named "XYZ_alpha.bmp", "XYZ_deblend.bmp", etc.
#The complete list of possible files:
#name+"_deblend.bmp", name+"_alpha.bmp", name+"_color.bmp", name+"_repair.bmp", and if Cmix/Lmix<>0.0, name+"_repair_c.bmp"
#and name2 such as "C:\Documents and Settings\username\My Documents\My Videos\extramask.bmp"
#some terms: "repair" means interpolated video, created by using outer edges and blurring them to cover logo area, sort of
#"deblend" means to remove a transparent logo by subtracting the logo pixels from the video
#the filter builds upon delogo 1.32 virtualdub filter which already does deblend and repair, but now you mix these two
#for better results.  Careful mask making in the original delogo is essential

#"clip" variable (clip): a video with logo which you want to remove
#"Lwidth" variable (int): the width of the logo area, until the nearest screen edge ie LOGO....| =8pixels
#"Lheight" variable (int): the height of the logo area .... You are selecting a rectangular one whole corner of the video
#"loc" variable (string): "LO“, "RO“, "LU“, "RU“, meaning location choice of Links Oben, Rechts Oben, Links Unten, Rechts 

Unten 
#  or Left Top, Right Top, Left Bottom, Right Bottom  
#  The logo can be located in four corners, from Left Top; (0,0) to Right Bottom; (clip.width-Lwidth,clip.height-Lheight)
#"name" variable (string): The naming prefix of the BMP files, i.e., ABC -> ABC_alpha.bmp, ABC_deblend.bmp, etc.
#"Cmix" variable (float, default 0.0): Chroma Mix.  Mixes varying amounts of logo's colormask.
#  If you use Cmix <> 0.0, then you must have "XYZ_repair_c.bmp".  The area should cover problematic areas, up to the full 

logo.
#  In this case, 0.4 to 1.0 for Cmix are recommended.
#"Lmix" variable (float, default 0.0): Luma Mix.  Positive value. Recommended Lmix values are 2.0 to 4.0~6.0. The lower you 

can afford, the better.  Lmix = 0.0 - 1.0 will mix the transparency-restauration with the repair-restauration by the 

according percentual amount. That's the old version - blurriness is increasing faster than artrefacts are disappearing.
#Lmix > 1.0: Each pixel of the transparency restauration is shifted by this value towards the value of the according pixel 

of the repair-restauration. Works out better than the old version, since the leftover artefacts of transparency restauration 

mostly are of small value.
#Example: A pixel of transparency-restauration has value "100". Same Pixel of repair-restauration has value "140". With 

Lmix=0.5, the resulting pixel will be "120". With Lmix=3.0, the resulting pixel will be "103".
#"name2" variable (string, default ""): possibility to deliver an additional mask, which is used to MaskedMerge() the 

filter's end result over the logo snip area ...
#  i.e. useful for hiding possible color changes from the RGB<-->YV12 conversion. 
#  (For this case, use a mask covering all of the logo, with a soft feathered edge beyond the logo.)
#  To use this 2nd masking, the variable "name2" *must* contain the "full/path/to/themask.bmp".
#"i" variable (bool, default false): set to True for interlaced footage
#"PP" variable (bool, default false): set to True for fixed postprocessing, rather crude. Use only if result can't be made 

stable by other means.
#"amount" variable (float, default 1.0): Amount of Postprocessing.  Not implemented in this version.

#tips/tricks: If you get error Script error: Invalid arguments to function "DeLogo", do not use an unnamed argument after 

named ones. (thanks Foxyshadis).
#to speed up, apply to small window of video then merge back with overlay.(thanks manolito, for reminding of Didée's idea)

function delogo( clip clp, int Lwidth, int Lheight, string loc, string name, 
 \               float "Cmix", float "Lmix", string "name2", bool "i", bool "PP",float "amount") 
       {
         name2=default(name2,"")
         PP=default(PP,false)
         amount=default(amount,1.0)
         logomask=(name2=="")?clp:imagereader(name2).loop().trim(0,framecount(clp)).converttoyv12(matrix="PC.601")
        # return logomask.histogram(mode="levels")
         Lmix=default(Lmix,0.0)
         Cmix=default(Cmix,0.0)
         i=default(i,false)
         ox=clp.width
         oy=clp.height
         Lwidth = Lwidth + (4 - (Lwidth % 4))#updated 2007-04-07
         Lheight = Lheight + (4 - (Lheight % 4))
         x1 = (LeftStr(loc,1)=="L")  ? 0 : ox-Lwidth
         y1 = (RightStr(loc,1)=="O") ? 0 : oy-Lheight
         logo = clp.crop(x1,y1,Lwidth,Lheight)
         row  = (x1==0) ? (y1==0) ? clp.crop(Lwidth,0,-0,Lheight) : clp.crop(Lwidth,oy-Lheight,-0,-0)
          \             : (y1==0) ? clp.crop(0,0,x1,Lheight) : clp.crop(0,oy-Lheight,x1,-0)
         rest =           (y1==0) ? clp.crop(0,Lheight,-0,-0): clp.crop(0,0,-0,oy-Lheight)
         ConvertToRGB(logo)
        # log1=VD_DeLogo(false, "", "ana2.bmp", "alpha-G3.bmp", "color-G3.bmp", "repair.bmp",  1.5, 3.0, 1, 1, 

i).ConvertToYV12()
         log1=VD_DeLogo(false, "", name+"_deblend.bmp", name+"_alpha.bmp", name+"_color.bmp", name+"_repair.bmp",  1.5, 3.0, 

1, 1, i).ConvertToYV12()
         log2 = (Cmix==0.0 && Lmix==0.0)
          \   ? log1 : VD_DeLogo(false, "", name+"_deblend.bmp", name+"_alpha.bmp", name+"_color.bmp", name+"_repair_c.bmp", 

 2.5, 3.0, 1, 1, i).ConvertToYV12()
         LL=string(int(round(Lmix)))
         LL1=string(int(round(Lmix*100.0)))
        # log1.DEdgemask(0,255,0,255,"1 1 1 1 0 1 1 1 1",U=2,V=2)
        # log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 8 28 56 76 56 28 8 1")
         PP ? (i ? log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 0 28 0 76 0 28 0 1")
        \        : log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 8 28 56 76 56 28 8 1") )
        \   : log1
       #  log1.yv12convolution("1 8 28 56 76 56 28 8 1","1 0 6 0 15 0 20 0 15 0 6 0 1")
         log1=Lmix<=1.0?log1:yv12lutxy(last,log1,yexpr="x y "+LL+" + > x "+LL+" - x y "+LL+" - < x "+LL+" + y ? ?",U=2,V=2)
         
         Cmix==0.0 ? log1 : MergeChroma(log1,log2,Cmix)
         Lmix==0.0 ? last
       \: Lmix >1.0 ? yv12lutxy(last,log2,yexpr="x y "+LL+" + > x "+LL+" - x y "+LL+" - < x "+LL+" + y ? ?",U=2,V=2)
       \:             yv12lutxy(last,log2,yexpr="x 100 "+LL1+" - * y "+LL1+" * + 100 /",U=2,V=2)
     #  \:             MergeLuma(last,log2,Lmix) ## -->"Access violation" ... yippieh ... müsse mache yv12lutxy ...

        # PP?yv12convolution("1 8 28 56 76 56 28 8 1","1 0 28 0 76 0 28 0 1",U=2,V=2):last
         PP?(i?separatefields.Removegrain(2).weave:removegrain(2)):last
         PP?temporalsoften(2,11,11,23,2).AddGrain(5,.0,.0):last
        # PP?repair(last.sharpen(1),last,mode=1,modeU=3):last
         name2==""?last:maskedmerge(logo,last,logomask.FitY2UV(),Y=3,U=3,V=3)
         
         row2 = (x1==0) ? stackhorizontal(last,row) : stackhorizontal(row,last)
         y1==0          ? stackvertical( row2,rest) : stackvertical( rest,row2)
         return last
         }

#ServeLogo.  Use this to produce a clip showing only logo.  Open in virtualdub, add delogo filter, and process from there.
#please use the same lwidth/lheight/corner parameters as above.
#do this: import("delogo.avs") mpeg2source(...) serverlogo(lwidth,lheight,"loc"), save as logoserve.avs, open in virtualdub, 

add filter
#delogo 1.32, use delogo guide to continue (configure, show preview, save analyze.bmp, color red parts.. etc.)
#once you've made your masks, save filenames as above, now new script: import("delogo.avs") (this file), 

mpeg2source(..),delogo(...),encode.
#requires avisynth 2.50+
#clip (clip): a video containing a logo to be removed
#Lwidth (int): the width of the logo
#Lheight(int): the height of the logo
#loc (string): The location of the logo. "LO“, "RO“, "LU“, "RU“ or Left Top, Right Top, Left Bottom, Right Bottom
#SnipSize (int, default 56): one out of every SnipSize frames will be returned
#avg (int, default 3): number of frames to average with temporalsoften. Useful for denoising the logo clip.
function ServeLogo( clip clp, int Lwidth, int Lheight, string loc, int "SnipSize", int "avg" )
       { SnipSize = default( SnipSize, 56 )
         avg      = default( avg,       3 )
         Lwidth = Lwidth + (4 - (Lwidth % 4))#updated 2007-04-07
         Lheight = Lheight + (4 - (Lheight % 4))
         x1 = (LeftStr(loc,1)=="L")  ? 0 : clp.width-Lwidth
         y1 = (RightStr(loc,1)=="O") ? 0 : clp.height-Lheight
         clp.crop(x1,y1,Lwidth,Lheight)
         SelectRangeEvery( SnipSize, 1 )
         return TemporalSoften( avg,255,255,255,2 )
         }
jmac698 is offline   Reply With Quote
Old 9th April 2007, 07:21   #11  |  Link
Adub
Fighting spam with a fish
 
Adub's Avatar
 
Join Date: Sep 2005
Posts: 2,687
There are a few lines that should be commented in there. If you leave it like this, Avisynth will fail to parse the script correctly, resulting in a lock-up. Please clean up the script a little, thank you.
__________________
FAQs:Bond's AVC/H.264 FAQ
Site:Adubvideo
Adub is offline   Reply With Quote
Old 23rd December 2007, 05:34   #12  |  Link
Spuds
dumber every day
 
Spuds's Avatar
 
Join Date: Dec 2006
Location: Planet Earth
Posts: 154
Well the holiday season required me to capture some TV shows and after that get involved with delogoing I was using the script above and some changes that were on the German doom9 forum and then began to add some of my own ideas to help simply the task. There are several steps involved and it can be confusing.

WARNING: this is a work in progress, help and ideas appreciated, it probably has some bugs!

I'll post the script in the next post, the changes are:
1) worked on improving the translation, its a bit less googlish now.
2) restructured the function extensively
3) updated several of the masktools v1 calls with v2 calls
4) added function to help select the logo frame and output the files needed to input into virtualdub delogo. These are setup, framenumber and thres. When used it will output a white frame, a logo frame and the start of a analysis mask all to be used in virtualdub delogo. The mask BMP's are saved as black(0,0,0) and red(255,0,0).
5) made it a bit more resilient to bad input, somewhat
6) changed the vd_delogo function by adding in pow(x,y) in place of the multiple par_x. Also the W computation line seemed wrong since it like U used par_x and not par_y, the way the function was Z would always be zero no matter the PAR. Update: Changed the name to vd_delogo_mod to avoid conflicts with original wrong version.
7) allowed loc to be supplied as RT (right top) LB (Left bottom) etc in addition to the original way
8) made sure color translations followed the interlaced flag
9) implemented old and new PP options.
10) changed to use ttempsmoothf in place of temporalsoften during serve logo
11) added temporalsoften as PP step after lmix/cmix

I'll update this post later with the basic usage flow, I'm tired now....

Last edited by Spuds; 25th December 2007 at 15:50.
Spuds is offline   Reply With Quote
Old 23rd December 2007, 05:43   #13  |  Link
Spuds
dumber every day
 
Spuds's Avatar
 
Join Date: Dec 2006
Location: Planet Earth
Posts: 154
First the improved (maybe ) translation from the above post


Delogo:

A wrapper function to help use virtualdub delogo in avisynth with some added avisynth processing for improved results. This avisynth script builds upon the virtualdub delogo 1.32 filter by doing a de-blend and repair, allowing you mix these two outputs (via cmix / lmix) for better results. Careful masking of the original logo is essential to getting acceptable results.

History:
2006-12-15 First English translation by jmac698
2007-03-25 Ad-hoc Modification for Eastermeyer by Didee (Post processor changes)
2007-04-07 Lwidth / LHeight mod4 improvement from manolito, Lmix clarification from Didée, doc updates from jmac698
2007-12-24 masktools v2 changes, setup/ frame number functions, analyze bmp creation, pow updates in vd_delogo, optional post processing mask generation, overall comments and code structure

Pre-requisites:
- Avisynth filters: MaskTools v.2 a32, RemoveGrain, MedianBlur (PP=1), FFT3DFilter (PP=2), AddGrain, GradFun2db, Ttempsmoothf (PP)
- Virtualdub filters: delogo
- Other: bmp files as created with virtualdub delogo

Virtualdub Delogo Terms:
"repair" means interpolated video, created by using logo edges and blurring them to cover entire logo
"deblend" means to remove a transparent logo by subtracting the logo pixels from the video

Inputs:
"loc" variable (string):
"LO“ or "LT for Left top, "RO“ or "RT" for right top, "LU“ or "LB" for left bottom, "RU“ or "LB" for right bottom
"Lwidth" variable (int): Distance from video edge (left or right based on loc) to the far edge of the logo area ... be liberal
"Lheight" variable (int): Distance from the video edge (top or bottom based on loc) to the far edge of the logo area ... be liberal
The above (3) variables will cut a corner from the video which must contain the logo.

"Clip" variable (clip): a video with a hideous logo that you want to remove
"Name" variable (string): The full directory naming prefix of the BMP files, i.e., c:\123\xyz\logo will make the filter look for the files c:\123xyz\logo_alpha.bmp, c:\123\xyz\logo_deblend.bmp, etc.

Save the needed .BMP files in the folder indicated by name. Name them "XYZ_alpha.bmp", "XYZ_deblend.bmp", "XYZ_color.bmp", "XYZ_repair.bmp"etc. You create these in the virtualdub using the delogo filter. Note that if Cmix or Lmix is not 0, you will need to create a "_repair_c.bmp" file.

"Cmix" variable (float, default 0.0): Chroma Mix. Mixes varying amounts of delogos repair and deblend results into a final result. If you use Cmix <> 0.0, then you must have "XYZ_repair_c.bmp" file. The area should cover problematic areas, up to the full logo. 0.4 to 1.0 for Cmix are recommended.

"Lmix" variable (float, default 0.0): Luma Mix. Recommended Lmix values are 2.0 to 4.0~6.0. The lower you can afford the better. Lmix > 1.0: Each pixel of the transparency restoration is shifted by this value towards the value of the pixel resulting from the repair-restoration. Example: A pixel has a transparency value of "100". The Same Pixel after repair has a value “140". With
Lmix=0.5, the resulting pixel will be "120". With Lmix=3.0, the resulting pixel will be "103".

"name2" variable (string, default ""): ability to deliver an additional mask which is used in MaskedMerge() in the logo area (the area we specified above). This can be useful for hiding potential color changes from the RGB <--> YV12 conversion. The bmp for this should be a mask covering the exact logo, with a soft feathered edge moving beyond the logo. To use this 2nd masking, the variable "name2" *must* contain the "full/path/to/the/mask.bmp".

"i" variable (bool, default false): set to True for interlaced footage
"PP" variable (int, default 0): set to 1, 2 or 3 for various post processing options. May help, may hurt, try and see for yourself.
“lmask” variable (bool, default true). Set to apply post processing through a soft mask on the logo. Set to false for full post processing.
"Amount" variable (float, default 1.0): Amount of removal effect to apply in percent, 1.0 is applying full removal result while 0.0 would show the original logo.
“Debug” variable (bool default false), will output the parameters that delogo will be called with.
“Serve” variable (bool default false), will output denoised frames in a set specified by snip size. Use this shortened and cleaned video in virtualdub to help with mask creation
“Setup” variable (bool default false), will output the clipped corner (when framenumber=-1) so you can see if you have the correct crop size. When framenumber<>-1 it will output 4 clips for use in paint and virtualdub.
Framenumber variable (int default -1). Used to specify a frame to save as a bmp for use in creating masks in your favorite graphics editor. It will output a frame of the logo, a white frame, and two starting masks for use in paint. The masks will have the background as black (0,0,0) and the outline as red (255,0,0)
Thres variable (int default=24), Used to fine-tune the masks that setup=true framenumber=?? will save. Increase to mark more with red, decrease to mark less.

Last edited by Spuds; 24th December 2007 at 21:38.
Spuds is offline   Reply With Quote
Old 23rd December 2007, 05:46   #14  |  Link
Spuds
dumber every day
 
Spuds's Avatar
 
Join Date: Dec 2006
Location: Planet Earth
Posts: 154
The current state of the function after my torture has been applied.

Code:
# Delogo 
# A wrapper function to help use virtualdub delogo in avisynth with some added avisynth processing for improved results. This avisynth 
# script builds upon the virtualdub delogo 1.32 filter by doing a deblend and repair, allowing you mix these two
# outputs (via cmix/lix) for better results.  Careful mask making of the original logo is essential
# History:
# 2006-12-15  First English translation by jmac698
# 2007-03-25  Ad-hoc Modification for Eastermeyer by Didee (Post processor changes)
# 2007-04-07  Lwidth/LHeight mod4 improvement from manolito, Lmix clarification from Didée, doc updates from jmac698
# 2007-12-20  masktools v2, setup/framenumber function, analyse bmp creation, par updates in vd_delogo, 
#             overall comments and code structure
# 
# Pre-requisites: 
# - Avisynth filters: MaskTools v.2, RemoveGrain, MedianBlur (PP=1), FFT3DFilter (PP=2), AddGrain, GradFun2db, ttempsmoothf, temporalsoften
# - Virtualdub filters: delogo 
# - Other: bmp files as created with virtualdub delogo
#
FUNCTION delogo( clip clp, int Lwidth, int Lheight, string loc, string name, \
                  bool "debug", int "par_x", int "par_y", \
                  float "Cmix", float "Lmix", string "name2", bool "i", int "PP",float "amount", bool "lmask", \
                  bool "setup", int "framenumber", int "thres", \
                  bool "serve", int "SnipSize", int "avg") 
{
  delogo_location = "C:\Program Files\AviSynth 2.5\plugins\virtualdub\" # directory location of the needed virtualdub filter file
  # Parameters used to find a clean logo frame and output a starting repair mask
  setup           = default( setup,false ) # use after you have the logo located, this will create some initial bmp's that you need for delogo
  thres           = default( thres,190 ) # luma threshold to attempt logo mask creation.
  framenumber      = default( framenumber,0 )
  
  # Parameters used to frameserve to virtualdub for use in delogo all frames search, needed for transparent logos
  serve           = default( serve,false ) # use after you have the logo repair bmp created, used to build masks for transparent logos in vdub
  SnipSize        = default( SnipSize, 56 ) # one out of every SnipSize frames will be returned for searching
  avg             = default( avg, 3 ) # number of frames to average with temporalsoften. Useful for denoising the logo clip.
 
  # Parameters used in this script
  debug           = default( debug,false) # show call to vd_delogo to help in debuging on with show and setup = false
  par_x           = default( par_x,1 ) # pixel aspect ratio X
  par_y           = default( par_y,1 ) # pixel aspect ratio y
  PP              = default( PP,2 ) # Post process function 0,1,2 to help reduce damage left behind by logo removal
  lmask           = default( lmask, true ) # apply post process through a simple mask
  amount          = default( amount,1.0 ) # how much noise to blend into the removal area to help hide artifacts 1.0 = keep 100 of logo, .1 = 10% logo 90% noise
  Lmix            = default( Lmix,0.0 ) # Luma blending of results
  Cmix            = default( Cmix,0.0 ) # Chroma blending of results
  name2           = default( name2,"" ) # optional logo mask, needs to be a mask that covers the logo and feathers away from the logo
  logomask        = ( name2 == "" ) ? clp : imagereader(name2).loop().trim(0,framecount(clp)).converttoyv12(matrix="PC.601")
  i               = default( i,false ) # Interlaced video true/false

  # seperate out the directory and logo name, may not need it but ....
  sl        = name.revstr().findstr("\") - 1
  Assert((sl >= 0),"specify a fully qualified directory and logo name to use")
  logo_name = (sl < 0  ) ? "" : rightstr(name,sl)
  logo_dir  = (sl < 0) ? "" : leftstr(name,strlen(name)-sl)
  
  # based on clip size and user input, cut off a corner that contains the logo, using this small area will speed up processing
  Lwidth          = m4(Lwidth)   
  Lheight         = m4(Lheight)
  loc             = ucase(loc)
  ox              = clp.width
  oy              = clp.height
  x1              = (LeftStr(loc,1)=="L")  ? 0 : ox-Lwidth
  y1              = (RightStr(loc,1)=="O" || RightStr(loc,1) == "T") ? 0 : oy-Lheight
  logo            = clp.crop(x1,y1,Lwidth,Lheight)
  
  # retain the rest of the clip of re-integration later.         
  row  = (x1 == 0) ? (y1 == 0) ? clp.crop(Lwidth,0,-0,Lheight) : clp.crop(Lwidth,oy-Lheight,-0,-0) \
                   : (y1 == 0) ? clp.crop(0,0,x1,Lheight) : clp.crop(0,oy-Lheight,x1,-0)
  rest = (y1 == 0) ? clp.crop(0,Lheight,-0,-0) : clp.crop(0,0,-0,oy-Lheight)
  logo_rgb = ConvertToRGB(logo)
  
  # If asked show the crop, useful to help zero in on the logo 
  (setup) ? prepare_Logo(logo,logo_dir,logo_name,framenumber,i, thres) : \
  (serve) ? ServeLogo( clp, Lwidth, Lheight, loc, SnipSize, avg, i ) : \
            remove_logo(logo_rgb, logo, Lwidth, Lheight, loc, name, logo_dir, logo_name, Cmix, Lmix, name2, i, PP, amount, \
                        delogo_location, debug, par_x, par_y, lmask)

  # re-integrate our delogo-ed corner with our original clip
  row2 = (x1 == 0 && setup == false && debug == false && serve == false) ? stackhorizontal(last,row) \
       : (setup == false && debug == false && serve == false) ? stackhorizontal(row,last) : nop()
  (y1 == 0 && setup == false && debug == false && serve == false) ? stackvertical( row2,rest) \
  : (setup == false && debug == false && serve == false) ? stackvertical( rest,row2) : last
  RETURN ( last )
}
 
FUNCTION remove_logo(clip logo_rgb, clip logo, int Lwidth, int Lheight, string loc, string name, string "logo_dir", string "logo_name", \
                      float "Cmix", float "Lmix", string "name2", bool "i", int "PP",float "amount", string "delogo_location", \
                      bool "debug", int "par_x", int "par_y", bool "lmask")
{  
  # set up our delogo names, 
  alpha_file    = logo_name + "_alpha.bmp"
  color_file    = logo_name + "_color.bmp"
  repair_file   = logo_name + "_repair.bmp"
  deblend_file  = logo_name + "_deblend.bmp"
  repair_c_file = logo_name + "_repair_c.bmp"

  # Set up to make the call to delogo, logodir can be either the supplied name or the supplied logo_dir
  log1 = logo_rgb.VD_DeLogo_Mod(false, "", logo_dir + deblend_file, logo_dir + alpha_file, logo_dir + color_file, logo_dir + repair_file, 1.5, 3.0, par_x, par_y, i, delogo_location, debug).ConvertToYV12(interlaced=i)
  log2 = (Cmix==0.0 && Lmix==0.0) ? log1 \
                                   : logo_rgb.VD_DeLogo_Mod(false, "", logo_dir + deblend_file, logo_dir + alpha_file, logo_dir + color_file, logo_dir + repair_c_file, 2.5, 3.0, par_x, par_y, i, delogo_location, debug).ConvertToYV12(interlaced=i)
  #logo=logo.ConvertToYV12(interlaced=i) 

  # post processing and masking of post results if requested
  postmask = (pp > 0 && lmask) ? mt_lut(mt_edge(log1,mode="min/max",thy2=190).mt_expand.mt_expand.mt_inflate,"x 35 > 0 x ?").mt_invert : blankclip(log1,color=$000000)
  post = ( PP == 1 )      ? log1.minblur(1,uv=2).medianblur(3,0,0).removegrain(11)  \
       : ( pp == 2 )      ? log1.fft3dfilter(sigma=16,sigma2=12,sigma3=8,sigma4=4,bt=3,bw=16,bh=16,ow=8,oh=8,degrid=1) \
       : ( pp == 3 && i ) ? log1.mt_convolution("1 8 28 56 76 56 28 8 1","1 0 28 0 76 0 28 0 1",y=3,v=2,u=2) \
       : ( pp == 3 )      ? log1.mt_convolution("1 8 28 56 76 56 28 8 1","1 8 28 56 76 56 28 8 1",y=3,v=2,u=2) \
       : log1
  ( pp > 0 ) ? mt_merge(log1,post,postmask) : log1

  # Determine how we are mixing in the chroma and luma of a repair and a deblend call to delogo, skip if only one call was made.
  LL  = string(int(round(Lmix)))
  LL1 = string(int(round(Lmix*100.0)))
  ( Cmix == 0.0 ) ? last : MergeChroma(last,log2,Cmix)
  ( Lmix == 0.0 ) ? last \
                  : (Lmix > 1.0) ? mt_lutxy(last,log2,yexpr="x y - abs " + LL + " <= y x y " + LL + " + > x " + LL + " - x y " + LL + " - < x " + LL + " + y ? ? ?",U=2,V=2) \
                  : mt_lutxy(last,log2,yexpr="x 100 " + LL1 + " - * y " + LL1 + " * + 100 /",U=2,V=2)

  # we have now removed, as best we can, the logo via repair and deblend.  Now lets "repair" the delogoed area
  gradfun2db(3.4) 
  ( pp > 0 ) ? temporalsoften(2,11,11,23,2) : last
  # a touch of noise can hide wonders :)
  noise = blankclip(logo,color_yuv=$808080).bilinearresize(m4(Lwidth/2.2),m4(Lheight/2.2)).addgrain(4,0,0).gaussresize(Lwidth,Lheight,p=35)
  ( debug ) ? nop() : mt_adddiff(last,noise,U=2,V=2)
  
  # Extra masking application
  ( name2 == "" || debug )    ? last : mt_merge(logo,last,logomask.FitY2UV(),Y=3,U=3,V=3)
  
  # how much of our work to keep?
  ( amount == 1.0 || debug )  ? last : mt_lutxy(last, logo, expr="x"+" "+string(amount)+" "+"* y "+" "+string(1.0-amount)+" * +",y=3,u=3,v=3)
  RETURN ( last )
}

FUNCTION m4(float x)
{
  # helper function to ensure MOD4 and atleast 16 
  x < 16 ? 16 : int(round(x/4.0)*4)
}

FUNCTION MinBlur(clip input, int r, int "uv")
{
  # Nifty Gauss/Median combination
  # Taken from MCBob.avs:
  uv   = default(uv,3)
  
  # process chroma if uv==3, otherwise just luma
  uv2  = (uv==2) ? 1  : uv
  rg4  = (uv==3) ? 4  : -1
  rg11 = (uv==3) ? 11 : -1
  rg20 = (uv==3) ? 20 : -1
  medf = (uv==3) ? 1  : -200
  
  # make our blur clips, r controls amount 
  RG11D = (r==1) ? mt_makediff(input,input.removegrain(11, rg11),U=uv2,V=uv2)
   \    : (r==2) ? mt_makediff(input,input.removegrain(11,rg11).removegrain(20,rg20),U=uv2,V=uv2)
   \    :          mt_makediff(input,input.removegrain(11,rg11).removegrain(20,rg20).removegrain(20,rg20),U=uv2,V=uv2)
  RG4D  = (r==1) ? mt_makediff(input,input.removegrain(4,rg4),U=uv2,V=uv2)
   \    : (r==2) ? mt_makediff(input,input.medianblur(2,2*medf,2*medf),U=uv2,V=uv2)
   \    :          mt_makediff(input,input.medianblur(3,3*medf,3*medf),U=uv2,V=uv2)
  DD    = mt_lutxy(RG11D,RG4D,"x 128 - y 128 - * 0 < 128 x 128 - abs y 128 - abs < x y ? ?",U=uv2,V=uv2)
  RETURN (input.mt_makediff(DD,U=uv,V=uv))
}

FUNCTION ServeLogo( clip clp, int Lwidth, int Lheight, string loc, int "SnipSize", int "avg", bool "i" )
{ 
  # ServeLogo.  Used to produce a clip showing only our logo.  Open this clip in virtualdub, add the delogo filter, and process from there.
  # You must use the same lwidth/lheight/corner parameters in all calls to delogo functions.
  # to use:
  # import("delogo.avs") mpeg2source(...) serverlogo(lwidth,lheight,"loc"), save as logoserve.avs, open in virtualdub,add filter
  # delogo 1.32, use delogo guide to continue (configure, show preview, save analyze.bmp, color red parts.. etc.)
  # Next steps: import("delogo.avs"), mpeg2source(..),delogo(...)
  SnipSize = default( SnipSize, 56 )       # one out of every SnipSize frames will be returned
  avg      = default( avg,       3 )       # number of frames to average with temporalsoften. Useful for denoising the logo clip.
  Lwidth   = m4(Lwidth)
  Lheight  = m4(Lheight)
  
  # based on clip size and user input, crop a corner that contains the logo, using only this small section will speed up processing
  # loc is the corner location of interest.  
  loc      = ucase(loc) 
  x1       = (LeftStr(loc,1) == "L")  ? 0 : clp.width - Lwidth
  y1       = (RightStr(loc,1) == "O" || RightStr(loc,1) == "T") ? 0 : clp.height - Lheight
  clp.crop(x1,y1,Lwidth,Lheight)
  SelectRangeEvery( SnipSize, 1 )
  # RETURN TemporalSoften( avg,256,256,255,2 )
  RETURN TTempSmoothF(maxr=avg,lthresh=256,cthresh=256,scthresh=255,interlaced=i)
}

FUNCTION prepare_logo(clip logo,string logo_dir,string logo_name, int "framenumber", bool "i", int "thres")
{
  logo        = (defined(framenumber) && framenumber > -1) ? trim(converttorgb(logo),framenumber,framenumber).converttoyv12(interlaced=i,matrix="pc.601") : logo.converttoyv12(interlaced=i)
  framenumber = (defined(framenumber)) ? framenumber : -1
  
  # Set up some backgrounds for us to use in creating masks
  redclip     = blankclip(logo,length=1,color=$ff0000)
  blackclip   = blankclip(logo,length=1,color=$000000)
  whiteclip   = blankclip(logo,length=1,color=$ffffff)
  outputclip  = whiteclip++logo
 
  # our assumption is that we have a nice shot of the logo on a dark background, two simple attempts at masking the logo 
  # in red for a starter in paintshop
  logo_mask     = mt_lut(logo,expr="x "+" "+string(thres)+" "+"< 0 255 ?").mt_binarize(threshold=thres,upper=false)
  logo_outline1 = mt_merge(logo,redclip,logo_mask,luma=true)
  logo_mask     = mt_edge(logo,mode="min/max",thy2=thres).mt_expand.mt_binarize(threshold=thres,upper=false)
  logo_outline2 = mt_merge(logo,redclip,logo_mask,luma=true)
  
  # write out the files, be sure to use 0-255 color range
  atemp=(framenumber > -1) ? ImageWriter(logo_outline1.ConvertToRGB24(matrix="pc.601").Levels(16, 1, 235, 0, 255, coring=false), file=logo_dir+logo_name+"1_", start=0,end=0,type="bmp") : nop()
  (framenumber > -1) ? overlay(logo,atemp,opacity=0) : nop()
  btemp=(framenumber > -1) ? ImageWriter(logo_outline2.ConvertToRGB24(matrix="pc.601").Levels(16, 1, 235, 0, 255, coring=false), file=logo_dir+logo_name+"2_", start=0,end=0,type="bmp") : nop()
  (framenumber > -1) ? overlay(logo,btemp,opacity=0) : nop()
  ctemp=(framenumber > -1) ? ImageWriter(outputclip.ConvertToRGB24(matrix="pc.601").Levels(16, 1, 235, 0, 255, coring=false), file=logo_dir+logo_name+"_", start=0,end=1,type="bmp") : nop()
  (framenumber > -1) ? overlay(logo,ctemp,opacity=0) : nop()
  (framenumber > -1) ? stackhorizontal(atemp,btemp,ctemp) : logo
  RETURN (last)
}

FUNCTION VD_DeLogo_Mod(clip clip, bool "on_frames", string "range", string "file_deblend", string "file_alpha", string "file_color", \
                    string "file_repair", float "depth", float "power", int "par_X", int "par_Y", bool "interlaced", string "delogo_location", bool "debug")
{
  # range = "100-200, 300-400"; or whole clip range = ""		       
  # pixel aspect ratio: par_X (1-16), par_Y (1-16)		       
  # depth (1.0 - 8.0), power (0.0 - 16.0)				       
 
  LoadVirtualdubPlugin(delogo_location + "delogo.vdf", "_VD_DeLogo")
  X     = round(10 * depth)
  Y     = round(10 * power)
  debug = default(debug,false)
    
  # Theoretically: z = 100*log10(par_X/par_Y)
  z = round(100*log(float(par_X)/float(par_Y)) / log(10))

  # Make the call to delogo via the virtualdub interface or provide debug info 
  (debug) ? blankclip(clip,width=640,height=480,color=$000000).subtitle("On Frames "+string(on_frames),y=1,size=14).subtitle("Range "+string(range),y=11,size=14) \
            .subtitle(file_deblend,y=21,size=14).subtitle(file_alpha,y=31,size=14).subtitle(file_color,y=41,size=14).subtitle(file_repair,y=51,size=14) \
            .subtitle("Depth "+string(x),y=61,size=14).subtitle("Power "+string(y),y=71,size=14).subtitle("Interlaced "+string(interlaced),y=81,size=14) \
            .subtitle("Z "+string(z),y=91,size=14) \  
          : clip._VD_DeLogo(default(on_frames,false) ? 1 : 0, default(range,""), default(file_deblend,""), default(file_alpha,""), \
            default(file_color,""),default(file_repair,""), default(X,15), default(Y,40), default(interlaced,false) ? 1 : 0, z)
  RETURN (last)
}

Last edited by Spuds; 25th December 2007 at 15:51.
Spuds is offline   Reply With Quote
Old 24th December 2007, 22:23   #15  |  Link
Spuds
dumber every day
 
Spuds's Avatar
 
Join Date: Dec 2006
Location: Planet Earth
Posts: 154
I made some revisions and posted the updated script and readme files in the previous posts. The short and sweet way to use this script is as follows. Note that the process is NOT automatic, you need to use avisynth, virtualdub and paint or other suitable graphics package.

Start with your basic script an import the above script and load a video file that you want to work on.

1) Step one, you need to cut out a corner of the video that contains the logo. The reason to do this is to increase the overall speed of what we are doing. Start by:

Code:
delogo(160,140,"RB","C:\My Videos\Logos\cbs",setup=true, framenumber=-1)
The output of this will be a video of size 160x140 from the RB right bottom corner. If you logo is in a different corner or needs a bigger clip then change and fine tune as needed. Note the use of of setup=true and framenumber=-1. You don’t have to be exact here and in fact if you cut to close to the logo its not good, leave some space or aim to have the logo in the middle of the resulting frame.

2) Once you are happy with the logo snip, scan through the video using the output of the above delogo line. Find a frame where the logo is against a black / dark background. You can usually find these at a station break. Anyway make note of the frame number (this example 272) and replace the -1 with the framenumer as follows.

Code:
delogo(160,140,"RB","C:\My Videos\Logos\cbs",setup=true, framenumber=272,thres=24)
The resulting output will be a stacked horizontal of 3 frames. They are two attempts at starting an analysis mask and the logo frame you picked. You will have to scan forward and backward (the output is only 2 frames) to save the white frame, I can’t figure out how to make this automatic 

Look at the first two images and fine-tune the thres number, this will increase the number of things it will paint as red (hopefully it’s the logo) and everything else is changed to black. NOTE the name is the directory and filename. This example will save files in C:\My Videos\Logos The names will be cbs_000000.bmp and all white frame cbs_000001.bmp the frame with the logo cbs1_000000.bmp and cbs2_000000.bmp two attempts at making a starting analyse mask for use in paint of whatever you like. Change the name to whatever you like and whatever directory you use.

Now go finalize / create your analyse bmp file as detailed in the delogo guide and manual.

3a) Now that you have your repair mask its time to do something with it. If you have a semi transparent logo, proceed as follows. You will need to use delogo to create 4 masks, to do this use:
Code:
delogo(160,140,"RB","C:\My Videos\Logos\cbs",serve=true, SnipSize=12) 
this will output every other frame that is “snipsize” away, basically a shortened video. Ideally you want to output 3000-5000 frames for delogo to do an acceptable analysis, more is better. Output the above into virtualdub. In virtualdub load the delogo 1.3.2 filter, open the filters configuration and load the analyse mask you created in step 2. Select show preview, select sample video, select all frames, wait. This is why we are using a small clip frame and a snipsize frame step, otherwise this step would take significantly longer. OK when its done you can fine tune (read the delogo manual).
SAVE the deblend, alpha, color and repair files as your file name (for this example its cbs) as cbs_deblend.bmp, cbs_alpha.bmp, cbs_color.bmp and cbs_repair_c.bmp in the same directory as above. Note the _c on the repair.
After saving those file, more the alpha repair slider to zero and save the repair maks ask cbs_repair.

NOTE: if the logo is not present in all frames then you must trim out the non-logoed frames in avisynth before you feed them in to delogo for analysis, if you don't you will not have acceptable results.

3b) You can get some quick results if you have a solid (not semi transparent) logo by using a two frame video in place of the 5000 frame video. In virtualdub open the cbs_000000.bmp file (the all white frame) , 000001 will open automatically as frame 2. With that video loaded follow the rest of set 3a (from load the analysis frame on)

4) Almost there, with the .bmp's created we make our final call as follows:
Code:
delogo(160,140,"RB","C:\My Videos\Logos\cbs",lmix=0.5,cmix=3.5,pp=2) 
Note the lmix, cmix and pp options are for example only, read the previous posts on how to fine tune these.

Last edited by Spuds; 28th December 2007 at 05:07.
Spuds is offline   Reply With Quote
Old 26th December 2007, 12:53   #16  |  Link
jmac698
Registered User
 
Join Date: Jan 2006
Posts: 1,865
new delogo method

Good job spuds. Jmac approved.
I've since made a new delogo method, which no one else seems to have invented yet. It uses the exact formula to recover the pixels. Due to different statistics of quantization errors in the logo area, there is still some slight outline that has to be cleaned with some of the above ideas.
The delogo is automatic and requires only a known background to find the logo. No need to draw masks. A typical known background is the black during scene cuts in a movie, or before commercial breaks. It's this typical background which allows an automatic search to be possible.

I haven't published this yet, it needs to be tweaked and packaged.

Thanks to Didee for telling me this was impossible and creating a sense of challenge.
jmac698 is offline   Reply With Quote
Old 26th December 2007, 17:40   #17  |  Link
Spuds
dumber every day
 
Spuds's Avatar
 
Join Date: Dec 2006
Location: Planet Earth
Posts: 154
Thanks Jmac, hope others can make use of the log removal workflow tweaks. Not bad once you do it a few times but getting started is a bit tough. Some of the PP option masks have helped remove additional artifacts but no miracles !

Quote:
I haven't published this yet, it needs to be tweaked and packaged
Very exciting information, I'm looking forward to an alpha or beta release so it can be taken for a test drive. The current collection of logo removers are OK, just very scene dependent on what bleeds through or not.
Spuds is offline   Reply With Quote
Old 26th December 2007, 21:30   #18  |  Link
IanB
Avisynth Developer
 
Join Date: Jan 2003
Location: Melbourne, Australia
Posts: 3,173
@jmac698,

Actually you need 2 different known background frames.

The Alpha blend equation is Out=a x In + (1-a) x Logo.

The black frame example readily gives you (1-a) x Logo, because In=0, which is great, you can treat the whole term as a constant, C, in the reversing expression.

In = (Out - C) x 1/a

You could try setting 1/a on the command line, but in practice the alpha mask usually blends to zero at the edges of the logo. So you really need another known frame to solve for 1/a values over the area of the logo.
IanB is offline   Reply With Quote
Old 18th June 2008, 22:01   #19  |  Link
sidewinder711
near the waterfront
 
sidewinder711's Avatar
 
Join Date: Feb 2008
Posts: 38
Thanks to Jmac698 and especially to Spuds for creating the modified DeLogo function including an "action plan"..

I tried to get rid of a logo from a German TV station called ZDF. Based on the instructions and the new "mask creating function" provided by Spuds, everything works smoothly without any problems till the last call.
- I have created the first set of masks (3 mask) and afterwards ...
- the second set of masks (alpha, deblend etc). For you I have put all these masks together on a spreadsheet which you can find here) .
- When I'm calling DeLogo(120,70,"LT","E:\test\DeLogo\cbs",lmix=0.5,cmix=3.5,pp=2) the original movie appears, but nothing has changed. The movie and the logo are the same as before.

Do I miss something and if so, what is it?


Edit: Nevermind, I found the problem. VirtualDub 1.8 isn't working properly atm with VD_DeLogo 1.3.2 ( it doesnt't create proper Alpha and Color masks). Therefore I recommand to use an older version of VirtualDub. For e.g. I used VirtualDub 1.7.7 and now the script and functions are working properly!

Last edited by sidewinder711; 22nd June 2008 at 15:12. Reason: Update
sidewinder711 is offline   Reply With Quote
Old 4th July 2008, 17:12   #20  |  Link
magic75
Registered User
 
Join Date: Jan 2005
Posts: 8
Thanks for all the great work everyone has put into this. Just one thing I noticed, setting pp=0 does not seem to yield the same results as omitting pp, which I had expected, reading the explanation above:
"PP" variable (int, default 0): set to 1, 2 or 3 for various post processing options

EDIT: aha, in the script it says default is 2

Last edited by magic75; 4th July 2008 at 17:24.
magic75 is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 20:21.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2021, vBulletin Solutions Inc.