示例#1
0
文件: lvsfunc.py 项目: RisGar/lvsfunc
def quick_denoise(clip: vs.VideoNode,
                  ref: vs.VideoNode = None,
                  cmode: str = 'knlm',
                  sigma: float = 2,
                  **kwargs) -> vs.VideoNode:
    funcname = "quick_denoise"
    """
    A rewrite of my old 'quick_denoise'. I still hate it, but whatever.
    This will probably be removed in a future commit.

    This wrapper is used to denoise both the luma and chroma using various denoisers of your choosing.
    If you wish to use just one denoiser,
    you're probably better off using that specific filter rather than this wrapper.

    BM3D is used for denoising the luma.

    Special thanks to kageru for helping me out with some ideas and pointers.

    :param sigma:               Denoising strength for BM3D
    :param cmode:               Chroma denoising modes:
                                 1 - Use knlmeans for denoising the chroma
                                 2 - Use tnlmeans for denoising the chroma
                                 3 - Use dfttest for denoising the chroma (requires setting 'sbsize' in kwargs)
                                 4 - Use SMDegrain for denoising the chroma
    :param ref: vs.VideoNode:  Optional reference clip to replace BM3D's basic estimate

    """
    y, u, v = kgf.split(clip)
    cmode = cmode.lower()

    if cmode in [1, 'knlm', 'knlmeanscl']:
        den_u = u.knlm.KNLMeansCL(d=3, a=2, **kwargs)
        den_v = v.knlm.KNLMeansCL(d=3, a=2, **kwargs)
    elif cmode in [2, 'tnlm', 'tnlmeans']:
        den_u = u.tnlm.TNLMeans(ax=2, ay=2, az=2, **kwargs)
        den_v = v.tnlm.TNLMeans(ax=2, ay=2, az=2, **kwargs)
    elif cmode in [3, 'dft', 'dfttest']:
        if 'sbsize' in kwargs:
            den_u = u.dfttest.DFTTest(sosize=kwargs['sbsize'] * 0.75, **kwargs)
            den_v = v.dfttest.DFTTest(sosize=kwargs['sbsize'] * 0.75, **kwargs)
        else:
            return error(funcname, "'sbsize' not specified")
    elif cmode in [4, 'smd', 'smdegrain']:
        den_u = haf.SMDegrain(u, prefilter=3, **kwargs)
        den_v = haf.SMDegrain(v, prefilter=3, **kwargs)
    else:
        return error(funcname, 'unknown cmode')

    den_y = mvf.BM3D(y, sigma=sigma, psample=0, radius1=1, ref=ref)
    return core.std.ShufflePlanes([den_y, den_u, den_v], 0, vs.YUV)
示例#2
0
    def main(self: Filtering) -> vs.VideoNode:  # noqa
        """Vapoursynth filtering"""
        src = WEB.clip_cut
        src = src.std.AssumeFPS(src)


        src = depth(src, 16)
        out = src


        denoise = hvf.SMDegrain(out, tr=1, thSAD=100, thSADC=100)
        out = denoise


        dering = hvf.EdgeCleaner(out, 15, smode=1, hot=True)
        dering = gf.MaskedDHA(dering, darkstr=0.05, brightstr=0.75)
        out = dering


        aaa = vdf.scale.nnedi3_upscale(get_y(out), pscrn=1, correct_shift=False)
        aaa = aaa.resize.Bicubic(1920, 1080, src_left=0.5, src_top=0.5, filter_param_a=-0.5, filter_param_b=0.25)
        out = vdf.misc.merge_chroma(aaa, out)


        cwarp = xvs.WarpFixChromaBlend(out, 64, depth=4)
        out = cwarp


        detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1200)
        deband = vdf.deband.dumb3kdb(out, 16, threshold=33, grain=[24, 0])
        deband = core.std.MaskedMerge(deband, out, detail_mask)
        out = deband


        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])[:100]
示例#3
0
def _dbgra(clip: vs.VideoNode) -> vs.VideoNode:
    clip = depth(clip, 16)
    clip = hvf.SMDegrain(clip, tr=1, thSAD=200)
    clip = vdf.deband.dumb3kdb(clip, threshold=45)
    clip = core.std.Expr(clip, ['x 64 -', 'x 32 +', 'x 32 +'])
    clip = kgf.adaptive_grain(clip, 0.4)
    return clip
示例#4
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src



    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise

    crop = core.std.Crop(out, left=12)
    crop = awf.bbmod(crop, left=2, thresh=20 << 8)
    resize = core.resize.Bicubic(crop, 1920)
    out = lvf.rfs(out, resize, [(78, 89)])


    y = get_y(out)
    lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate()

    fkrescale = fake_rescale(
        y, 882, 0, 1,
        deringer=lambda x: gf.MaskedDHA(x, rx=1.85, ry=1.85, darkstr=0.25, brightstr=1.0, maskpull=100, maskpush=200),
        antialiser=lambda c: lvf.sraa(c, 2, 13, downscaler=core.resize.Bicubic)
    )
    merged = core.std.MaskedMerge(y, fkrescale, lineart)
    out = vdf.merge_chroma(merged, out)


    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering


    out = lvf.rfs(
        out, denoise,
        [(0, 11), (38, 77), (115, 133), (316, 395), (441, 460), (606, 779), (825, 844), (990, 1127)]
    )




    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband




    grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333)
    out = grain


    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz



    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#5
0
def do_filter() -> vs.VideoNode:
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    out = src

    luma = get_y(out)
    rows = [
        core.std.CropAbs(luma, out.width, 1, top=out.height - 1),
        core.std.CropAbs(luma, out.width, 1, top=out.height - 2)
    ]
    diff = core.std.Expr(rows, 'x y - abs').std.PlaneStats()

    row_fix = vdf.merge_chroma(
        luma.fb.FillBorders(bottom=1, mode="fillmargins"),
        out.fb.FillBorders(bottom=2, mode="fillmargins"))

    fixrow = core.std.FrameEval(out,
                                partial(_select_row, clip=out,
                                        row_fix=row_fix),
                                prop_src=diff)
    out = fixrow

    fixedge_a = awf.bbmod(out, 1, 1, 1, 1, 20, blur=700, u=False, v=False)

    fixedge = out
    fixedge = lvf.rfs(fixedge, fixedge_a, [(EDSTART + 309, EDEND)])
    out = fixedge

    out = depth(out, 16)

    dehalo = gf.MaskedDHA(out, rx=1.4, ry=1.4, darkstr=0.02, brightstr=1)
    dehalo = lvf.rfs(out, dehalo, [(EDEND + 1, src.num_frames - 1)])
    out = dehalo

    resize = core.std.Crop(out, right=12, bottom=8).resize.Bicubic(1920, 1080)
    resize = lvf.rfs(out, resize, [(27005, 27076)])
    out = resize

    # Denoising only the chroma
    pre = hvf.SMDegrain(out, tr=2, thSADC=300, plane=3)
    planes = split(out)
    planes[1], planes[2] = [
        mvf.BM3D(planes[i], 1.25, radius2=2, pre=plane(pre, i))
        for i in range(1, 3)
    ]
    out = join(planes)

    preden = core.dfttest.DFTTest(out, sbsize=16, sosize=12, tbsize=1)
    detail_mask = lvf.mask.detail_mask(preden, brz_a=2500, brz_b=1500)

    deband = vdf.dumb3kdb(preden, 16, threshold=[17, 17], grain=[24, 0])
    deband = core.std.MergeDiff(deband, out.std.MakeDiff(preden))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    decz = vdf.decsiz(out, min_in=128 << 8, max_in=192 << 8)
    out = decz

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#6
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    out = depth(src, 16)

    denoise = hvf.SMDegrain(out, thSAD=150, thSADC=75)
    out = denoise

    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(
        75 << 8).std.Maximum().std.Inflate()

    antialias = lvf.sraa(y,
                         1.5,
                         9,
                         downscaler=core.resize.Spline36,
                         gamma=200,
                         mdis=18)

    sharp = hvf.LSFmod(antialias,
                       strength=95,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)

    minmax = core.std.Expr([y, sharp, antialias], 'x y z min max y z max min')
    merge = core.std.MaskedMerge(y, minmax, lineart)
    out = vdf.merge_chroma(merge, out)

    y = get_y(out)
    detail_dark_mask = detail_dark_mask_func(y, brz_a=10000, brz_b=9000)
    detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

    detail_mask = core.std.Expr([y, detail_mask_grow, detail_mask],
                                f'x {28<<8} < y z ?')

    deband = dbs.f3kpf(out, 17, 24, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.2,
                        0.1,
                        1.25,
                        luma_scaling=14,
                        sharp=80,
                        static=False,
                        lo=19,
                        hi=[192, 240])
    out = grain

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#7
0
def do_filter() -> vs.VideoNode:
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    out = src

    luma = get_y(out)
    rows = [
        core.std.CropAbs(luma, out.width, 1, top=out.height - 1),
        core.std.CropAbs(luma, out.width, 1, top=out.height - 2)
    ]
    diff = core.std.Expr(rows, 'x y - abs').std.PlaneStats()

    row_fix = vdf.merge_chroma(
        luma.fb.FillBorders(bottom=1, mode="fillmargins"),
        out.fb.FillBorders(bottom=2, mode="fillmargins"))

    fixrow = core.std.FrameEval(out,
                                partial(_select_row, clip=out,
                                        row_fix=row_fix),
                                prop_src=diff)
    out = fixrow

    out = depth(out, 16)

    # Denoising only the chroma
    pre = hvf.SMDegrain(out, tr=2, thSADC=300, plane=3)
    planes = split(out)
    planes[1], planes[2] = [
        mvf.BM3D(planes[i], 1.25, radius2=2, pre=plane(pre, i))
        for i in range(1, 3)
    ]
    out = join(planes)

    preden = core.dfttest.DFTTest(out, sbsize=16, sosize=12, tbsize=1)
    detail_mask = lvf.mask.detail_mask(preden, brz_a=2500, brz_b=1500)

    deband = vdf.dumb3kdb(preden, 16, threshold=[17, 17], grain=[24, 0])
    deband = core.std.MergeDiff(deband, out.std.MakeDiff(preden))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    decz = vdf.decsiz(out, min_in=128 << 8, max_in=192 << 8)
    out = decz

    ref = depth(src, 16)
    credit = out
    credit = lvf.rfs(out, ref, CREDITS)
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#8
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = depth(denoise, 16)

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([*[1] * 9])

    detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband_b = dumb3kdbv2(out, 24, 64)
    deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask)
    deband = lvf.rfs(deband, deband_b, [(414, 496)])

    out = deband

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#9
0
文件: lvsfunc.py 项目: kageru/lvsfunc
def quick_denoise(clip: vs.VideoNode, mode='knlm', bm3d=True, sigma=3, h=1.0, refine_motion=True, sbsize=16, resample=True):
    """
    Wrapper for generic denoising. Denoising is done by BM3D with a given denoisers being used for ref. Returns the denoised clip used
    as ref if BM3D=False.

    Mode 1 = KNLMeansCL
    Mode 2 = SMDegrain
    Mode 3 = DFTTest

    Will be removed eventuallyTM.
    """
    if resample:
        if clip.format.bits_per_sample != 16:
            clip = fvf.Depth(clip, 16)
    clipY = core.std.ShufflePlanes(clip, 0, vs.GRAY)

    if mode in [1, 'knlm']:
        denoiseY = clipY.knlm.KNLMeansCL(d=3, a=2, h=h)
    elif mode in [2, 'SMD', 'SMDegrain']:
        denoiseY = haf.SMDegrain(clipY, prefilter=3, RefineMotion=refine_motion)
    elif mode in [3, 'DFT', 'dfttest']:
        denoiseY = clipY.dfttest.DFTTest(sigma=4.0, tbsize=1, sbsize=sbsize, sosize=sbsize*0.75)
    else:
        raise ValueError('denoise: unknown mode')

    if bm3d:
        denoisedY = mvf.BM3D(clipY, sigma=sigma, psample=0, radius1=1, ref=denoiseY)
    elif bm3d is False:
        denoisedY = denoiseY

    if clip.format.color_family is vs.GRAY:
        return denoisedY
    else:
        srcU = clip.std.ShufflePlanes(1, vs.GRAY)
        srcV = clip.std.ShufflePlanes(2, vs.GRAY)
        merged = core.std.ShufflePlanes([denoisedY, srcU, srcV], 0, vs.YUV)
        return merged
示例#10
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src



    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise



    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering


    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband




    grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333)
    out = grain


    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz



    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#11
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    opstart, opend = 6161, 8319
    eptitle_s, eptitle_e = 8320, 8439
    edstart, edend = 31170, 33326
    preview_s, preview_e = 33687, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = denoise

    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', 0.055,
                              (1, 1)).std.Median().std.Convolution([*[1] * 9])

    descale = core.descale.Debilinear(y, w, h)

    upscale = vdf.fsrcnnx_upscale(
        descale,
        height=h * 2,
        shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
        upscaler_smooth=eedi3_upscale,
        profile='slow',
        strength=85)

    antialias = sraa_eedi3(upscale, 9)

    downscale = muvf.SSIM_downsample(antialias,
                                     src.width,
                                     src.height,
                                     filter_param_a=0,
                                     filter_param_b=0)
    downscale = core.std.MaskedMerge(y, downscale, lineart)

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([*[1] * 9])

    detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    dehalo_ref = gf.MaskedDHA(ref,
                              rx=1.65,
                              ry=1.65,
                              darkstr=0.15,
                              brightstr=1.0,
                              maskpull=48,
                              maskpush=140)
    dehalo_mask_a = vdf.region_mask(rescale_mask, top=650)
    dehalo_mask_b = vdf.region_mask(rescale_mask, right=400)

    credit = out
    dehalo_range_a = [(25, 205), (518, 612), (2090, 2172), (14449, 14537)]
    dehalo_range_b = [(3893, 3981)]
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0),
                     [(2197, 2252), (4072, 4129), (4409, 4527), (5390, 5484),
                      (8473, 8603), (8610, 8669), (9826, 9909), (10666, 10713),
                      (12088, 12507), (14943, 15052), (17988, 18136),
                      (18897, 18976),
                      (edstart, edend)] + dehalo_range_a + dehalo_range_b)
    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_a, 0),
        dehalo_range_a)
    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_b, 0),
        dehalo_range_b)
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#12
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    # src += src[-1]
    src = depth(src, 16)
    out = src

    opstart, opend = 480, 2637
    edstart, edend = 32249, 34405



    # Remove the noise
    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, sigma=[2, 1], radius1=1, ref=ref)
    out = denoise




    # Limited antialiasing
    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(75<<8).std.Maximum().std.Inflate()
    aa = lvf.sraa(y, 2, 13, downscaler=partial(core.resize.Bicubic, filter_param_a=-0.5, filter_param_b=0.25))
    sharp = hvf.LSFmod(aa, strength=70, Smode=3, edgemode=0, source=y)


    y = core.std.MaskedMerge(y, sharp, lineart)
    out = vdf.merge_chroma(y, out)






    # Deband masks
    planes = split(out)

    preden = core.dfttest.DFTTest(out, sigma=14.0, sigma2=10.0, sbsize=1, sosize=0).rgvs.RemoveGrain(3)
    grad_mask, yrangebig = morpho_mask(preden)


    rgb = core.resize.Bicubic(preden, 960, 540, format=vs.RGB48).std.SetFrameProp('_Matrix', delete=True)
    chroma_masks = [core.std.Prewitt(p).std.Binarize(5500).rgvs.RemoveGrain(11) for p in split(rgb) + split(preden)[1:]]
    chroma_mask = core.std.Expr(chroma_masks, 'x y + z + a + b +').std.Maximum()
    chroma_mask = core.std.Merge(chroma_mask, chroma_mask.std.Minimum()).std.BoxBlur(0, 1, 1, 1, 1)

    fdogmask = vdf.edge_detect(preden.std.Median(), 'FDOG', 8250, (4, 1)).std.BoxBlur(0, 2, 1, 2, 1)
    detail_mask = lvf.denoise.detail_mask(planes[0].std.BoxBlur(0, 1, 1, 1, 1), brz_a=3300, brz_b=2000)


    # Debanding stages
    debands = [None] * 3
    deband_y_strong = dbs.f3kbilateral(planes[0], 16, 65)
    deband_y_normal = dumb3kdb(planes[0], 16, 36)
    deband_y_light = core.std.MaskedMerge(dumb3kdb(planes[0], 14, 32), planes[0], detail_mask)
    debands[1] = dbs.f3kbilateral(planes[1], 12, 50)
    debands[2] = dbs.f3kbilateral(planes[2], 12, 50)


    debands[0] = core.std.MaskedMerge(deband_y_strong, deband_y_normal, grad_mask)
    debands[0] = core.std.MaskedMerge(debands[0], deband_y_light, yrangebig)
    debands[1], debands[2] = [core.std.MaskedMerge(debands[i], planes[i], chroma_mask) for i in range(1, 3)]
    deband = join(debands)
    deband = lvf.rfs(deband, core.std.MaskedMerge(dbs.f3kbilateral(out, 20, 97), out, fdogmask), [(opstart+2019, opstart+2036), (opstart+1504, opstart+1574)])
    out = deband


    # Regraining
    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 25)
    adgmask_b = core.adg.Mask(ref, 10)

    stgrain_a = core.grain.Add(out, 0.1, 0, seed=333)
    stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert())

    stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, seed=333)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert())
    stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

    dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, seed=333)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain



    # Credits OP and ED
    ref = src
    src_ncop, src_nced = [depth(c, 16) for c in [JPBD_NCOP.src_cut, JPBD_NCED.src_cut]]
    src_c, src_ncop, src_nced = [c.std.BoxBlur(0, 2, 1, 2, 1) for c in [src, src_ncop, src_nced]]

    opening_mask = vdf.dcm(out, src_c[opstart:opend+1], src_ncop[:opend-opstart+1], opstart, opend, 2, 2)
    ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2)
    credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +').std.Inflate()

    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask), [(opstart, opend), (edstart, edend)])
    out = credit





    # Fix letterboxes ending
    crop = core.std.Crop(out, 0, 0, 132, 132).edgefixer.ContinuityFixer(0, 1, 0, 0)
    crop = core.std.AddBorders(crop, 0, 0, 132, 132)
    out = lvf.rfs(out, crop, [(edstart, edend)])




    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
示例#13
0
    def main(self: Filtering) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        out = src


        h = 800  # noqa
        w = get_w(h)  # noqa
        opstart, opend = 2830, 4986
        edstart, edend = 31504, 33661




        inp = get_y(out)
        out = inp



        # Remove the grain
        ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=0)
        preden = mvf.BM3D(out, sigma=2, radius1=1, ref=ref)
        out = preden




        # Rescale / Antialiasing / Limiting
        out = depth(out, 32)
        lineart = vdf.mask.FDOG().get_mask(out, lthr=0.065, hthr=0.065).std.Maximum().std.Minimum()
        lineart = lineart.std.Median().std.Convolution([1] * 9)


        descale_clips = [core.resize.Bicubic(out, w, h, filter_param_a=1/3, filter_param_b=1/3),
                         core.descale.Debicubic(out, w, h, 0, 1/2),
                         core.descale.Debilinear(out, w, h)]
        descale = core.std.Expr(descale_clips, 'x y z min max y z max min z min')

        upscale = vdf.scale.fsrcnnx_upscale(descale, height=h * 2, shader_file=r'_shaders\FSRCNNX_x2_56-16-4-1.glsl',
                                            upscaled_smooth=vdf.scale.eedi3_upscale(descale), profile='zastin',
                                            sharpener=partial(gf.DetailSharpen, sstr=1.65, power=4, mode=0, med=True))


        antialias = self.sraa_eedi3(upscale, 3, alpha=0.2, beta=0.4, gamma=100, mdis=20, nrad=3)

        downscale = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic', filter_param_a=0, filter_param_b=0)

        adaptmask = core.adg.Mask(downscale.std.PlaneStats(), 25).std.Minimum().std.Minimum().std.Convolution([1] * 9)
        contra = gf.ContraSharpening(downscale, depth(preden, 32), radius=2).rgsf.Repair(downscale, 1)
        contra = core.std.MaskedMerge(downscale, contra, adaptmask)


        scaled = core.std.MaskedMerge(out, contra, lineart)
        merged = vdf.misc.merge_chroma(depth(scaled, 16), src)
        out = merged


        detail_light_mask = lvf.mask.detail_mask(out, brz_a=1500, brz_b=600)

        deband = vdf.deband.dumb3kdb(out, 16, [33, 1], sample_mode=4, use_neo=True)
        deband = core.std.MaskedMerge(deband, out, detail_light_mask)
        out = deband


        # Restore the grain
        neutral = inp.std.BlankClip(960, 540, color=128 << 8)
        diff = join([inp.std.MakeDiff(preden), neutral, neutral])
        grain = core.std.MergeDiff(out, diff)
        out = grain



        crop_a = self.crop_and_fix(out, src, top=128, bottom=136)
        crop_b = self.crop_and_fix(out, src, top=132, bottom=140)
        crop = out
        crop = lvf.rfs(crop, crop_a, [(25696, 25750), (25768, 25963), (26916, 27095),
                                      (27213, 27319), (27368, 27395), (27615, 27810)])
        crop = lvf.rfs(crop, crop_b, [(25751, 25767), (25964, 26723), (26786, 26915),
                                      (27096, 27212), (27320, 27367), (27396, 27614)])
        out = crop




        ref = src
        creditless_mask = vdf.mask.diff_creditless_mask(
            ref, src[opstart:opend+1], JPBD_NCOP.clip_cut[:opend-opstart+1], opstart, thr=25 << 8, sw=3, sh=3, prefilter=True
        ).std.Deflate()
        ringing_mask = hvf.HQDeringmod(ref, mrad=1, msmooth=2, mthr=40, show=True)

        credit = out
        credit = lvf.rfs(credit, ref, [(edstart, edend)])
        credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, creditless_mask, 0), [(opstart, opend)])
        credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ringing_mask, 0),
                         [(opstart + 169, opstart + 411)])
        out = credit



        endcard = out + out[31757] * 119
        out = endcard


        decs = vdf.noise.decsiz(out, sigmaS=10, min_in=110 << 8, max_in=192 << 8, gamma=1.1)
        out = decs


        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#14
0
    def main(self: Filtering) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        out = src


        h = 800  # noqa
        w = get_w(h)  # noqa
        edstart, edend = 31384, 33540



        inp = get_y(out)
        out = inp



        # Remove the grain
        ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=0)
        preden = mvf.BM3D(out, sigma=2, radius1=1, ref=ref)
        out = preden




        # Rescale / Antialiasing / Limiting
        out = depth(out, 32)
        lineart = vdf.mask.FDOG().get_mask(out, lthr=0.065, hthr=0.065).std.Maximum().std.Minimum()
        lineart = lineart.std.Median().std.Convolution([1] * 9)


        descale_clips = [core.resize.Bicubic(out, w, h, filter_param_a=1/3, filter_param_b=1/3),
                         core.descale.Debicubic(out, w, h, 0, 1 / 2),
                         core.descale.Debilinear(out, w, h)]
        descale = core.std.Expr(descale_clips, 'x y z min max y z max min z min')

        upscale = vdf.scale.fsrcnnx_upscale(descale, height=h * 2, shader_file=r'_shaders\FSRCNNX_x2_56-16-4-1.glsl',
                                            upscaled_smooth=vdf.scale.eedi3_upscale(descale), profile='zastin',
                                            sharpener=partial(gf.DetailSharpen, sstr=1.65, power=4, mode=0, med=True))


        antialias = self.sraa_eedi3(upscale, 3, alpha=0.2, beta=0.4, gamma=100, mdis=20, nrad=3)

        downscale = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic', filter_param_a=0, filter_param_b=0)

        adaptmask = core.adg.Mask(downscale.std.PlaneStats(), 25).std.Minimum().std.Minimum().std.Convolution([1] * 9)
        contra = gf.ContraSharpening(downscale, depth(preden, 32), radius=2).rgsf.Repair(downscale, 1)
        contra = core.std.MaskedMerge(downscale, contra, adaptmask)


        scaled = core.std.MaskedMerge(out, contra, lineart)
        merged = vdf.misc.merge_chroma(depth(scaled, 16), src)
        out = merged


        detail_light_mask = lvf.mask.detail_mask(out, brz_a=1500, brz_b=600)

        deband_a = vdf.deband.dumb3kdb(out, 16, [33, 1], sample_mode=4, use_neo=True)
        deband_b = vdf.deband.dumb3kdb(out, 17, 40)
        deband = lvf.rfs(deband_a, deband_b, [(11812, 11931), (33541, 33600)])

        deband = core.std.MaskedMerge(deband, out, detail_light_mask)
        out = deband



        # Restore the grain
        neutral = inp.std.BlankClip(960, 540, color=128 << 8)
        diff = join([inp.std.MakeDiff(preden), neutral, neutral])
        grain = core.std.MergeDiff(out, diff)
        out = grain



        ref = src
        credit = out
        credit = lvf.rfs(credit, ref, [(edstart, edend)])
        out = credit



        endcard = out + out[31717] * 121
        out = endcard


        decs = vdf.noise.decsiz(out, sigmaS=10, min_in=110 << 8, max_in=192 << 8, gamma=1.1)
        out = decs


        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#15
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    opstart, opend = 2038, 4196
    eptitle_s, eptitle_e = 4197, 4316
    edstart, edend = 31530, 33687
    preview_s, preview_e = 33688, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = denoise

    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', 0.055,
                              (1, 1)).std.Median().std.Convolution([*[1] * 9])

    descale = core.descale.Debilinear(y, w, h)

    upscale = vdf.fsrcnnx_upscale(
        descale,
        height=h * 2,
        shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
        upscaler_smooth=eedi3_upscale,
        profile='slow',
        strength=85)

    antialias = sraa_eedi3(upscale, 9)

    downscale = muvf.SSIM_downsample(antialias,
                                     src.width,
                                     src.height,
                                     filter_param_a=0,
                                     filter_param_b=0)
    downscale = core.std.MaskedMerge(y, downscale, lineart)

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([*[1] * 9])

    detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband_b = dumb3kdbv2(out, 24, 64)
    deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask)
    deband = lvf.rfs(deband, deband_b, [(opstart + 414, opstart + 496)])

    out = deband

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0), [(8993, 9066),
                                                       (20104, 20223),
                                                       (edstart, edend)])

    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#16
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut

        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub

        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y],
                                  f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y,
                                   src_web_y.std.Convolution([1] * 9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        bdweb = lvf.rfs(bdweb, src_web_y, [(64, 1413), (32034, 33195),
                                           (33465, 33881), (34174, 34524)])
        out = vdf.misc.merge_chroma(bdweb, src)

        # ranges_frames = [
        #     (64, 131), (215, 292), (339, 410), (444, 515), (566, 657),
        #     (695, 786), (903, 971), (977, 1045), (1058, 1153), (1278, 1335),
        #     (1355, 1413)
        # ]
        # cm = partial(vdf.mask.region_mask, clip=out.std.BlankClip(format=vs.GRAY16, color=65535))

        # credit_mask = [
        #     cm()
        # ]

        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = out
        bdchanges = lvf.rfs(bdchanges, dering_src, [(882, 902), (5596, 5701),
                                                    (9909, 10064),
                                                    (11804, 11864)])
        bdchanges = lvf.rfs(bdchanges,
                            core.std.MaskedMerge(out, dering_src, diff_mask),
                            [(2534, 2682), (2840, 2887), (3188, 3271),
                             (3818, 3859), (3986, 4087), (4499, 4618),
                             (5009, 5088), (14736, 14801), (15744, 15872),
                             (17106, 17135), (17913, 18143), (24247, 24438),
                             (33196, 33329), (34021, 34173)])
        # return bdchanges, diff_mask
        out = bdchanges

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_d = vdf.deband.dumb3kdb(out, 17, 65)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_d, [(3920, 3985)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a,
                                         adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b,
                                         adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out,
                           0.3,
                           0.1,
                           1.25,
                           sharp=80,
                           static=False,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
示例#17
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    edstart1, edend1 = 37428, 37428 + 2160
    edstart2, edend2 = edend1 + 12, edend1 + 2160




    ref = hvf.SMDegrain(out, thSAD=300)
    denoise = mvf.BM3D(out, [1.5, 1.25], radius1=1, ref=ref)
    out = denoise




    y = get_y(out)
    lineart = gf.EdgeDetect(y, 'scharr').morpho.Dilate(2, 2).std.Inflate()

    fkrescale = fake_rescale(
        y, 882, 0, 1,
        deringer=lambda x: gf.MaskedDHA(x, rx=1.85, ry=1.85, darkstr=0.25, brightstr=1.0, maskpull=100, maskpush=200),
        antialiser=lambda c: lvf.sraa(c, 2, 13, downscaler=core.resize.Bicubic)
    )
    merged = core.std.MaskedMerge(y, fkrescale, lineart)
    out = vdf.merge_chroma(merged, out)


    dering = hvf.EdgeCleaner(out, 17, smode=1, hot=True)
    out = dering



    out = lvf.rfs(out, denoise, [(edstart1, src.num_frames - 1)])


    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1000)
    deband = vdf.dumb3kdb(out, 15, threshold=17, grain=(24, 0))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband




    grain = adptvgrnMod(out, 0.3, static=True, grain_chroma=False, hi=[128, 240], seed=333)
    out = grain


    decz = vdf.decsiz(out, min_in=128 << 8, max_in=200 << 8)
    out = decz



    ref = depth(src, 16)
    src_c, src_nced1, src_nced2 = [
        depth(x, 16).std.Convolution(
            [1, 2, 1, 2, 4, 2, 1, 2, 1]
        ) for x in [src, JPBD_NCED1.src_cut, JPBD_NCED2.src_cut]
    ]

    ending_mask1 = vdf.dcm(out, src_c[edstart1:edend1 + 1], src_nced1[:edend1 - edstart1 + 1], edstart1, edend1, 2, 2)
    ending_mask2 = vdf.dcm(out, src_c[edstart2:edend2 + 1], src_nced2[:edend2 - edstart2 + 1], edstart2, edend2, 2, 2)
    ending_mask = core.std.Expr([ending_mask1, ending_mask2], 'x y +')
    ending_mask = iterate(ending_mask, core.std.Inflate, 4)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ending_mask), [(edstart1, edend2)])
    credit = lvf.rfs(credit, ref, [(21594, 21737), (39589, 39599), (41744, src.num_frames - 1)])
    out = credit


    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#18
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    h = 900
    w = get_w(h)

    # Remove the grain
    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    degrain = mvf.BM3D(out, sigma=[1.5, 1], radius1=1, ref=ref)
    degrain = insert_clip(degrain, smhdegrain(out[5539:5670], 2, 280), 5539)
    degrain = insert_clip(degrain, smhdegrain(out[5933:5992], 2, 200), 5933)
    degrain = insert_clip(degrain, smhdegrain(out[6115:6180], 2, 200), 6115)
    degrain = insert_clip(degrain, smhdegrain(out[6180:6281], 2, 200), 6180)
    degrain = insert_clip(degrain, smhdegrain(out[39303:39482], 2, 280), 39303)
    degrain = insert_clip(degrain, smhdegrain(out[40391:40837], 2, 200), 40391)
    degrain = insert_clip(degrain, smhdegrain(out[40908:41087], 2, 280), 40908)
    degrain = insert_clip(degrain, smhdegrain(out[41671:41791], 2, 280), 41671)
    degrain = insert_clip(degrain, smhdegrain(out[41791:41977], 2, 280), 41791)
    degrain = insert_clip(degrain, smhdegrain(out[41977:42073], 2, 280), 41977)

    degrain = insert_clip(degrain, smhdegrain(out[43083:44462], 2, 350), 43083)
    degrain = lvf.rfs(degrain, out, [(51749, 52387)])
    out = depth(degrain, 32)

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'kirsch', 0.075,
                                (1, 1)).std.Median().std.Inflate()

    descale = core.descale.Debilinear(luma, w, h)
    upscale = eedi3_upscale(descale)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.2,
                                         beta=0.6,
                                         gamma=300,
                                         mdis=15).resize.Bicubic(
                                             src.width, src.height)

    rescale = core.std.MaskedMerge(luma, antialias, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    y = get_y(out)
    detail_light_mask = lvf.denoise.detail_mask(y.std.Median(),
                                                brz_a=2500,
                                                brz_b=1200)

    pf = out.std.Convolution([1] * 9).std.Merge(out, 0.45)

    diffdb = core.std.MakeDiff(out, pf)

    deband = dumb3kdb(pf, 16, 30)
    deband_b = dbs.f3kbilateral(pf, 20, 100)
    deband = lvf.rfs(deband, deband_b, [(43083, 44461)])

    deband = core.std.MergeDiff(deband, diffdb)
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)

    deband = lvf.rfs(deband, out, [(51749, 52387)])
    out = deband

    sharp = hvf.LSFmod(out,
                       strength=65,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.00)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.05, sharp=60, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = src
    rescale_mask = vdf.drm(ref, h, mthr=65, sw=4, sh=4)
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0), [(0, 2956),
                                                       (43104, 45749)])
    credit = lvf.rfs(credit, ref, [(45824, 50401),
                                   (52388, src.num_frames - 1)])
    out = credit

    return depth(out, 10)
示例#19
0
 def ref_denoise(clip: vs.VideoNode, **kwargs) -> vs.VideoNode:
     return hvf.SMDegrain(clip, **kwargs)
示例#20
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    # Remove the noise
    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, sigma=[2, 1], radius1=1, ref=ref)
    out = denoise

    # Limited antialiasing
    y = get_y(out)
    lineart = core.std.Sobel(y).std.Binarize(
        75 << 8).std.Maximum().std.Inflate()
    aa = lvf.sraa(y,
                  2,
                  13,
                  downscaler=partial(core.resize.Bicubic,
                                     filter_param_a=-0.5,
                                     filter_param_b=0.25))
    sharp = hvf.LSFmod(aa, strength=70, Smode=3, edgemode=0, source=y)

    y = core.std.MaskedMerge(y, sharp, lineart)
    out = vdf.merge_chroma(y, out)

    # Deband masks
    planes = split(out)

    preden = core.dfttest.DFTTest(out,
                                  sigma=14.0,
                                  sigma2=10.0,
                                  sbsize=1,
                                  sosize=0,
                                  planes=[0, 1, 2]).rgvs.RemoveGrain(3)
    grad_mask, yrangebig = morpho_mask(preden)

    rgb = core.resize.Bicubic(preden, 960, 540,
                              format=vs.RGB48).std.SetFrameProp('_Matrix',
                                                                delete=True)
    chroma_masks = [
        core.std.Prewitt(p).std.Binarize(5500).rgvs.RemoveGrain(11)
        for p in split(rgb) + split(preden)[1:]
    ]
    chroma_mask = core.std.Expr(chroma_masks,
                                'x y + z + a + b +').std.Maximum()
    chroma_mask = core.std.Merge(chroma_mask,
                                 chroma_mask.std.Minimum()).std.BoxBlur(
                                     0, 1, 1, 1, 1)

    detail_mask = lvf.denoise.detail_mask(planes[0].std.BoxBlur(0, 1, 1, 1, 1),
                                          brz_a=3300,
                                          brz_b=2000)

    # Debanding stages
    debands = [None] * 3
    deband_y_strong = dbs.f3kbilateral(planes[0], 16, 65)
    deband_y_normal = dumb3kdb(planes[0], 16, 41)
    deband_y_light = core.std.MaskedMerge(dumb3kdb(planes[0], 14, 32),
                                          planes[0], detail_mask)
    debands[1] = dbs.f3kbilateral(planes[1], 12, 50)
    debands[2] = dbs.f3kbilateral(planes[2], 12, 50)

    debands[0] = core.std.MaskedMerge(deband_y_strong, deband_y_normal,
                                      grad_mask)
    debands[0] = core.std.MaskedMerge(debands[0], deband_y_light, yrangebig)
    debands[1], debands[2] = [
        core.std.MaskedMerge(debands[i], planes[i], chroma_mask)
        for i in range(1, 3)
    ]
    deband = join(debands)
    out = deband

    # Regraining
    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 25)
    adgmask_b = core.adg.Mask(ref, 10)

    stgrain_a = core.grain.Add(out, 0.1, 0, seed=333)
    stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert())

    stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, seed=333)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
    stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert())
    stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

    dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, seed=333)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#21
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src += src[-1]

    # Variables
    opstart, opend = 2206, 4362
    eptitle_s, eptitle_e = 4363, 4482
    edstart, edend = 31528, 33685
    preview_s, preview_e = 33686, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = denoise

    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', 0.055,
                              (1, 1)).std.Median().std.Convolution([*[1] * 9])

    descale = core.descale.Debilinear(y, w, h)

    upscale = vdf.fsrcnnx_upscale(
        descale,
        height=h * 2,
        shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
        upscaler_smooth=eedi3_upscale,
        profile='slow',
        strength=85)

    antialias = sraa_eedi3(upscale, 9)

    downscale = muvf.SSIM_downsample(antialias,
                                     src.width,
                                     src.height,
                                     filter_param_a=0,
                                     filter_param_b=0)
    downscale = core.std.MaskedMerge(y, downscale, lineart)

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([*[1] * 9])

    detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    dehalo_ref = gf.MaskedDHA(ref,
                              rx=1.65,
                              ry=1.65,
                              darkstr=0.15,
                              brightstr=1.0,
                              maskpull=48,
                              maskpush=140)
    dehalo_mask_b = vdf.region_mask(rescale_mask, right=400)

    credit = out
    dehalo_range_b = [(18, 101), (16853, 16917)]
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0),
                     [(126, 160), (1722, 1761), (7749, 7795), (8189, 8232),
                      (8445, 8504), (9020, 9067), (9727, 9768), (12430, 12520),
                      (12876, 12971), (13608, 13646), (15833, 15879),
                      (20526, 20586), (20783, 20823), (21193, 21239),
                      (23812, 23854), (24018, 24059),
                      (edstart, edend)] + dehalo_range_b)

    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_b, 0),
        dehalo_range_b)
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#22
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut

        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub

        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y],
                                  f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y,
                                   src_web_y.std.Convolution([1] * 9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        out = vdf.misc.merge_chroma(bdweb, src)

        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask)
        bdchanges = lvf.rfs(out, bdchanges, [(4455, 4607), (4876, 5078),
                                             (5199, 5246), (5958, 6035),
                                             (6894, 7076), (7275, 7406),
                                             (7653, 7784), (7863, 7970),
                                             (8142, 8348), (8784, 9065),
                                             (9276, 9800), (10613, 10720),
                                             (10739, 10780), (10949, 10969),
                                             (11105, 11230), (11924, 12289),
                                             (12865, 12891), (13139, 13213),
                                             (15520, 15733), (19160, 19243),
                                             (20351, 20422), (24824, 24979),
                                             (26357, 26527), (27920, 28000),
                                             (29576, 29659), (29780, 29881),
                                             (30128, 30271), (30644, 30763),
                                             (31776, 31811), (32522, 32641)])
        # return bdchanges, diff_mask
        out = bdchanges

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        ref = depth(src_cru, 16)
        cred_mask = Mask.credits_mask(src, JPBD_NCOP.clip_cut,
                                      JPBD_NCED.clip_cut, OPSTART, OPEND,
                                      EDSTART, EDEND)
        cred = out
        cred = lvf.rfs(cred, core.std.MaskedMerge(cred, ref, cred_mask, 0),
                       [(OPSTART, OPEND), (EDSTART, EDEND)])
        out = cred

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_a = vdf.placebo.deband(out,
                                      22,
                                      threshold=8,
                                      iterations=3,
                                      grain=0)
        import rekt
        deband_c = rekt.rekt_fast(out,
                                  lambda x: vdf.placebo.deband(x, 18, 6, 2, 0),
                                  bottom=600)
        deband_d = vdf.deband.dumb3kdb(out, 17, 65)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)])
        deband = lvf.rfs(deband, deband_c, [(12362, 12391)])
        deband = lvf.rfs(deband, deband_d, [(14789, 15025)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a,
                                         adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b,
                                         adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out,
                           0.3,
                           0.1,
                           1.25,
                           sharp=80,
                           static=False,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
示例#23
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)
        src_cru = WEB_CRU.clip_cut
        src_aod = WEB_AOD.clip_cut


        # Dehardsubbing using .ass file
        masksub = Mask.hardsub_mask(src_aod.std.BlankClip(), SUB, FONTDIR)
        dehardsub = core.std.MaskedMerge(src_aod, src_cru, masksub)
        src_web = dehardsub


        # AoD is poorly rescaled
        src_y, src_cru_y, src_web_y = map(get_y, [src, src_cru, src_web])

        thr = 10
        src_web_y = core.std.Expr([src_web_y, src_cru_y], f'x y - abs {thr} < x y * sqrt y ?')
        src_web_y = depth(src_web_y, 16)

        ringrid = core.rgvs.Repair(src_web_y, src_web_y.std.Convolution([1]*9), 11)
        ringrid = core.std.Expr([ringrid, src_web_y], 'x y min')

        # Remove ringing with AoD+CR
        ring_mask = Mask.ringing_mask(src_y)
        bdweb = core.std.MaskedMerge(src_y, ringrid, ring_mask)
        bdweb = lvf.rfs(bdweb, src_web_y, [(793, 1503), (1696, 2301), (32121, 34164), (34472, 34523)])
        out = vdf.misc.merge_chroma(bdweb, src)



        # Restore BD changes
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)

        diff_mask = Mask.diff_mask((src, src_cru), brz=4750.0)
        bdchanges = core.std.MaskedMerge(out, dering_src, diff_mask)
        bdchanges = lvf.rfs(out, bdchanges, [(9419, 9512), (17731, 17865)])
        bdchanges = lvf.rfs(bdchanges, dering_src, [(14977, 15078), (15382, 15540), (23311, 23346)])
        # return bdchanges, diff_mask
        out = bdchanges




        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(
            depth(out, 32), knlm_h=0.15, sigma=1,
            knlm_args=dict(d=1, a=3, s=3), bm3d_args=dict(ref=depth(ref, 32))
        )
        denoise = depth(denoise, 16)
        out = denoise



        pre = get_y(out)


        # Remove haloing
        dehalo = gf.MaskedDHA(pre, rx=1.4, ry=1.4, darkstr=0.1, brightstr=1.0, maskpull=40, maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp, ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo




        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000, 7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa




        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp


        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked




        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma


        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out, 17, 30, sample_mode=4, use_neo=True)
        deband_x = vdf.placebo.deband(out, 28, 4, iterations=3, grain=0)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1]*9), deband_1, deband_2],
            [f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength + f' - * + x {th_lo} <= z y ? ?',
             'x y * sqrt x z * sqrt * y * z * 0.25 pow'])

        deband = lvf.rfs(deband, deband_x, [(6688, 6714)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband



        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a, adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out, 0.2, 0.1, 1.15, sharp=80, static=True, fade_edges=False, protect_neutral=False, seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out, 0.3, 0.1, 1.25, sharp=80, static=False, fade_edges=False, protect_neutral=False, seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain


        if int(NUM) != 12:
            while out.num_frames < 34646:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#24
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    # Variables
    opstart, opend = 2111, 4268
    edstart, edend = 31650, 33809
    full_zone = [(18727, 18774), (31590, 31649), (33990, src.num_frames - 1)
                 ]  # eyecatch, episode name and next episode
    shabc_zone = [(edstart + 15, edstart + 1215),
                  (edstart + 1882, edstart + 2126)]
    h = 720
    w = get_w(h)

    # Bicubic sharp parts don't have bad edges
    edges_a = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    edges_b = awf.bbmod(src, left=6, thresh=32, blur=200)
    edges = lvf.rfs(edges_a, edges_b, [(edstart + 1275, edstart + 1757)])
    edges = lvf.rfs(edges, src, [(opstart, opend)] + full_zone)
    out = depth(edges, 32)

    # Denoise
    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.4, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = denoise
    # denoise = out

    # Descale
    luma = get_y(out)
    lineart = vdf.edge_detect(luma, 'FDOG', 0.055,
                              (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1)

    descale_a = core.descale.Despline36(luma, w,
                                        h).std.SetFrameProp('descaleKernel',
                                                            data='spline36')
    descale_b = core.descale.Debicubic(luma, w, h, 0, 1).std.SetFrameProp(
        'descaleKernel', data='sharp_bicubic')
    descale = lvf.rfs(descale_a, descale_b, shabc_zone)

    # Chroma reconstruction
    # y_m is the assumed mangled luma.
    # Descale 1080p -> Bad conversion in 422 720p -> Regular 1080p 420
    radius = 2
    y, u, v = descale, plane(out, 1), plane(out, 2)
    y_m = core.resize.Point(y, 640, 720,
                            src_left=-1).resize.Bicubic(960,
                                                        540,
                                                        filter_param_a=1 / 3,
                                                        filter_param_b=1 / 3)

    # 0.25 for 444 and 0.25 for right shifting
    y_m, u, v = [
        c.resize.Bicubic(w,
                         h,
                         src_left=0.25 + 0.25,
                         filter_param_a=0,
                         filter_param_b=.5) for c in [y_m, u, v]
    ]

    y_fixup = core.std.MakeDiff(y, y_m)
    yu, yv = Regress(y_m, u, v, radius=radius, eps=1e-7)

    u_fixup = ReconstructMulti(y_fixup, yu, radius=radius)
    u_r = core.std.MergeDiff(u, u_fixup)

    v_fixup = ReconstructMulti(y_fixup, yv, radius=radius)
    v_r = core.std.MergeDiff(v, v_fixup)

    # -0.5 * 720/1080 = -1/3
    # -1/3 for the right shift
    # https://forum.doom9.org/showthread.php?p=1802716#post1802716
    u_r, v_r = [
        c.resize.Bicubic(960,
                         540,
                         src_left=-1 / 3,
                         filter_param_a=-.5,
                         filter_param_b=.25) for c in [u_r, v_r]
    ]

    upscale = vdf.fsrcnnx_upscale(
        descale,
        height=h * 2,
        shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
        upscaler_smooth=eedi3_upscale,
        profile='zastin')

    antialias = sraa_eedi3(upscale,
                           3,
                           alpha=0.2,
                           beta=0.4,
                           gamma=40,
                           nrad=3,
                           mdis=20)

    downscale = muvf.SSIM_downsample(antialias,
                                     src.width,
                                     src.height,
                                     filter_param_a=0,
                                     filter_param_b=0)
    downscale = core.std.MaskedMerge(luma, downscale, lineart)

    merged_a = join([downscale, u_r, v_r])
    merged_b = vdf.merge_chroma(downscale, denoise)
    merged = lvf.rfs(merged_a, merged_b, shabc_zone)
    out = depth(merged, 16)

    warp = xvs.WarpFixChromaBlend(out, 80, 2, depth=8)
    out = warp

    dering = gf.MaskedDHA(out,
                          rx=1.25,
                          ry=1.25,
                          darkstr=0.05,
                          brightstr=1.0,
                          maskpull=48,
                          maskpush=140)
    out = dering

    qtgmc = hvf.QTGMC(out, Preset="Slower", InputType=1, ProgSADMask=2.0)
    qtgmc = vdf.fade_filter(out, out, qtgmc, edstart + 1522,
                            edstart + 1522 + 24)
    qtgmc = lvf.rfs(out, qtgmc, [(edstart + 1522 + 25, edstart + 1757)])
    out = qtgmc

    out = lvf.rfs(out, depth(denoise, 16), [(opstart, opend)])

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.BoxBlur(0, 1, 1, 1, 1)

    detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')

    deband = dumb3kdb(out, 22, 30)
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = depth(edges, 16)
    credit = out
    rescale_mask = vdf.diff_rescale_mask(ref, h, b=0, c=1, mthr=40, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4).std.BoxBlur(0, 1, 1, 1, 1)

    credit = lvf.rfs(credit, ref, full_zone)
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask),
                     [(edstart, edend)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#25
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    edstart, edend = 31888, src.num_frames-1


    shift = core.resize.Point(out, src_left=1).edgefixer.ContinuityFixer([2, 1, 1], 0, 0, 0)
    out = lvf.rfs(out, shift, [(235, 318)])



    ref = hvf.SMDegrain(out, tr=1, thSAD=300, plane=4)
    denoise = mvf.BM3D(out, [1.5, 1], 1, profile1='lc', ref=ref)
    out = denoise


    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', scale_value(0.065, 32, 16), (1, 1)).std.Median().std.BoxBlur(0, 1, 1, 1, 1)

    rescale = fake_rescale(y, 837.5, 1/3, 1/3, coef_dering=0.1, coef_dark=1.25,
                           coef_warp=1.15, coef_sharp=0.75, coef_finalsharp=0.85)
    rescale = core.std.MaskedMerge(y, rescale, lineart)

    out = vdf.merge_chroma(rescale, out)





    preden = core.dfttest.DFTTest(get_y(out), ftype=0, sigma=0.5, sbsize=16, sosize=12, tbsize=1)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=6000, brz_b=5000)
    detail_light_mask = lvf.denoise.detail_mask(preden, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask], 'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate, 2).std.BoxBlur(0, 1, 1, 1, 1)

    detail_mask = core.std.Expr([preden, detail_mask_grow, detail_mask], f'x {40<<8} < y z ?')

    pf = vdf.merge_chroma(preden, out)
    deband = dumb3kdb(pf, 17, 40)
    deband_b = dumb3kdb(pf, 20, 80)

    deband = lvf.rfs(deband, deband_b, [(2194, 2216), (2283, 2306)])
    deband = core.std.MergeDiff(deband, out.std.MakeDiff(pf))
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)
    out = deband


    grain = kgf.adaptive_grain(out, 0.35)
    out = grain



    ref = depth(src, 16)
    src_c, src_nced = [depth(x, 16) for x in [src, JPBD_NCED.src_cut[13:]]]

    ending_mask = vdf.dcm(out, src_c[edstart:edend+1], src_nced[:edend-edstart+1], edstart, edend, 2, 2).std.BoxBlur(0, 2, 2, 2, 2)

    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, ending_mask), [(31900, src.num_frames-1)])
    out = credit



    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2], [0, 1, 2])
示例#26
0
def do_filter():
    """Vapoursynth filtering"""
    src = WEB.src_cut
    src = src.std.AssumeFPS(src)

    src = depth(src, 16)
    out = src

    denoise = hvf.SMDegrain(out, tr=3, thSAD=150, thSADC=150)
    out = denoise

    dering = hvf.EdgeCleaner(out, 20, smode=1, hot=True)
    out = dering

    y = get_y(out)
    taps = 5
    w, h = 1600, 900
    descale = core.descale.Delanczos(depth(y, 32), w, h, taps)

    upscale = vdf.nnedi3_upscale(descale, pscrn=1, correct_shift=False)
    rescale = core.resize.Bicubic(upscale,
                                  1920,
                                  1080,
                                  src_left=.5,
                                  src_top=.5,
                                  filter_param_a=-.5,
                                  filter_param_b=.25)
    out = depth(rescale, 16)

    sharp = hvf.LSFmod(out,
                       strength=90,
                       Smode=3,
                       edgemode=0,
                       source=get_y(denoise))
    out = sharp

    merge = vdf.merge_chroma(out, denoise)
    out = merge

    detail_mask = lvf.mask.detail_mask(out, brz_a=2250, brz_b=1200)
    pref = out.std.Convolution([1, 2, 1, 2, 4, 2, 1, 2,
                                1]).std.Convolution([1] * 9)
    deband1 = vdf.dumb3kdb(pref, 17, 45, grain=16, seed=333)
    deband2 = vdf.dumb3kdb(pref,
                           15,
                           49,
                           grain=16,
                           sample_mode=4,
                           use_neo=True,
                           blur_first=False,
                           seed=333)

    th_lo, th_hi = 20 << 8, 26 << 8
    strength = '{1} x - {1} {0} - /'.format(th_lo, th_hi)
    deband = core.std.Expr([pref, deband1, deband2], [
        f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' + strength +
        f' - * + x {th_lo} <= z y ? ?', 'y'
    ])

    deband = core.std.MergeDiff(deband, out.std.MakeDiff(pref))
    deband = core.std.MaskedMerge(deband, out, detail_mask)
    out = deband

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        size=1.2,
                        luma_scaling=16,
                        hi=[128, 240],
                        protect_neutral=False,
                        seed=333)
    out = grain

    ref = denoise
    rescale_mask = vdf.drm(src, h, 'spline36', mthr=80).std.Maximum()
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask),
                     [(2374, 4530), (4544, 4648), (4701, 4762), (30070, 30210),
                      (31266, 33422)])
    credit = lvf.rfs(credit, ref, [(33423, src.num_frames - 1)])
    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2], [0, 1, 2])
示例#27
0
def smhdegrain(clip: vs.VideoNode, tr, th) -> vs.VideoNode:
    return hvf.SMDegrain(clip, tr=tr, thSAD=th, plane=4)
示例#28
0
    def main(self) -> vs.VideoNode:
        """Vapoursynth filtering"""
        src = JPBD.clip_cut
        src = depth(src, 16)

        ring_mask = Mask.ringing_mask(get_y(src))
        dering_src = hvf.EdgeCleaner(src, 20, hot=True)
        out = dering_src

        ref = Denoise.ref_denoise(get_y(out), tr=1)
        denoise = Denoise.hybrid_denoise(depth(out, 32),
                                         knlm_h=0.15,
                                         sigma=1,
                                         knlm_args=dict(d=1, a=3, s=3),
                                         bm3d_args=dict(ref=depth(ref, 32)))
        denoise = depth(denoise, 16)
        out = denoise

        pre = get_y(out)

        # Remove haloing
        dehalo = gf.MaskedDHA(pre,
                              rx=1.4,
                              ry=1.4,
                              darkstr=0.1,
                              brightstr=1.0,
                              maskpull=40,
                              maskpush=255)
        bila = core.bilateral.Bilateral(dehalo, sigmaS=1, sigmaR=0.08)
        dehalorp = core.rgvs.Repair(dehalo, bila, 13)
        dehalo = core.std.MaskedMerge(dehalo, dehalorp,
                                      ring_mask.std.Maximum(), 0)
        dehalo = core.std.Expr([dehalo, pre], 'x y min')
        out = dehalo

        # Antialiasing sraaaaaaaaaa
        lineart = vdf.mask.ExPrewitt().get_mask(out, 4000,
                                                7500).std.Convolution([1] * 25)
        aaa = AA().upscaled_sraaaaaaaaaa(out, height=1620)
        out = aaa

        unwarp = self.line_darkening(out, 0.075).warp.AWarpSharp2(depth=-1)
        out = unwarp

        motion = hvf.SMDegrain(out, tr=3, thSADC=600, RefineMotion=True)
        masked = core.std.MaskedMerge(out, motion, lineart)
        out = masked

        mergechroma = vdf.misc.merge_chroma(out, denoise)
        out = mergechroma

        db_mask = Mask.deband_mask(out, (4000, 4000, 4000), (2000, 2000, 2000))

        deband_1 = vdf.deband.dumb3kdb(out, 17, [36, 48])
        deband_2 = vdf.deband.dumb3kdb(out,
                                       17,
                                       30,
                                       sample_mode=4,
                                       use_neo=True)
        deband_a = vdf.placebo.deband(out,
                                      22,
                                      threshold=8,
                                      iterations=3,
                                      grain=0)

        th_lo, th_hi = 22 << 8, 28 << 8
        strength = f'{th_hi} x - {th_hi} {th_lo} - /'
        deband = core.std.Expr(
            [out.std.Convolution([1] * 9), deband_1, deband_2], [
                f'x {th_lo} > x {th_hi} < and z ' + strength + ' * y 1 ' +
                strength + f' - * + x {th_lo} <= z y ? ?',
                'x y * sqrt x z * sqrt * y * z * 0.25 pow'
            ])

        deband = lvf.rfs(deband, deband_a, [(OPSTART + 1382, OPSTART + 1433)])
        deband = core.std.MaskedMerge(deband, out, db_mask)
        out = deband

        ref = get_y(out).std.PlaneStats()
        adgmask_a = ref.adg.Mask(25)
        adgmask_b = ref.adg.Mask(10)

        stgrain_a = core.grain.Add(out, 0.1, 0, seed=333, constant=True)
        stgrain_a = core.std.MaskedMerge(out, stgrain_a,
                                         adgmask_b.std.Invert())

        stgrain_b = sizedgrn(out,
                             0.2,
                             0.1,
                             1.15,
                             sharp=80,
                             static=True,
                             fade_edges=False,
                             protect_neutral=False,
                             seed=333)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b, adgmask_b)
        stgrain_b = core.std.MaskedMerge(out, stgrain_b,
                                         adgmask_a.std.Invert())
        stgrain = core.std.MergeDiff(stgrain_b, out.std.MakeDiff(stgrain_a))

        dygrain = sizedgrn(out,
                           0.3,
                           0.1,
                           1.25,
                           sharp=80,
                           static=False,
                           fade_edges=False,
                           protect_neutral=False,
                           seed=333)
        dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
        grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
        out = grain

        if int(NUM) != 12:
            while out.num_frames < 2160:
                out += out[-1]

        return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2],
                                          [0, 1, 2])
示例#29
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src += src[-1]

    # Variables
    opstart, opend = 8296, 10452
    eptitle_s, eptitle_e = 10453, 10572
    edstart, edend = 31528, 33685
    preview_s, preview_e = 33686, src.num_frames - 1
    h = 720
    w = get_w(h)

    edges = core.edgefixer.ContinuityFixer(src, *[[2, 1, 1]] * 4)
    out = depth(edges, 32)

    ref = hvf.SMDegrain(depth(get_y(out), 16), thSAD=450)
    denoise = hybrid_denoise(out, 0.35, 1.75, dict(a=2, d=1),
                             dict(ref=depth(ref, 32)))
    out = denoise

    y = get_y(out)
    lineart = vdf.edge_detect(y, 'FDOG', 0.055,
                              (1, 1)).std.Median().std.Convolution([*[1] * 9])

    descale = core.descale.Debilinear(y, w, h)

    upscale = vdf.fsrcnnx_upscale(
        descale,
        height=h * 2,
        shader_file=r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
        upscaler_smooth=eedi3_upscale,
        profile='slow',
        strength=85)

    antialias = sraa_eedi3(upscale, 9)

    downscale = muvf.SSIM_downsample(antialias,
                                     src.width,
                                     src.height,
                                     filter_param_a=0,
                                     filter_param_b=0)
    downscale = core.std.MaskedMerge(y, downscale, lineart)

    merged = vdf.merge_chroma(downscale, out)
    merged = lvf.rfs(merged, out, [(opstart, opend), (eptitle_s, eptitle_e),
                                   (preview_s, preview_e)])
    out = depth(merged, 16)

    detail_dark_mask = detail_dark_mask_func(get_y(out),
                                             brz_a=8000,
                                             brz_b=6000)
    detail_light_mask = lvf.denoise.detail_mask(out, brz_a=2500, brz_b=1200)
    detail_mask = core.std.Expr([detail_dark_mask, detail_light_mask],
                                'x y +').std.Median()
    detail_mask_grow = iterate(detail_mask, core.std.Maximum, 2)
    detail_mask_grow = iterate(detail_mask_grow, core.std.Inflate,
                               2).std.Convolution([*[1] * 9])

    detail_mask = core.std.Expr([get_y(out), detail_mask_grow, detail_mask],
                                f'x {32<<8} < y z ?')

    deband = dumb3kdbv2(out, 22, 24)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband_b = dumb3kdbv2(out, 24, 64)
    deband_b = core.std.MaskedMerge(deband_b, out, detail_light_mask)
    deband = lvf.rfs(deband, deband_b, [(opstart + 414, opstart + 496)])

    out = deband

    ref = get_y(out).std.PlaneStats()
    adgmask_a = core.adg.Mask(ref, 30)
    adgmask_b = core.adg.Mask(ref, 12)

    stgrain = sizedgrn(out, 0.1, 0.05, 1.05, sharp=80)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_b)
    stgrain = core.std.MaskedMerge(out, stgrain, adgmask_a.std.Invert())

    dygrain = sizedgrn(out, 0.2, 0.05, 1.15, sharp=80, static=False)
    dygrain = core.std.MaskedMerge(out, dygrain, adgmask_a)
    grain = core.std.MergeDiff(dygrain, out.std.MakeDiff(stgrain))
    out = grain

    ref = depth(src, 16)
    rescale_mask = vdf.drm(ref, 720, 'bilinear', mthr=30, sw=0, sh=0)
    rescale_mask = vdf.region_mask(rescale_mask, *[10] * 4)
    rescale_mask = hvf.mt_expand_multi(rescale_mask,
                                       mode='ellipse',
                                       sw=4,
                                       sh=4)
    rescale_mask = rescale_mask.std.Binarize(scale_value(
        100, 8, 16)).std.Inflate().std.Convolution([*[1] * 9])

    dehalo_ref = gf.MaskedDHA(ref,
                              rx=1.65,
                              ry=1.65,
                              darkstr=0.15,
                              brightstr=1.0,
                              maskpull=48,
                              maskpush=140)
    dehalo_mask_a = vdf.region_mask(rescale_mask, top=650, right=200)

    credit = out
    dehalo_range_a = [(18, 130), (1291, 1355), (14691, 14846), (15126, 15189)]
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, rescale_mask,
                                                  0),
                     [(131, 220), (400, 505), (817, 899), (1766, 1809),
                      (1925, 2041), (4033, 4116), (4342, 4453), (4964, 5031),
                      (6422, 6515), (7848, 7978),
                      (10606, 10728), (11619, 11701), (15339, 15457),
                      (edstart, edend)] + dehalo_range_a)
    credit = lvf.rfs(
        credit, core.std.MaskedMerge(credit, dehalo_ref, dehalo_mask_a, 0),
        dehalo_range_a)

    out = credit

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
示例#30
0
文件: denoise.py 项目: pog42/lvsfunc
def quick_denoise(clip: vs.VideoNode,
                  ref: Optional[vs.VideoNode] = None,
                  cmode: str = 'knlm',
                  sigma: float = 2,
                  **kwargs: Any) -> vs.VideoNode:
    """
    This wrapper is used to denoise both the luma and chroma using various denoisers of your choosing.
    If you wish to use just one denoiser,
    you're probably better off using that specific filter rather than this wrapper.

    A rewrite of my old 'quick_denoise'. I still hate it, but whatever.
    This will probably be removed in a future commit.

    BM3D is used for denoising the luma.

    Special thanks to kageru for helping me out with some ideas and pointers.

    Alias for this function is `lvsfunc.qden`.

    Dependencies: havsfunc (optional: SMDegrain mode), mvsfunc

    Deciphering havsfunc's dependencies is left as an excercise for the user.

    :param clip:         Input clip
    :param cmode:        Chroma denoising modes:
                          'knlm' - Use knlmeans for denoising the chroma (Default),
                          'tnlm' - Use tnlmeans for denoising the chroma,
                          'dft'  - Use dfttest for denoising the chroma (requires setting 'sbsize' in kwargs),
                          'smd'  - Use SMDegrain for denoising the chroma,
    :param sigma:        Denoising strength for BM3D (Default: 2)
    :param ref:          Optional reference clip to replace BM3D's basic estimate
    :param kwargs:       Parameters passed to chroma denoiser

    :return:             Denoised clip
    """
    try:
        import mvsfunc as mvf
    except ModuleNotFoundError:
        raise ModuleNotFoundError(
            "quick_denoise: missing dependency 'mvsfunc'")

    if clip.format is None or clip.format.color_family not in (vs.YUV,
                                                               vs.YCOCG,
                                                               vs.RGB):
        raise ValueError(
            "quick_denoise: input clip must be vs.YUV, vs.YCOCG, or vs.RGB")

    planes = split(clip)
    cmode = cmode.lower()

    if cmode in [1, 'knlm', 'knlmeanscl']:
        planes[1] = planes[1].knlm.KNLMeansCL(d=3, a=2, **kwargs)
        planes[2] = planes[2].knlm.KNLMeansCL(d=3, a=2, **kwargs)
    elif cmode in [2, 'tnlm', 'tnlmeans']:
        planes[1] = planes[1].tnlm.TNLMeans(ax=2, ay=2, az=2, **kwargs)
        planes[2] = planes[2].tnlm.TNLMeans(ax=2, ay=2, az=2, **kwargs)
    elif cmode in [3, 'dft', 'dfttest']:
        try:
            sbsize = cast(int, kwargs['sbsize'])
            planes[1] = planes[1].dfttest.DFTTest(sosize=int(sbsize * 0.75),
                                                  **kwargs)
            planes[2] = planes[2].dfttest.DFTTest(sosize=int(sbsize * 0.75),
                                                  **kwargs)
        except KeyError:
            raise ValueError("quick_denoise: '\"sbsize\" not specified'")
    elif cmode in [4, 'smd', 'smdegrain']:
        try:
            import havsfunc as haf
        except ModuleNotFoundError:
            raise ModuleNotFoundError(
                "quick_denoise: missing dependency 'havsfunc'")

        planes[1] = haf.SMDegrain(planes[1], prefilter=3, **kwargs)
        planes[2] = haf.SMDegrain(planes[2], prefilter=3, **kwargs)
    else:
        raise ValueError("quick_denoise: 'Unknown cmode'")

    ref = ref or planes[0]
    planes[0] = mvf.BM3D(planes[0], sigma=sigma, psample=0, radius1=1, ref=ref)
    return join(planes)