Vapoursynth InpaintDelogo

From wiki.selur.net
Jump to navigation Jump to search

InpaintDelogo removes TV logos and watermarks: opaque logos are inpainted from their surroundings, transparent ones are deblended by subtracting the logo, and both methods can be combined. It also handles moving logos, can build the mask automatically and can reuse background hidden behind the logo in neighbor frames.

Filtering → Vapoursynth → Other

InpaintDelogo controls in Hybrid
InpaintDelogo controls in Hybrid

What it does

A mask marks the logo. Inpaint fills the masked area from the pixels around it; Deblend first analyzes the clip to estimate the logo's color and transparency and then removes it, which keeps the picture behind a semi-transparent logo. Both deblends and inpaints what remains. Only the area given by Loc is processed; all other pixels keep their source values. Dynamic masks cover logos or titles that change, Track follows a moving logo, and Temporal takes the background from neighbor frames where it is visible.

Requirements

  • AvsInpaint and akarin (needs a CPU with AVX2); BestSource for mask videos, FFT3D for negative oPP/dPP, GrainFactory3 for GrainPP. Works on Windows and Linux.
  • A mask: an image of the full frame (bmp, png, jpg, tif, webp, gif) with the logo in white (255 full range, 235 or more TV range), or a mask video.
  • YUV 8 – 16 bit integer, not 4:1:0, 4:1:1 or 4:4:0; interlaced material is handled as fields.

Settings

Control Parameter Range / values Hybrid default Meaning
Mask mask image or video file empty Logo mask; empty = filter skipped. A video forces Inpaint and disables Mode and Dynamic mask.
Mode Mode Inpaint, Deblend, Both Inpaint Removal method.
Loc (left/top/right/bottom) Loc 0 – 16384 in steps of 2 0 / 0 / 0 / 0 Area that is processed; 0 = whole frame. Auto sets it from the white box of the mask plus a margin.
show – on/off off Preview only: draws the Loc area as a green rectangle.
confine to Loc – on/off on With Automask: keep the automatic mask inside Loc.
Inflate Inflate 0 – 8 1 Grows the mask by this many pixels; 3 – 4 helps when the mask misses the logo edge.
Turbo Turbo −2 – 3 0 Inpainting preset: negative = slower with larger radii (HD/UHD), positive = fast and blurry; Radius, Sharpness, PreBlur and PostBlur only apply at 0.
Radius / Sharpness / PreBlur / PostBlur Radius, Sharpness, PreBlur, PostBlur 1 – 50 / 0 – 200 / 0 – 30 / 0 – 30 8 / 45 / 6.5 / 4 Area the inpainting takes values from, how strictly it follows line directions, and the blurs before and after the line directions are measured; a changed value turns Optimize1 off.
Optimize1 Optimize1 on/off on Faster presets on frames where the logo sits on an almost uniform background; not used with a dynamic mask or positive Turbo.
KillShape KillShape on/off off Closes small holes in the mask so the inpainted area looks less busy; meant for positive Turbo, Inpaint only.
prePP prePP on/off off Blurs the Loc area before inpainting; meant for positive Turbo, not for Deblend.
Temporal Temporal 0 – 100 0 Neighbor frames on each side that may show what the logo hides (moving background); 0 = off. Inpaint with a mask image only, no Track.
Track / TrackTh Track, TrackTh on/off, 0.05 – 1 off, 0.35 Inpaint with a mask image: searches the logo shape in every frame inside Loc; TrackTh is the lowest match that counts as the logo.
Analyze Analyze 1, 2, 3 2 Frames used for the logo analysis (Deblend, Both, Automask): 1 = solid around the mask edge, 2 = solid at the Loc border, 3 = all frames. 1 cannot be used with Automask.
AnalyzeTh AnalyzeTh 1 – 255 30 Largest luma range a frame may have in the checked area to be used (8-bit scale); raise it when too few frames are found.
No border at – none, top, bottom, left, right none For Analyze 2: side where Loc has no border around the logo; the opposite strip is used instead.
ReAnalyze – on/off off Analyzes the logo again instead of reusing the cached analysis.
Interp / IntSpd / Optimize2 / EdgePP / dPP Interp, IntSpd, Optimize2, EdgePP, dPP 0 – 4 / 1 – 4 / 0 – 3 / 0 – 3 / −8 – 8 2 / 1 / 3 / 0 / −3 Deblend and Both only: blend of an inpainted version into the deblended logo, its speed, its per-frame optimizations, inpainting of the mask edges, and post-processing of the deblended area.
oPP / oPPm oPP, oPPm −8 – 8 / 0 – 3 −5 / 3 Post-processing of the inpainted area: positive values blur, negative values blur and denoise with FFT3D, 0 = off; oPPm adds a soft border to its mask.
GrainPP GrainPP 0 – 3 0 Adds grain to the delogoed area so it blends into grainy surroundings; 0 = off.
Greyscale – on/off off For grayscale video: only luma is processed, the chroma of the output is neutral.
Dynamic mask DynMask off, luma, luma (temporal), subtitles, gradient, color off Builds the mask per frame: bright pixels, bright pixels that stay, bright text with a dark outline, edges, or one color. Inpaint mode; Both only luma.
Luma threshold DynTune 1 – 254 200 Brightness threshold of the dynamic mask (8-bit scale).
Color / Tolerance / Color inflate – RRGGBB / 1 – 140 / 0 – 4 FFFFFF / 10 / 1 Color dynamic mask.
Mask inflate – 0 – 10 0 Grows the dynamic mask; not for gradient.
Automask / aMix – on/off, −50 – 6 off, 0 Creates the mask from an analysis of the clip and saves it next to the mask or source file; needs a Loc that frames the logo. aMix makes the mask thinner or thicker.
Show – off, 1, 2, Automask view off Preview only: shows intermediate results.

Example

Mask J:/tmp/claude/wiki/assets/logo_mask.png (640x356, white box in the top right corner; no mask is set by default), otherwise default settings, on a 10-bit YUV 4:2:0 source (640x356):

# removing logo with InpaintDelogo
clip = inpaintdelogo.InpaintDelogo(clip, mask="J:/tmp/claude/wiki/assets/logo_mask.png", Loc="0,0,-0,-0", tools={'expr': 'akarin', 'rg': 'zsmooth', 'hysteresis': 'hysteresis', 'fft3d': 'neo_fft', 'grain': 'noise', 'scd': 'scd'})

How Hybrid calls it

  • Only values that differ from the script defaults are written; AnalyzeTh is always written, because the script would use 16 instead of 30 on clips with 45000 frames or more.
  • For Deblend and Both the analysis result is cached in Hybrid's temp folder, per mask, Loc and analysis settings.
  • The filter is skipped with a comment when there is no mask or the mask has no white pixels, or only white pixels, inside Loc.
  • Processing runs on the Loc area in 8-bit 4:2:0 internally, so 8-bit thresholds need no scaling.
  • Tools group: expr (akarin, cranexpr), rg (zsmooth, neo_smo), hysteresis (hysteresis, misc on Windows), fft3d (neo_fft); with GrainPP above 0 also grain (noise, grain on Linux/macOS) and scd (scd, misc on Windows, std, mv; default scd).

Background

InpaintDelogo is an AviSynth+ script by VoodooFX for removing opaque, semi-transparent and some dynamic logos, and also for removing or extracting hard subtitles. Hybrid uses a VapourSynth port of version 3.7 that extends Inflate up to 8 and adds Track and Temporal; Show modes above 2 and negative Analyze values are not ported.

AvsInpaint

AvsInpaint provides the core functions (inpainting, logo analysis, deblending, distance function) for AviSynth and VapourSynth.

Sources