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 13th May 2010, 23:26   #1  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,992
s_ExLogo v1.1 Logo Removal - Dekafka Mod

Code:
#------------------------------------------------------------------------
#                s_ExLogo() v1.1, De-logo Function, With Clipping
#                                by StainlessS
#
# http://forum.doom9.org/showthread.php?t=154559
#------------------------------------------------------------------------
# History:
#
# v1.0 Initial release, featuring Lousy coordinate calculations. 
# v1.1 15 Sept 2010: Fixed haphazard coord calcs + lots of other alterations.
#      More like what v1.0 should have been, with more rigorous error checking and reporting.
#      SPow now 2.2 by default as in pre-release v0.0
#------------------------------------------------------------------------
#
# ("s_" Just Means Script Function)
#
# Filter requirements:- NONE (Tested only on Avisynth v2.5.8 and v2.6)
#
# Based on Dekafka (YUY2 Only)
#
#  HHHHHH         s_Exlogo, samples above and below (shown left as 'H')
# VLLLLLLV        and combines them into a horizontal bar.
# VLLLLLLV        Samples left and right and combines them into a vertical bar (show as 'V'.
# VLLLLLLV        Logo area shown as 'L'.
# VLLLLLLV        These bars may or may not be blurred, and are then resized to fit
#  HHHHHH         the logo area. The resized bars are then mixed together based
#                 on arg "Spow" and the ratio of length of Vertical bars to length
#                 of horizontal bars. Finally, the resultant de-logo'd area is
#                 Layer'ed onto the clip using the Amount arg.
#                   Clipping can be set so as to avoid eg sampling letterboxing when
#                 blurring out the logo (would normally result in nasty black
#                 block instead of a nasty logo). 
#
#  Basic usage:-
#   s_ExLogo(clip, int LogoX, int LogoY, int LogoW, Int LogoH)
#
#     LogoX,LogoY,LogoW,LogoH, position of logo, width and height (Compulsory args)
#         LogoX, LogoY, Sets upper left position of logo rectangle.
#         LogoW, LogoH, Width and height of Logo rectangle,
#            Zero and -ve, values can be used, relative to the width and height,
#            (as used in crop)
#            s_ExLogo(Last,680,520,-4,-4) would set logo area to (680,520,36,52)
#              on a 720x576 clip.
#         LogoX and LogoW should be in even numbers only (YUY2).
#
#  Optional args
#     int LogoMode, 0-4, Default 2.
#         0 = Show LOGO position by dimmed rectangle. (initial logo setup)
#         1 = Show PATCH (CLIPPED logo) position & Clipping. NON CLIPPED area shown in GREEN.
#             Clipping setup, Used AFTER LogoMode=0 (Initial Logo Setup).
#         2 = Normal, Default.
#         3 = Keep Chroma (delogo Luma only)
#         4 = Keep Luma (delogo Chroma only)
#
#     int BlurMode, 0-6, Default 4, Sets Both HBlur and VBlur as below.
#         0 = 0.0,  Off, No Blurring, BilinearResize only. (maybe subtitles)
#         1 = 0.2
#         2 = 0.33
#         3 = 0.5
#         4 = 1.0  Default
#         5 = 1.58 Maximum possible
#         6=  1.0  User Defined. (defaults to 1.0 here, as HBlur & VBlur, default 1.0)
#
#     int HBlur, Int VBlur, Default 1.0
#         Set by BlurMode or user defined if BlurMode = 6.
#         HBlur controls amount of Horizontal blurring in Vertical bars.
#         VBlur controls amount of Vertical blurring in Horizontal bars.
#
#     int ClipX, ClipY,ClipW,ClipH, Clipping rectangle, All default 0
#         As used in crop.
#         ClipX, ClipY, Sets upper left position of clipping rectangle.
#         ClipW, ClipH, Width and height of clipping rectangle,
#            Zero and -ve, values can be used, relative to the clip width and height.
#            The defaults (0) sets ClipW to Width and ClipH to Height.
#         In Normal usage, (no borders/letterboxing), not used at all.
#         Sometimes (black borders) rarely more than 1 of these Clip? args
#         and never more than 2 will be set.
#         ClipX and ClipW should be in even numbers only (YUY2).
#
#     float spow, 1.0 to 150.0, Default 2.2
#         When mixing blurred horizontal and vertical bars either side, top and bottom,
#         of a logo, this arg controls the mix. When spow==1.0, the bars with the
#         longest sides are given precedence weighted by how long they are compared
#         to the other bars. If the vertical bars either side of the logo are eg
#         100 pixels tall and the horizontal bars are 50, then the vertical bars
#         are mixed with 2:1 the strength of the horizontal bars, ie 66%, (about
#         170 for argument to Layer(), 256*0.66). Dekafka would have given this
#         example a strength of 255, close to 100% (255/256). Strangely, if lengths
#         were swapped about, it would have gotten a strength of 64, = 25%. s_ExLogo
#         is symetrical, whereas Dekafka is not.
#
#         Based on the above example where vertical bars are twice as long as the
#         horizontal bars:-
#         spow        V_Strength%     Layer_arg          ratio
#         1.0            66%            170               2:1      (Linear)
#         1.6            75%            191               3:1
#         2.2            80%            205               4:1      (Default)
#         2.8            83%            213               5:1
#         3.3            86%            219               6:1
#         4.0            88%            224               7:1
#         4.6            89%            228               8:1
#         5.0            90%            230               9:1
#         5.7            91%            233               10:1
#         143.0          99.6           255               255:1
#
#
#         As you can see, the above spow Default is 2.2, with a ratio of 4:1
#         meaning that if the vertical bars are twice as long as the horizontal ones,
#         they acquire a strength of 80%, 4:1 as opposed to 2:1 when linear spow of 1.0
#         is used.
#         Using spow=143.0 (or anywhere close) pretty much switches OFF the shortest side
#         which may have application. Anything else above about 5.7 is unlikely to be of
#         any great use. The spow arg does NOT produce miracles, but is something else
#         to play with if you get bored.
#           In this version, the default spow has reverted back to the original test value
#         of 2.2 (was 1.6 in first release). spow really is just an externally adjustable
#         default value, meant for testing and not really intended to be changed, suggest
#         that if you dont like the default setting, that you manually change it in the
#         source instead of submitting an spow arg every time its used.
#
#     int Mix, -1 to 256, default -1 (Use SPow)
#         Overrides Spow calculations for controlling mixing of vertical and horizontal
#         bars based on vertical : horizontal ratio.
#         Sets the argument passed to 'Layer()" directly, eg 256 uses ALL of the vertical
#         bars and NONE of the horizontal, 128 does a 50/50 mix and 0 uses only
#         horizontal bars. For one-off adjustments, may be best to use Mix instead
#         of using the spow arg.
#
#     int Amount, 0-256, Default 252, How much of blurred de-logo is used.
#         This controls  how much of the blurred de-logo put together by spow (or Mix, above)
#         is finally combined with the original clip to replace the logo area.
#
#------------------------------------------------------------------------ 
#  X-Coords should be in even numbers only (YUY2).
# -------
#  IN-USE:
#    Position logo using LogoMode=0 (Ignores clipping in this mode).
#      Displays Logo area as a "dimmed" rectangle. MUST SET LOGO IN THIS MODE 1st.
#    If borders/letterboxing, then:
#      Switch to LogoMode=1,
#         Shows Patch (CLIPPED logo) position & Clipping. NON CLIPPED area shown in GREEN.
#         NOTE, the Logo rectangle (patch) will have been clipped in this mode and any
#         that has been clipped out will NOT be hi-lited. Changed NON Clipped color
#         in v1.1 from Pink to GREEN. I'm sure that a better (more intuitive) method for
#         clipped hi-liting could be found, but this is the easy way, and I'm basically lazy.
#    When coords of Logo and optional clipping set then:
#      Switch to LogoMode=2, Normal usage. (LogoMode 3 and 4, may also have application)
# -------
#  CLIPPING:
#    If you have a standard set of LOGO coords for a particular station logo then
#    you would use these LOGO coords whether or not there are any borders/letterboxing.
#    You would only use the CLIP coords if borders/letterboxing, LOGO coords are NOT
#    changed. The only Clipping coords that need be set, are the ones where the
#    borders are, so if eg:
#      Video clip has eg letter boxing top and bottom, and logo is in top left, then:
#        Use LogoMode=1, to set only "ClipY", in this case ClipY should be the coord
#        of the topmost logo pixel that does NOT contain any border.
#        When set correctly, switch to LogoMode=2 (default use).
#        Blurred de-logo data is (in this case) taken only from left, right and bottom
#        of logo patch area. (Patch area = clipped LOGO area). 
# -------
#  SOME USAGE EXAMPLES, TO SHOW YOU WHAT TO EXPECT with LogoModes 0 and 1.
#
#  s_ExLogo(20,20,100,100,LogoMode=0)			# Logo Top LHS, No clipping, Show Logo 
#  s_ExLogo(20,20,100,100,ClipY=70,LogoMode=1)  # Logo Top LHS, Top HALF LOGO Clipped, Show Logo/Clipping 
#
#  s_ExLogo(0,12,-0,40,LogoMode=0)			    # Full width scrolling logo, No clipping, Show Logo 
#  s_ExLogo(0,12,-0,40,ClipY=32,logomode=1)	    # Full width scrolling logo, Top HALF LOGO Clipped, Show Logo/Clipping
# -------
#  LASTLY, Have had pretty impressive results using this as a post processor to AvsInpaint with low setting
#  for amount and FFT3DFilter doing a further little bit of smoothing on a cropped area slightly larger
#  than the patch area. (AvsInpaint using InPaintFunc.avs by Reuf Toc). AvsInpaint, can be a little on the slow
#  side, but whilst you are waiting, you could always spend your time wisely, perhaps; write a good book.
#------------------------------------------------------------------------
Find v1.1 s_ExLogo update here:

Also, if comments/complaints, post here.

Please Enjoy

Last edited by StainlessS; 16th June 2011 at 03:58. Reason: Spelt FFT3DFilter as FF3DFilter
StainlessS is offline   Reply With Quote
Old 15th September 2010, 23:27   #2  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,992
s_ExLogo v1.1 now available.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS is offline   Reply With Quote
Old 15th January 2011, 14:57   #3  |  Link
tasslehoff44
Registered User
 
Join Date: Aug 2010
Posts: 14
removing logo

Hi StainlessS,

I don't understand anything on your prefilter or the inpaint filter.

Can you help me to remove this logo from ts source ?

Screenshot

Thanks in advance.
tasslehoff44 is offline   Reply With Quote
Old 17th January 2011, 21:15   #4  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,992
Hi tasslehoff44,

For the single frame you provided, it is simple.

Code:
Import("D:\AVS\SCRIPT\S_Exlogo.AVS")
ImageSource("D:\AVS\screenshot.bmp",fps=25.0)
ConvertToYUY2() # For S_ExLogo()

LOGOMODE=2	# 0 for setup, 2 for normal use

S_ExLogo(1720,38,108,94,logomode=LOGOMODE)

return Last
You can set "LOGOMODE" to 0 to see how it would look during
setup.

Quote:
I don't understand anything on your prefilter or the inpaint filter.
I presume you mean "PostFilter". I sometimes use S_Exlogo() as
a post processor to InPaintFunc(), help for which is best
obtained on it's page, see
here
for a comment I made on it.

I can only give a rough guide to how I usually use S_ExLogo
together with InPaintFunc, I dont have any kind of standard
script for it.

1.
I usually crop out an area somewhat bigger than
the logo, and export that from within VDubMod as a HuffYUV
encoded clip.

2.
I use InPaintFunc on the cropped AVI, usually
on trim'ed sequences on several machines simultaneously
(as InPaintFunc is quite sedate in pace). The results of the
InPaintFunc sequences are again saved as HUFFYUV avi's.
This step is VERY SLOW.

3a.
We process the results of step 2. after splicing the trim's
together if necessary. For best results, I think that it is better
to crop the patch area (area of logo) leaving about 4 to 8 pixels as a
border area and then use FFT3DFilter on this.

3b.
Use S_ExLogo() on the original clip with "amount=255".

3c.
Overlay() the step 3a. results back onto the step 3b.
results with corrected coordinates (This could be a
little tricky unless your used to playing with coordinates).


Notes:-
1. Area for InPaintFunc needs to be somewhat bigger than
the logo to give InPaintFunc something to work with. The
size of the border here, depends on the size of the logo.

2. Steps 1. and 2. could be combined.

3a. We dont need to apply FFT3DFilter to the area required
by InPaintFunc, we only want to use the logo area with a little
border to do a little spatio-temporal smoothing. (or some other
temporal/spatio-temporal smoother). Suggest something like:-
Code:
CROPLOGO=CROPLOGO.FFT3DFilter(interlaced=false,Plane=4,BT=3,sigma=3.0)
3c. You can vary the 'opacity' arg to Overlay() when mixing
the two de-logoed areas together (3a. and 3b. results).
Coords to use here, the x/y coords from step 1. plus the
size of the x/y cropping at step 3a.

The above multistep approach is so that we do the very slow
InPaintFunc step only once and can play with the eg opacity
arg to OverLay() to get the best settings.

Hope some of that makes sense.

Edit:-
The method of InPaintFunc filter is not really intended for video,
more for stills, and results in temporal anomalies.
The Dekafka/s_ExLogo method is not ideal either. The above
approach just allows you to mix both de-logo methods where
s_ExLogo is used to subdue InPaintFunc anomalies a little.

Have tried at step 3a. using step 2. results,
with FFT3DFilter followed by s_ExLogo (OR the other
way around) varying the s_ExLogo 'amount' arg, and
overlaying these results onto the original clip. However,
I NOW like doing it the way outlined above.

EDIT: Mistake, Changed 'AvsInpaint' to 'InPaintFunc'.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 16th June 2011 at 20:41. Reason: Spelt FFT3dFilter as FF3DFilter
StainlessS is offline   Reply With Quote
Old 18th January 2011, 18:53   #5  |  Link
tasslehoff44
Registered User
 
Join Date: Aug 2010
Posts: 14
Thanks for the answer,

I tried with the single frame, that's realy good.
But i don't really understand your tuto for the entire video.

Avisynth isn't the only tool to use for remove logo ? I have to encode in lossless avi with vdmod ?
tasslehoff44 is offline   Reply With Quote
Old 8th July 2012, 22:03   #6  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,992
Code:
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, 2, Y)
#  rightline = clip.Crop(xright, ytop-2, 2, Y)

  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
}
Can someone with Wiki editing privileges make the above two corrections to the Dekafa scipt
function in Wiki. I've seen about 3 versions, all with differently screwed coords. Only 1 version by a user
other than the author, that used the code inline rather than as
a script function, only that one had correct coords.


Dekafka here:
http://avisynth.org/mediawiki/Shared_functions/DeKafka

EDIT: Just remove the '-2' from leftline & rightline, lines.

EDIT: DID IT MYSELF, DID NOT REALIZE THAT I COULD EDIT WIKI ANONYMOUSLY.
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 9th July 2012 at 17:16.
StainlessS is offline   Reply With Quote
Reply

Tags
dekafka, delogo, logo, logo removal

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 02:30.


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