Skip to content

Commit

Permalink
hdcam_dering: Add pre-descaled clip
Browse files Browse the repository at this point in the history
  • Loading branch information
LightArrowsEXE committed Nov 25, 2023
1 parent c5a2fc1 commit b927440
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions lvsfunc/hdcam.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@

def hdcam_dering(
clip: vs.VideoNode,
kernel: KernelT = Lanczos(taps=4),
kernel: KernelT | vs.VideoNode = Lanczos(taps=4),
upscaler: ScalerT = Nnedi3,
limiter: bool | Callable[[vs.VideoNode, vs.VideoNode, vs.VideoNode], vs.VideoNode] = True,
show_mask: bool = False
Expand All @@ -39,26 +39,35 @@ def hdcam_dering(
:param clip: Clip to process.
:param kernel: Kernel used for descaling. Defaults to Lanczos 4-tap.
Optionally, if a VideoNode is passed, it will replace the descaled clip with that.
:param upscaler: Primary scaler used for re-upscaling. This should ideally not be too sharp,
so you shouldn't use Waifu2x or FSRCNNX with this. Defaults to Nnedi3.
:param limiter: Whether to limit the clip or not. If a callable is passed, it will run that instead.
The callable must accept a src, a filtered clip, and a ref clip.
Defaults to True.
:param show_mask: Return the mask. Defaults to False.
:return: Deringed clip or the mask if show_mask=True.
:return: Deringed clip or the ringing mask if show_mask=True.
"""
func = FunctionUtil(clip, hdcam_dering, 0, (vs.YUV, vs.GRAY), 16)

kernel = Kernel.ensure_obj(kernel, func.func)
if not isinstance(kernel, vs.VideoNode):
kernel = Kernel.ensure_obj(kernel, func.func)

upscaler = Scaler.ensure_obj(upscaler, func.func)

if (clip.width, clip.height) != (1920, 1080):
raise CustomValueError("You must pass a 1920x1080 clip!", func.func, (clip.width, clip.height))

clip_y = plane(func.work_clip, 0)

descaled_y = kernel.descale(clip_y, 1440, clip.height)
if isinstance(kernel, vs.VideoNode):
descaled_y = plane(kernel, 0)
elif isinstance(kernel, Kernel):
descaled_y = kernel.descale(clip_y, 1440, clip.height)
else:
raise CustomValueError(f"Could not determine how to handle the given kernel, \"{kernel=}\"!", hdcam_dering)

ret_y = retinex(descaled_y)

kirsch = Kirsch(MagDirection.E | MagDirection.W).edgemask(ret_y)
Expand Down

0 comments on commit b927440

Please sign in to comment.