Example #1
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')



    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise



    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))


    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height*2, '_shaders/FSRCNNX_x2_56-16-4-1.glsl', core.resize.Point)

    antialias = single_rate_antialiasing(upscale, 13, alpha=0.3, beta=0.45, gamma=320, mdis=18)

    scaled = muvf.SSIM_downsample(antialias, src.width, src.height, kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)


    # Slight sharp though CAS
    sharp = hvf.LSFmod(out, strength=75, Smode=3, Lmode=1, edgemode=1, edgemaskHQ=True)
    out = sharp


    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering



    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp


    preden = core.knlm.KNLMeansCL(out, d=0, a=3, h=0.6, device_type='GPU', channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)
    deband = dbs.f3kpf(out, 17, 42, 42)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband


    adg_mask = core.adg.Mask(out.std.PlaneStats(), 20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain


    return depth(out, 10)
Example #2
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])
Example #3
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



    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, 12), (75, 109), (237, 271), (323, 413), (500, 523),
         (1012, 1084), (1295, 1750)]
    )




    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])
Example #4
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

    # 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])
Example #5
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src + src[-1]

    denoise = mvf.BM3D(out, [2.5, 1.5], radius1=1)
    diff = core.std.MakeDiff(out, denoise)
    out = denoise

    luma = get_y(out)
    dehalo = gf.MaskedDHA(luma,
                          rx=2.5,
                          ry=2.5,
                          darkstr=0.15,
                          brightstr=1.2,
                          maskpull=48,
                          maskpush=140)
    out = dehalo

    dering = gf.HQDeringmod(out, sharp=3, drrep=24, thr=24, darkthr=0)
    out = dering

    antialias_mask = gf.EdgeDetect(out, 'FDOG')
    antialias = lvf.sraa(out,
                         1.5,
                         13,
                         gamma=100,
                         downscaler=core.resize.Spline64)
    out = core.std.MaskedMerge(out, antialias, antialias_mask)

    out = vdf.merge_chroma(out, denoise)

    warp = xvs.WarpFixChromaBlend(out, 64, depth=8)
    out = warp

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2250,
                                          brz_b=1500).std.Median()
    deband = dbs.f3kpf(out, 17, 36, 36)
    deband_b = dbs.f3kpf(out, 17, 56, 48)
    deband = lvf.rfs(deband, deband_b, [(23708, 24371)])
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    grain_original = core.std.MergeDiff(out, diff)
    grain_new = core.grain.Add(out, 0.15, 0, constant=True)
    grain_mask = core.adg.Mask(out.std.PlaneStats(),
                               30).std.Expr(f'x x {96<<8} - 0.25 * +')
    grain = core.std.MaskedMerge(grain_new, grain_original, grain_mask)
    out = grain

    ending = lvf.rfs(out, src, [(31241, src.num_frames - 1)])
    out = ending

    return depth(out, 10)
Example #6
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    h = 720
    w = get_w(h)


    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix


    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise



    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale, 13, alpha=0.2, beta=0.5, gamma=600, mdis=15)


    scaled = core.resize.Bicubic(antialias, src.width, src.height)
    rescale = core.std.MaskedMerge(luma, scaled, depth(line_mask, 32))
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)



    preden = core.knlm.KNLMeansCL(get_y(out), h=0.75, a=2, d=3, device_type='gpu', device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    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.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

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


    deband_a = dbs.f3kpf(out, 16, 30, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 4)
    deband = core.std.MaskedMerge(deband_a, deband_b, preden)
    deband = core.std.MaskedMerge(deband_a, out, detail_mask)
    deband = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24, grainc=24)
    out = deband


    grain = adptvgrnMod(out, 0.4, 0.3, 1.25, luma_scaling=8, sharp=80, static=False, lo=19)
    out = grain


    return depth(out, 10)
Example #7
0
def do_filter():
    """Vapoursynth filtering"""
    def _nnedi3(clip: vs.VideoNode, factor: float, args: dict)-> vs.VideoNode:
        upscale = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \
            .std.Transpose().nnedi3.nnedi3(0, True, **args)
        sraa = _sraa(upscale, dict(nsize=3, nns=3, qual=1, pscrn=1))
        return core.resize.Bicubic(sraa, clip.width*factor, clip.height*factor,
                                   src_top=.5, src_left=.5, filter_param_a=0, filter_param_b=0.25)

    # My GPU’s dying on it
    def _sraa(clip: vs.VideoNode, nnargs: dict)-> vs.VideoNode:
        clip = clip.nnedi3cl.NNEDI3CL(0, False, **nnargs).std.Transpose()
        clip = clip.nnedi3cl.NNEDI3CL(0, False, **nnargs).std.Transpose()
        return clip

    # Fun part / Cutting
    src_funi, src_wkn = [depth(c, 16) for c in CLIPS_SRC]
    src_funi, src_wkn = src_funi[744:], src_wkn[0] + src_wkn

    # Dehardsubbing
    # comp = lvf.comparison.stack_compare(src_funi, src_wkn, make_diff=True)
    src = core.std.MaskedMerge(src_wkn, src_funi, kgf.hardsubmask(src_wkn, src_funi))
    hardsub_rem = core.std.MaskedMerge(src, src_funi, kgf.hardsubmask_fades(src, src_funi, 8, 2000))
    src = lvf.rfs(src, hardsub_rem, [(3917, 4024)])


    # Regular filterchain
    op, ed = (17238, 19468), (31889, 34045)
    h = 846
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')

    luma = get_y(src)

    thr = 8000
    line_mask = gf.EdgeDetect(luma, 'FDOG').std.Median().std.Expr(f'x {thr} < x x 3 * ?')

    descale = core.descale.Debicubic(depth(luma, 32), w, h, b, c)
    rescaled = _nnedi3(depth(descale, 16), src.height/h, dict(nsize=0, nns=4, qual=2, pscrn=2))
    rescaled = core.std.MaskedMerge(luma, rescaled, line_mask)
    merged = vdf.merge_chroma(rescaled, src)
    out = merged

    cred_m = vdf.drm(src, h, b=b, c=c, mthr=80, mode='ellipse')
    credit = lvf.rfs(out, core.std.MaskedMerge(out, src, cred_m), [op])
    credit = lvf.rfs(credit, src, [ed])
    out = credit

    deband = dbs.f3kpf(out, 17, 36, 36)
    deband = core.std.MaskedMerge(deband, out, line_mask)
    grain = core.grain.Add(deband, 0.25)

    return depth(grain, 10)
Example #8
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)
    ed = (30089, 32247)

    denoise = kgf.hybriddenoise(src, 0.45, 2)
    out = denoise

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('mitchell')


    luma = get_y(out)
    line_mask = shf.edge_mask_simple(luma, 'FDOG', 0.08, (1, 1))


    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = shf.fsrcnnx_upscale(descale, src.height, 'shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  partial(SSIM_downsample, kernel='Bicubic'))
    rescale = core.std.MaskedMerge(luma, upscale, line_mask)
    merged = vdf.merge_chroma(rescale, denoise)
    out = depth(merged, 16)



    mask = shf.detail_mask(out, (10000, 4000), (12000, 3500), [(2, 2), (2, 2)], sigma=[50, 250, 400], upper_thr=0.005)
    deband = dbs.f3kpf(out, 17, 42, 48, thrc=0.4)
    deband = core.std.MaskedMerge(deband, out, mask)

    deband_b = placebo.deband(out, 27, 8, 3, 0)
    deband = lvf.rfs(deband, deband_b, [(3404, 3450)])

    deband_c = shf.deband_stonks(out, 20, 8, 3, shf.edge_mask_simple(out, 'prewitt', 2500, (8, 1)))
    deband = lvf.rfs(deband, deband_c, [(5642, 5784), (6222, 6479), (7798, 8073), (8133, 8256), (9699, 9817)])

    deband_d = placebo.deband(out, 17, 7.5, 1, 0)
    deband_d = core.std.MaskedMerge(deband_d, out, mask)
    deband = lvf.rfs(deband, deband_d, [(8074, 8132), (8711, 8766), (12267, 12433), (28468, 28507)])

    grain = core.neo_f3kdb.Deband(deband, preset='depth', grainy=24, grainc=24)
    out = grain


    grain = adptvgrnMod(out, 0.3, size=4/3, sharp=55, luma_scaling=14, grain_chroma=False)
    out = grain


    ending = shinyori_ed01.filtering(src, *ed)
    final = lvf.rfs(out, ending, [ed])

    return depth(final, 10)
Example #9
0
def do_filter():
    """Vapoursynth filtering"""

    def _fsrcnnx(clip: vs.VideoNode) -> vs.VideoNode:
        blank = core.std.BlankClip(clip, format=vs.GRAY16, color=128 << 8)
        clip = join([clip, blank, blank])
        # The chroma is upscaled with box AKA nearest but we don't care since we only need the luma.
        # It's especially faster and speed is the key :^)
        clip = core.placebo.Shader(clip, 'Shaders/FSRCNNX_x2_56-16-4-1.glsl', clip.width*2, clip.height*2, filter='box')
        return get_y(clip)

    def _nnedi(clip: vs.VideoNode) -> vs.VideoNode:
        args = dict(nsize=4, nns=4, qual=2, pscrn=2)
        clip = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \
            .std.Transpose().nnedi3.nnedi3(0, True, **args)
        return core.resize.Spline36(clip, src_top=.5, src_left=.5)

    def _rescale(clip: vs.VideoNode, thr: int, downscaler: Callable[[vs.VideoNode], vs.VideoNode]) -> vs.VideoNode:
        return downscaler(core.std.Merge(_nnedi(clip), _fsrcnnx(clip), thr))

    src = SRC_CUT

    fixedges = lvf.ef(src, [1, 1, 1])

    denoise = CoolDegrain(depth(fixedges, 16), tr=1, thsad=48, thsadc=84, blksize=8, overlap=4, plane=4)


    w, h = 1280, 720
    b, c = vdf.get_bicubic_params('robidoux')
    luma = get_y(denoise)
    descale = depth(core.descale.Debicubic(depth(luma, 32), w, h, b, c), 16)
    rescale = _rescale(descale, 0.55, lambda c: core.resize.Bicubic(c, src.width, src.height, filter_param_a=0, filter_param_b=0))

    line_mask = lvf.denoise.detail_mask(rescale, brz_a=7000, brz_b=2000)
    rescale = core.std.MaskedMerge(luma, rescale, line_mask)



    credit_mask = vdf.drm(luma, b=b, c=c, mode='ellipse', sw=3, sh=3)
    credit = core.std.MaskedMerge(rescale, luma, credit_mask)


    merged = vdf.merge_chroma(credit, denoise)


    deband_mask = lvf.denoise.detail_mask(merged, brz_a=3000, brz_b=1500)
    deband = dbs.f3kpf(merged, 17, 36, 36)
    deband = core.std.MaskedMerge(deband, merged, deband_mask)
    grain = core.neo_f3kdb.Deband(deband, preset='depth', grainy=32, output_depth=10,
                                  dither_algo=3, keep_tv_range=True)

    return grain
Example #10
0
    def aa_stonks(clip: vs.VideoNode) -> vs.VideoNode:
        mask = core.std.Prewitt(get_y(clip)).std.Binarize(4000)
        mask = iterate(mask, core.std.Maximum, 4)
        mask = iterate(mask, core.std.Minimum, 2)
        mask = iterate(mask, core.std.Deflate, 4)
        mask = vdf.region_mask(mask, 400, 400, 0, 0)

        descale = core.descale.Debicubic(depth(get_y(clip), 32), 1440, 810)
        upscale = core.caffe.Waifu2x(descale, 3, 2, model=6)
        downscale = core.descale.Debilinear(upscale, 1920, 1080)
        merged = vdf.merge_chroma(depth(downscale, 16), clip)
        merged = core.std.MaskedMerge(clip, merged, mask)

        return core.warp.AWarpSharp2(merged, 128, 2, depth=16)
Example #11
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])
Example #12
0
def _aa_extra(clip: vs.VideoNode) -> vs.VideoNode:
    downscaler_fun = lambda x, wid, hei: \
        core.fmtc.resample(x, wid, hei, kernel='gauss', invks=True, invkstaps=2, taps=1, a1=32)
    luma = get_y(clip)
    antiaa = lvf.sraa(luma, 2, height=720)
    antiaa = TAAmbk(antiaa,
                    'Eedi3SangNom',
                    mtype=2,
                    alpha=0.75,
                    beta=0.2,
                    gamma=40,
                    aa=96)
    antiaa = lvf.sraa(antiaa, 2, height=clip.height, downscaler=downscaler_fun)
    return vdf.merge_chroma(antiaa, clip)
Example #13
0
def filtering(clip: vs.VideoNode, edstart: int, edend: int)-> vs.VideoNode:
    """Main function"""

    clip = depth(clip, 32)

    denoise = CoolDegrainSF(clip, tr=1, thsad=36, blksize=8, overlap=4)
    out = denoise


    luma = get_y(out)
    descale = core.descale.Debicubic(luma, w, h, b, c)
    out = descale


    upscale = shf.nnedi3_upscale(out, clip.height/h, dict(nsize=4, nns=4, qual=2, pscrn=1))
    out = upscale


    antialias = _antialias_stonk(descale, 128)
    mask = core.std.Sobel(antialias).std.Maximum().std.Maximum()
    antialias = lvf.rfs(out, core.std.MaskedMerge(out, antialias, mask), [(edstart+683, edstart+730)])
    merged = vdf.merge_chroma(antialias, denoise)
    out = depth(merged, 16)


    sharp = lvf.rfs(out, _unblur(descale, denoise), [(edstart+501, edstart+617)])
    out = sharp


    ref = core.resize.Point(luma, format=vs.YUV420P16)
    credit = core.std.MaskedMerge(out, ref, vdf.drm(ref, h, b=b, c=c), 0)
    out = credit


    deband_a = shf.deband_stonks(out, 24, 8, 1, shf.edge_mask_simple(out, 'prewitt', 2500, (2, 0)))
    deband_b = shf.deband_stonks(out, 31, 16, 3, shf.edge_mask_simple(out, 'prewitt', 2500, (6, 0)))
    deband_c = dbs.f3kpf(out, 17, 36, 36)
    deband = lvf.rfs(out, deband_a, [(edstart+44, edstart+69), (edstart+94, edstart+165),
                                     (edstart+190, edstart+213), (edstart+320, edstart+375),
                                     (edstart+683, edstart+730)])
    deband = lvf.rfs(deband, deband_b, [(edstart+166, edstart+189)])
    deband = lvf.rfs(deband, deband_c, [(edstart+376, edstart+682), (edstart+731, edend)])
    out = deband

    grain = core.neo_f3kdb.Deband(out, preset='depth', grainy=24, grainc=24)
    out = grain

    return out
Example #14
0
def hybrid_denoise(clip: vs.VideoNode, knlm_h: float = 0.5, sigma: float = 2,
                   knlm_args: Optional[Dict[str, Any]] = None,
                   bm3d_args: Optional[Dict[str, Any]] = None)-> vs.VideoNode:
    knargs = dict(a=2, d=3, device_type='gpu', device_id=0, channels='UV')
    if knlm_args is not None:
        knargs.update(knlm_args)

    b3args = dict(radius1=1, profile1='fast')
    if bm3d_args is not None:
        b3args.update(bm3d_args)

    luma = get_y(clip)
    luma = mvf.BM3D(luma, sigma, **b3args)
    chroma = core.knlm.KNLMeansCL(clip, h=knlm_h, **knargs)

    return vdf.merge_chroma(luma, chroma)
Example #15
0
    def _nneedi3_clamp(clip: vs.VideoNode, strength: int = 1)-> vs.VideoNode:
        bits = clip.format.bits_per_sample - 8
        thr = strength * (1 >> bits)

        luma = get_y(clip)

        def _strong(clip: vs.VideoNode)-> vs.VideoNode:
            args = dict(alpha=0.25, beta=0.5, gamma=40, nrad=2, mdis=20, vcheck=3)
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            clip = core.eedi3m.EEDI3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip, luma.width, luma.height, src_left=-.5, src_top=-.5)

        def _weak(clip: vs.VideoNode)-> vs.VideoNode:
            args = dict(nsize=3, nns=2, qual=2)
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            clip = core.znedi3.nnedi3(clip, 1, True, **args).std.Transpose()
            return core.resize.Spline36(clip, luma.width, luma.height, src_left=-.5, src_top=-.5)

        clip_aa = core.std.Expr([_strong(luma), _weak(luma), luma],
                                'x z - y z - * 0 < y x y {0} + min y {0} - max ?'.format(thr))
        return vdf.merge_chroma(clip_aa, clip)
Example #16
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)

    h = 882
    w = get_w(h)
    kernel = 'lanczos'
    taps = 5

    denoise = CoolDegrain(src, tr=1, thsad=24, blksize=8, overlap=4, plane=4)
    out = denoise

    luma = get_y(out)

    descale = kgf.get_descale_filter(kernel, taps=taps)(depth(luma, 32), w, h)
    upscale = vdf.fsrcnnx_upscale(
        depth(descale, 16), src.width, src.height,
        '_assets/shaders/FSRCNNX_x2_56-16-4-1.glsl',
        partial(core.resize.Bicubic, filter_param_a=0, filter_param_b=0))
    out = vdf.merge_chroma(upscale, out)

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)

    deband = dbs.f3kpf(out, 17, 30, 30)

    deband = core.std.MaskedMerge(deband, out, deband_mask)
    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=18,
                                   keep_tv_range=True)
    out = deband

    grain = kgf.adaptive_grain(out, 0.2, luma_scaling=14)
    out = grain

    return depth(out, 10)
Example #17
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut

    full = core.resize.Bicubic(src,
                               format=vs.YUV444P8,
                               filter_param_a=0,
                               filter_param_b=1 / 2)
    crop = core.std.Crop(full, 10, 10, 5, 6)
    edgefix = awf.bbmod(crop, 1, 1, 1, 1, thresh=64)
    out = depth(edgefix, 16)

    antialias = lvf.sraa(get_y(out), 2, 13)
    antialias = lvf.rfs(out, vdf.merge_chroma(antialias, out),
                        [(1845, src.num_frames - 1)])
    out = antialias

    return core.resize.Bicubic(out,
                               1920,
                               1080,
                               format=vs.YUV420P10,
                               filter_param_a=0,
                               filter_param_b=1 / 2,
                               dither_type='error_diffusion')
Example #18
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src


    opstart, opend = 59, 1630
    edstart, edend = 30776, src.num_frames-1
    h = 846
    w = get_w(h)
    cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp']
    cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters]



    degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1))

    out = degrain



    y = get_y(out)
    y32 = depth(y, 32)
    lineart = vdf.edge_detect(y32, 'kirsch', 0.055, (1, 1)).std.Median().std.Inflate()




    descale_clips = [core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters]
    descale = core.std.Expr(descale_clips, 'x y z a min min min x y z max max min')

    conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1])
    thr, coef = 0.013, 3
    descale_fix = core.std.Expr([descale, conv], f'x y - abs {thr} < y x ?').std.PlaneStats()
    adapt_mask = core.adg.Mask(descale_fix, 12).std.Invert().std.Expr(f'x 0.5 - {coef} * 0.5 + 0 max 1 min')

    descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask)



    upscale = vdf.fsrcnnx_upscale(descale, w*2, h*2, r'shaders\FSRCNNX_x2_56-16-4-1.glsl', upscaler_smooth=eedi3_upscale,
                                  profile='zastin', sharpener=partial(gf.DetailSharpen, sstr=1.25, power=4))

    aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40)
    aa = aa_strong

    down = muvf.SSIM_downsample(aa, src.width, src.height, filter_param_a=0, filter_param_b=0)


    upscale = depth(
        core.std.MaskedMerge(y32, down, lineart), 16
    )

    merged = vdf.merge_chroma(upscale, out)
    out = merged



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


    pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0)
    diff = core.std.MakeDiff(out, pf)

    deband = core.f3kdb.Deband(pf, 17, 36, 36, 36, 12, 12, 2, keep_tv_range=True, output_depth=16)

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





    grain = adptvgrnMod(out, 0.25, 0.15, size=out.height/h, sharp=80, luma_scaling=10, static=True)
    out = grain






    # # Restore 1080p stuff
    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),
                     [(opstart, opend), (1634, 1728), (edstart, edend)])
    credit = lvf.rfs(credit, ref, [(15200, 15271)])
    out = credit


    return depth(out, 10).std.Limiter(16<<2, [235<<2, 240<<2])
Example #19
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)
Example #20
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])
Example #21
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])
Example #22
0
def do_filter():
    """Vapoursynth filtering"""
    def _sraa(clip: vs.VideoNode, nnargs: dict, eeargs: dict) -> vs.VideoNode:
        def _nnedi3(clip):
            return clip.nnedi3.nnedi3(0, False, **nnargs)

        def _eedi3(clip, sclip):
            return clip.eedi3m.EEDI3(0, False, **eeargs, sclip=sclip)

        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        return clip

    def _nnedi3(clip: vs.VideoNode, factor: float, args: dict) -> vs.VideoNode:
        upscale = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \
            .std.Transpose().nnedi3.nnedi3(0, True, **args)
        return core.resize.Spline36(upscale,
                                    clip.width * factor,
                                    clip.height * factor,
                                    src_top=.5,
                                    src_left=.5)

    def _line_mask(clip: vs.VideoNode, thr: int) -> vs.VideoNode:
        mask = core.std.Prewitt(clip)
        mask = core.std.Expr(mask, 'x 2 *').std.Median()
        mask = core.std.Expr(mask, f'x {thr} < x x 3 * ?')
        return mask.std.Inflate().std.Deflate()

    def _ssharp(clip: vs.VideoNode,
                strength: float,
                width: int,
                height: int,
                factor: float = 2,
                b: float = -1,
                c: float = 6) -> vs.VideoNode:
        source = clip
        sharp = core.resize.Bicubic(clip, clip.width*factor, clip.height*factor, \
            filter_param_a=b, filter_param_b=c).resize.Lanczos(width, height)

        source = core.resize.Spline64(source, sharp.width, sharp.height)

        sharp = core.rgvs.Repair(sharp, source, 13)
        sharp = mvf.LimitFilter(source,
                                sharp,
                                thrc=0.5,
                                elast=6,
                                brighten_thr=0.5,
                                planes=0)

        final = core.std.Expr([sharp, source],
                              f'x {strength} * y 1 {strength} - * +')
        return final

    def to_gray(clip: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode:
        clip = core.std.AssumeFPS(clip, ref)
        return core.resize.Point(clip,
                                 format=vs.GRAY16,
                                 matrix_s=mvf.GetMatrix(ref))

    def _perform_masks_credit(path: Path) -> List[MaskCredit]:
        return [
            MaskCredit(lvf.src(str(mask)), int(str(mask.stem).split('_')[2]),
                       int(str(mask.stem).split('_')[3]))
            for mask in path.glob('*')
        ]

    # pylint: disable=unused-argument
    def _diff(n: int, f: vs.VideoFrame, new: vs.VideoNode,
              adapt: vs.VideoNode) -> vs.VideoNode:
        psa = f.props['PlaneStatsAverage']
        if psa > 0.5:
            clip = new
        elif psa < 0.4:
            clip = adapt
        else:
            weight = (psa - 0.4) * 10
            clip = core.std.Merge(adapt, new, weight)
        return clip

    def _ret_mask(clip: vs.VideoNode, thr: int) -> vs.VideoNode:
        mask = kgf.retinex_edgemask(clip)
        mask = core.std.Median(mask).std.Binarize(thr)
        mask = iterate(mask, core.std.Median, 2)
        mask = iterate(mask, core.std.Maximum, 3)
        mask = iterate(mask, core.std.Minimum, 2)
        return mask

    opstart, opend = 1774, 3944
    edstart, edend = 31781, 33938
    src = JPBD.src_cut
    src = depth(src, 16)

    denoise_a = mdf.hybriddenoise_mod(src, 0.55, 2.25)
    denoise_b = mdf.hybriddenoise_mod(src, 0.55, 10)
    denoise = lvf.rfs(denoise_a, denoise_b, [(opstart, opstart + 44)])
    diff = core.std.MakeDiff(src, denoise, [0, 1, 2])

    luma = get_y(denoise)

    upscale = _nnedi3(luma, 1.5, dict(nsize=0, nns=3, qual=1, pscrn=1))
    sraa = _sraa(upscale, dict(nsize=0, nns=3, qual=1, pscrn=1),
                 dict(alpha=0.2, beta=0.5, gamma=80, nrad=3, mdis=18))
    sraa = core.rgvs.Repair(sraa, upscale, 3)
    rescale = _ssharp(sraa, 0.55, src.width, src.height, 2)

    artefacts_mask = core.std.BlankClip(rescale, color=(256 << 8) - 1)
    artefacts_mask = vdf.region_mask(artefacts_mask, 2, 2, 2, 2).std.Inflate()
    rescale = core.std.MaskedMerge(luma, rescale, artefacts_mask)

    lineart_mask = _line_mask(luma, 8000)
    antialias = core.std.MaskedMerge(luma, rescale, lineart_mask)

    antialias_merged = vdf.merge_chroma(antialias, denoise)

    src_c, src_ncop = [
        c.knlm.KNLMeansCL(a=6, h=20, d=0, device_type='gpu')
        for c in [src, JPBD_NCOP.src_cut[:opend - opstart + 1]]
    ]
    credit_mask = vdf.dcm(src, src_c[opstart:opend + 1], src_ncop, opstart,
                          opend, 2, 2).std.Deflate()
    credit = core.std.MaskedMerge(antialias_merged, denoise, credit_mask)

    masks_credit_ = _perform_masks_credit(Path('masks_' + JPBD.name[-2:] +
                                               '/'))

    for mask in masks_credit_:
        credit = lvf.rfs(
            credit,
            core.std.MaskedMerge(credit, denoise,
                                 to_gray(mask.mask, src).std.Deflate()),
            [(mask.start_frame, mask.end_frame)])

    deband_mask = lvf.denoise.detail_mask(credit, brz_a=3000, brz_b=1500)
    dark_mask = core.std.Expr([deband_mask, _ret_mask(credit, 12500)], 'x y +')
    deband_a = dbs.f3kpf(credit, 18, 36, 36)
    deband_b = dbs.f3kpf(credit, 18, 42, 42)
    deband_c = placebo.Deband(credit,
                              radius=12,
                              threshold=20,
                              iterations=3,
                              grain=0)
    deband_d = placebo.Deband(credit,
                              radius=10,
                              threshold=8,
                              iterations=2,
                              grain=0)
    deband = lvf.rfs(deband_a, deband_b, [(opstart + 483, opstart + 554)])
    deband = lvf.rfs(deband, deband_c, [(opstart, opstart + 44)])
    deband = lvf.rfs(deband, core.std.MaskedMerge(deband_d, credit, dark_mask),
                     [(opstart + 1070, opstart + 1103)])
    deband = lvf.rfs(deband, deband_d, [(opstart + 1104, opstart + 1124)])
    deband = core.std.MaskedMerge(deband, credit, deband_mask)

    grain_original = core.std.MergeDiff(deband, diff, [0, 1, 2])
    grain_original_nochroma = core.std.MergeDiff(deband, diff, [0])
    grain_new = core.neo_f3kdb.Deband(deband,
                                      preset='depth',
                                      grainy=32,
                                      grainc=32)
    grain_new_nochroma = vdf.merge_chroma(grain_new, deband)
    avg = core.std.PlaneStats(deband)
    adapt_mask = core.adg.Mask(get_y(avg), 28)
    grain_adapt = core.std.MaskedMerge(grain_new, grain_original, adapt_mask)

    gf3_args = dict(g1str=5,
                    g2str=3.85,
                    g3str=3.5,
                    g1shrp=50,
                    g2shrp=60,
                    g3shrp=60,
                    g1size=1.65,
                    g2size=1.60,
                    g3size=1.25)
    grain_a = hvf.GrainFactory3(deband, **gf3_args)
    grain_b = mdf.adptvgrnMod_mod(deband,
                                  2,
                                  size=1.5,
                                  sharp=60,
                                  static=False,
                                  luma_scaling=14)

    grain = core.std.FrameEval(
        deband, partial(_diff, new=grain_new, adapt=grain_adapt), avg)

    grain = lvf.rfs(grain, grain_original, [(5058, 5253), (7871, 7989)])
    grain = lvf.rfs(grain, grain_new_nochroma,
                    [(opstart + 117, opstart + 873),
                     (opstart + 921, opstart + 993)])
    grain = lvf.rfs(grain, grain_original_nochroma,
                    [(opstart + 874, opstart + 920),
                     (opstart + 994, opstart + 1069),
                     (opstart + 1125, opstart + 1202)])
    grain = lvf.rfs(grain, grain_a, [(opstart, opstart + 44)])
    grain = lvf.rfs(grain, grain_b, [(opstart + 1070, opstart + 1124)])

    stabilize = hvf.GSMC(src, radius=2, planes=0)
    ending = vdf.merge_chroma(stabilize, denoise)
    final = lvf.rfs(grain, ending, [(edstart, edend)])

    final = final[:opstart] + final[opstart + 2:opstart + 2160] + final[opend +
                                                                        1:]
    return depth(final, 10), opstart, opend
Example #23
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)

    h = 720
    w = get_w(h)
    # getnative script returns 0.2 0.5 as best combo but it introduces too much halos.
    # I think it's plain mitchell but robidoux is good too and very slightly sharp.
    b, c = vdf.get_bicubic_params('robidoux')
    opstart = 0

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)
    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')

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

    antialias = lvf.rfs(
        out,
        lvf.sraa(out,
                 1.65,
                 9,
                 alpha=0.3,
                 beta=0.45,
                 gamma=240,
                 nrad=3,
                 mdis=25), [(opstart + 840, opstart + 881)])
    out = antialias

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1, show=False)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)
    deband = dbs.f3kpf(out, 17, 42, 42)
    deband_b = placebo.deband(out, 22, 6, 2)
    deband = lvf.rfs(deband, deband_b, [(opstart + 1515, opstart + 1603)])
    deband = core.std.MaskedMerge(deband, out, mask)
    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    return depth(out, 10)
Example #24
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])
Example #25
0
def do_filter():
    """Vapoursynth filtering"""
    def _sraa(clip: vs.VideoNode, nnargs: dict, eeargs: dict) -> vs.VideoNode:
        def _nnedi3(clip):
            return clip.nnedi3.nnedi3(0, False, **nnargs)

        def _eedi3(clip, sclip):
            return clip.eedi3m.EEDI3(0, False, **eeargs, sclip=sclip)

        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        clip = _eedi3(clip, _nnedi3(clip)).std.Transpose()
        return clip

    def _nnedi3(clip: vs.VideoNode, factor: float, args: dict) -> vs.VideoNode:
        upscale = clip.std.Transpose().nnedi3.nnedi3(0, True, **args) \
            .std.Transpose().nnedi3.nnedi3(0, True, **args)
        return core.resize.Spline36(upscale,
                                    clip.width * factor,
                                    clip.height * factor,
                                    src_top=.5,
                                    src_left=.5)

    def _line_mask(clip: vs.VideoNode, thr: int) -> vs.VideoNode:
        mask = core.std.Prewitt(clip)
        mask = core.std.Expr(mask, 'x 2 *').std.Median()
        mask = core.std.Expr(mask, f'x {thr} < x x 3 * ?')
        return mask.std.Inflate().std.Deflate()

    def _ssharp(clip: vs.VideoNode,
                strength: float,
                width: int,
                height: int,
                factor: float = 2,
                b: float = -1,
                c: float = 6) -> vs.VideoNode:
        source = clip
        sharp = core.resize.Bicubic(clip, clip.width*factor, clip.height*factor, \
            filter_param_a=b, filter_param_b=c).resize.Lanczos(width, height)

        source = core.resize.Spline64(source, sharp.width, sharp.height)

        sharp = core.rgvs.Repair(sharp, source, 13)
        sharp = mvf.LimitFilter(source,
                                sharp,
                                thrc=0.5,
                                elast=6,
                                brighten_thr=0.5,
                                planes=0)

        final = core.std.Expr([sharp, source],
                              f'x {strength} * y 1 {strength} - * +')
        return final

    def to_gray(clip: vs.VideoNode, ref: vs.VideoNode) -> vs.VideoNode:
        clip = core.std.AssumeFPS(clip, ref)
        return core.resize.Point(clip,
                                 format=vs.GRAY16,
                                 matrix_s=mvf.GetMatrix(ref))

    def _perform_masks_credit(path: Path) -> List[MaskCredit]:
        return [
            MaskCredit(lvf.src(str(mask)), int(str(mask.stem).split('_')[2]),
                       int(str(mask.stem).split('_')[3]))
            for mask in path.glob('*')
        ]

    def _w2x(clip: vs.VideoNode) -> vs.VideoNode:
        waifu2x = core.w2xc.Waifu2x(mvf.ToRGB(clip, depth=32), noise=2, scale=2) \
            .resize.Bicubic(clip.width, clip.height)
        return mvf.ToYUV(waifu2x, css='420', depth=16)

    def _perform_filtering_ending(clip: vs.VideoNode,
                                  adapt_mask: vs.VideoNode) -> vs.VideoNode:
        luma = get_y(clip)
        denoise_a = mvf.BM3D(luma, 2.25, 1)
        denoise_b = mvf.BM3D(luma, 1.25, 1)
        denoise = core.std.MaskedMerge(denoise_a, denoise_b, adapt_mask)
        grain = core.grain.Add(denoise, 0.3, constant=True)
        return core.std.MaskedMerge(denoise, grain, adapt_mask)

    # pylint: disable=unused-argument
    def _diff(n: int, f: vs.VideoFrame, new: vs.VideoNode,
              adapt: vs.VideoNode) -> vs.VideoNode:
        psa = f.props['PlaneStatsAverage']
        if psa > 0.5:
            clip = new
        elif psa < 0.4:
            clip = adapt
        else:
            weight = (psa - 0.4) * 10
            clip = core.std.Merge(adapt, new, weight)
        return clip

    def aa_stonks(clip: vs.VideoNode) -> vs.VideoNode:
        mask = core.std.Prewitt(get_y(clip)).std.Binarize(4000)
        mask = iterate(mask, core.std.Maximum, 4)
        mask = iterate(mask, core.std.Minimum, 2)
        mask = iterate(mask, core.std.Deflate, 4)
        mask = vdf.region_mask(mask, 400, 400, 0, 0)

        descale = core.descale.Debicubic(depth(get_y(clip), 32), 1440, 810)
        upscale = core.caffe.Waifu2x(descale, 3, 2, model=6)
        downscale = core.descale.Debilinear(upscale, 1920, 1080)
        merged = vdf.merge_chroma(depth(downscale, 16), clip)
        merged = core.std.MaskedMerge(clip, merged, mask)

        return core.warp.AWarpSharp2(merged, 128, 2, depth=16)

    opstart, opend = 1272, 3428
    edstart, edend = 31769, 33926
    src = JPBD.src_cut
    src = depth(src, 16)
    src = core.std.FreezeFrames(src, opstart + 2132, opend, opstart + 2132)

    denoise = mdf.hybriddenoise_mod(src, 0.55, 2.25)
    diff = core.std.MakeDiff(src, denoise, [0, 1, 2])

    luma = get_y(denoise)

    upscale = _nnedi3(luma, 1.5, dict(nsize=0, nns=3, qual=1, pscrn=1))
    sraa = _sraa(upscale, dict(nsize=0, nns=3, qual=1, pscrn=1),
                 dict(alpha=0.2, beta=0.5, gamma=80, nrad=3, mdis=18))
    sraa = core.rgvs.Repair(sraa, upscale, 3)
    rescale = _ssharp(sraa, 0.55, src.width, src.height, 2)

    artefacts_mask = core.std.BlankClip(rescale, color=(256 << 8) - 1)
    artefacts_mask = vdf.region_mask(artefacts_mask, 2, 2, 2, 2).std.Inflate()
    rescale = core.std.MaskedMerge(luma, rescale, artefacts_mask)

    lineart_mask = _line_mask(luma, 8000)
    antialias = core.std.MaskedMerge(luma, rescale, lineart_mask)

    antialias_merged = vdf.merge_chroma(antialias, denoise)

    antialias_strong_a = aa_stonks(denoise)
    antialias_strong_b = TAAmbk(denoise, 'Eedi3', cycle=3, mtype=0)
    antialias_merged = lvf.rfs(antialias_merged, antialias_strong_a,
                               [(4782, 4785)])
    antialias_merged = lvf.rfs(antialias_merged, antialias_strong_b,
                               [(11808, 11898)])

    src_c, src_ncop = [
        c.knlm.KNLMeansCL(a=6, h=20, d=0, device_type='gpu')
        for c in [src, JPBD_NCOP.src_cut[:opend - opstart + 1]]
    ]
    credit_mask = vdf.dcm(src, src_c[opstart:opend + 1], src_ncop, opstart,
                          opend, 2, 2).std.Deflate()
    credit = core.std.MaskedMerge(antialias_merged, denoise, credit_mask)

    masks_credit_ = _perform_masks_credit(Path('masks_' + JPBD.name[-2:] +
                                               '/'))

    for mask in masks_credit_:
        credit = lvf.rfs(
            credit,
            core.std.MaskedMerge(credit, denoise,
                                 to_gray(mask.mask, src).std.Deflate()),
            [(mask.start_frame, mask.end_frame)])

    deband_mask = lvf.denoise.detail_mask(credit, brz_a=3000, brz_b=1500)
    deband_a = dbs.f3kpf(credit, 18, 36, 36)
    deband_b = dbs.f3kpf(credit, 18, 42, 42)
    deband_c = placebo.Deband(credit,
                              radius=16,
                              threshold=4,
                              iterations=1,
                              grain=0)
    deband_d = placebo.Deband(deband_b,
                              radius=20,
                              threshold=5,
                              iterations=1,
                              grain=0)
    deband = lvf.rfs(deband_a, deband_b, [(opstart, opstart + 146)])
    deband = lvf.rfs(deband, deband_c, [(opstart + 1225, opstart + 1238)])
    deband = lvf.rfs(deband, deband_d, [(opstart + 970, opstart + 984)])
    deband = core.std.MaskedMerge(deband, credit, deband_mask)

    grain_original = core.std.MergeDiff(deband, diff, [0, 1, 2])
    grain_new = core.neo_f3kdb.Deband(deband,
                                      preset='depth',
                                      grainy=32,
                                      grainc=32)
    avg = core.std.PlaneStats(deband)
    adapt_mask = core.adg.Mask(get_y(avg), 28)
    grain_adapt = core.std.MaskedMerge(grain_new, grain_original, adapt_mask)

    grain = core.std.FrameEval(
        deband, partial(_diff, new=grain_new, adapt=grain_adapt), avg)

    grain = lvf.rfs(grain, grain_new, [(opstart + 147, opstart + 496),
                                       (opstart + 575, opstart + 644),
                                       (opstart + 702, opstart + 969),
                                       (opstart + 1076, opstart + 1117),
                                       (opstart + 1428, opstart + 1461),
                                       (opstart + 1859, opstart + 2035)])
    grain = lvf.rfs(grain, grain_original, [(14412, 14728), (31146, 31299)])

    w2x = _w2x(denoise).grain.Add(1, 0.5, constant=True)
    w2x = lvf.rfs(grain, w2x, [(opstart + 1211, opstart + 1224)])

    ending = _perform_filtering_ending(src, adapt_mask)
    ending = vdf.merge_chroma(ending, denoise)
    final = lvf.rfs(w2x, ending, [(edstart, edend)])

    return depth(final, 10)
Example #26
0
def do_filter():
    """Vapoursynth filtering"""
    # Source and dithering
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    # Variables
    h = 846
    w = get_w(h)
    cubic_filters = ['catrom', 'mitchell', 'robidoux', 'robidoux sharp']
    cubic_filters = [vdf.get_bicubic_params(cf) for cf in cubic_filters]

    # Remove the dynamic grain
    degrain = hybrid_denoise(out, 0.35, 1.2, dict(a=2, d=1))
    out = degrain

    y = get_y(out)
    y32 = depth(y, 32)
    lineart = vdf.edge_detect(y32, 'kirsch', 0.055,
                              (1, 1)).std.Median().std.Inflate()

    # Use multiple descaling kernel for a sharper result
    descale_clips = [
        core.descale.Debicubic(y32, w, h, b, c) for b, c in cubic_filters
    ]
    descale = core.std.Expr(descale_clips,
                            'x y z a min min min x y z max max min')

    # Fix descaling artifacts (yes even for catrom there's still artifacts)
    conv = core.std.Convolution(descale, [1, 2, 1, 2, 0, 2, 1, 2, 1])
    thr, coef = 0.013, 3.2
    descale_fix = core.std.Expr([descale, conv],
                                f'x y - abs {thr} < y x ?').std.PlaneStats()
    adapt_mask = core.adg.Mask(
        descale_fix,
        12).std.Invert().std.Expr(f'x 0.80 - {coef} * 0.20 + 0 max 1 min')

    descale = core.std.MaskedMerge(descale, descale_fix, adapt_mask)

    # Double using eedi3+nnedi, fsrcnnx and a sharpener
    upscale = vdf.fsrcnnx_upscale(descale,
                                  w * 2,
                                  h * 2,
                                  r'shaders\FSRCNNX_x2_56-16-4-1.glsl',
                                  upscaler_smooth=eedi3_upscale,
                                  profile='zastin',
                                  sharpener=partial(gf.DetailSharpen,
                                                    sstr=1.25,
                                                    power=4))

    # Antialiasing by eedi3
    aa_strong = sraa_eedi3(upscale, 13, alpha=0.3, beta=0.5, gamma=40)
    aa = aa_strong

    # Rescale to 1080p with Bicubic b=0, c=0 AKA Hermite
    down = muvf.SSIM_downsample(aa,
                                src.width,
                                src.height,
                                filter_param_a=0,
                                filter_param_b=0)

    upscale = depth(core.std.MaskedMerge(y32, down, lineart), 16)

    merged = vdf.merge_chroma(upscale, out)
    out = merged

    # Deband with prefilter
    y = get_y(out)
    detail_light_mask = lvf.denoise.detail_mask(y, brz_a=2500, brz_b=1200)

    pf = iterate(out, core.std.Maximum, 2).std.Convolution([10] * 9, planes=0)
    diff = core.std.MakeDiff(out, pf)

    deband = core.f3kdb.Deband(pf,
                               17,
                               36,
                               36,
                               36,
                               12,
                               12,
                               2,
                               keep_tv_range=True,
                               output_depth=16)
    deband = core.std.MergeDiff(deband, diff)
    deband = core.std.MaskedMerge(deband, out, detail_light_mask)
    out = deband

    # Regraining
    grain = adptvgrnMod(out,
                        0.25,
                        0.15,
                        size=out.height / h,
                        sharp=80,
                        luma_scaling=10,
                        static=True)
    out = grain

    return depth(out, 10).std.Limiter(16 << 2, [235 << 2, 240 << 2])
Example #27
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])
Example #28
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 16)
    out = src

    h = 720
    w = get_w(h)

    fixedges = awf.bbmod(out, 2, 2, 2, 2, 64 << 8, 999)
    out = fixedges

    decomb = hvf.Vinverse(out)
    decomb = lvf.rfs(out, decomb, [(828, 836)])
    out = decomb

    clean = core.knlm.KNLMeansCL(out,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='UV')
    clean = core.knlm.KNLMeansCL(clean,
                                 h=0.55,
                                 a=2,
                                 d=3,
                                 device_type='gpu',
                                 device_id=0,
                                 channels='Y')
    diff_den = core.std.MakeDiff(out, clean)
    out = depth(clean, 32)

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, correct_shift=False,
                                 pscrn=1).resize.Bicubic(src.width,
                                                         src.height,
                                                         src_left=.5,
                                                         src_top=.5)
    rescale = core.std.MaskedMerge(luma, upscale, line_mask)

    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    moozzi = warping(out, 0.4, 4)
    sharp = hvf.LSFmod(moozzi,
                       strength=95,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    deband_mask = lvf.denoise.detail_mask(out, brz_a=2000, brz_b=1000)
    deband = dbs.f3kpf(out, 17, 30, 30)
    deband = core.std.MaskedMerge(deband, out, deband_mask)
    out = deband

    grain_org = core.std.MergeDiff(out, diff_den)
    out = grain_org

    ref = decomb
    credit_mask = vdf.diff_rescale_mask(ref, mthr=40, sw=5, sh=5)
    credit_mask = vdf.region_mask(credit_mask, 10, 10, 10,
                                  10).std.Inflate().std.Inflate()
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, credit_mask),
                     [(0, 725), (31741, 33864)])
    antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic)
    credit = lvf.rfs(credit, core.std.MaskedMerge(out, antialias, credit_mask),
                     [(833, 933), (1060, 1229), (1716, 1887), (2665, 2830),
                      (4813, 4947), (8179, 8272), (13757, 13810),
                      (20630, 20737), (20866, 20951), (21338, 21409),
                      (21480, 21520), (24719, 24786), (24829, 24869),
                      (28206, 28298), (28299, 28426), (33927, 34046)])
    out = credit

    return depth(out, 10)
Example #29
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src += src[-1] * 2
    h = 720
    w = get_w(h)

    edgesfix = awf.bbmod(src, 1, 1, 1, 1, 48, 500)
    out = edgesfix

    clip = depth(out, 32)
    denoise = hybrid_denoise(clip, 0.45, 1.5)
    out = denoise

    luma = get_y(out)
    line_mask = line_mask_func(luma)

    descale = core.descale.Debilinear(luma, w, h)
    upscale = vdf.nnedi3_upscale(descale, pscrn=1)
    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.4,
                                         beta=0.3,
                                         gamma=400,
                                         mdis=15).resize.Bilinear(
                                             src.width, src.height)

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

    preden = core.knlm.KNLMeansCL(get_y(out),
                                  h=0.75,
                                  a=2,
                                  d=3,
                                  device_type='gpu',
                                  device_id=0)
    detail_dark_mask = detail_dark_mask_func(preden, brz_a=8000, brz_b=6000)
    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.Convolution([1, 1, 1, 1, 1, 1, 1, 1, 1])

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

    deband_a = dbs.f3kpf(out, 17, 36, 42, thr=0.5, elast=2, thrc=0.2)
    deband_b = placebo.deband(out, 18, 5.5, 2, 0)

    deband = core.std.MaskedMerge(deband_a, deband_b, preden)
    deband = core.std.MaskedMerge(deband, out, detail_mask)

    deband = core.neo_f3kdb.Deband(deband,
                                   preset='depth',
                                   grainy=24,
                                   grainc=24)
    out = deband

    ref, src = [depth(x, 16) for x in [denoise, src]]
    credit_mask = vdf.drm(ref, kernel='bilinear', mthr=65)
    credit = out
    credit = lvf.rfs(credit, core.std.MaskedMerge(credit, ref, credit_mask, 0),
                     [(0, 1380), (36437, 38719)])
    credit = lvf.rfs(credit, ref, [(20810, 20881),
                                   (38720, src.num_frames - 1)])
    out = credit

    grain = adptvgrnMod(out,
                        0.3,
                        0.15,
                        1.25,
                        luma_scaling=8,
                        sharp=80,
                        static=False,
                        lo=19)
    out = grain

    return depth(out, 10)
Example #30
0
def do_filter():
    """Vapoursynth filtering"""
    src = JPBD.src_cut
    src = depth(src, 32)

    h = 720
    w = get_w(h)
    b, c = vdf.get_bicubic_params('robidoux')
    full_stuff = [(0, 1310), (15484, 15639)]

    denoise = hybrid_denoise(src, 0.5, 2)
    out = denoise

    luma = get_y(out)
    line_mask = vdf.edge_detect(luma, 'FDOG', 0.05, (1, 1))

    descale = core.descale.Debicubic(luma, w, h, b, c)
    upscale = vdf.fsrcnnx_upscale(descale, None, descale.height * 2,
                                  '_shaders/FSRCNNX_x2_56-16-4-1.glsl',
                                  core.resize.Point)
    upscale_smooth = vdf.nnedi3_upscale(descale, pscrn=1)
    upscale = lvf.rfs(upscale, upscale_smooth, [(5534, 5598)])

    antialias = single_rate_antialiasing(upscale,
                                         13,
                                         alpha=0.3,
                                         beta=0.45,
                                         gamma=320,
                                         mdis=18)

    scaled = muvf.SSIM_downsample(antialias,
                                  src.width,
                                  src.height,
                                  kernel='Bicubic')
    rescale = core.std.MaskedMerge(luma, scaled, line_mask)
    merged = vdf.merge_chroma(rescale, out)
    out = depth(merged, 16)

    # Slight sharp though CAS
    sharp = hvf.LSFmod(out,
                       strength=75,
                       Smode=3,
                       Lmode=1,
                       edgemode=1,
                       edgemaskHQ=True)
    out = sharp

    dering = gf.HQDeringmod(out, thr=16, darkthr=0.1)
    out = dering

    warp = xvs.WarpFixChromaBlend(out, thresh=48, depth=8)
    out = warp

    preden = core.knlm.KNLMeansCL(out,
                                  d=0,
                                  a=3,
                                  h=0.6,
                                  device_type='GPU',
                                  channels='Y')
    deband_mask = lvf.denoise.detail_mask(preden, brz_a=2000, brz_b=800, rad=4)

    deband = dbs.f3kpf(out, 17, 42, 42)

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

    out = deband

    adg_mask = core.adg.Mask(out.std.PlaneStats(),
                             20).std.Expr(f'x x {128<<8} - 0.25 * +')
    grain = core.grain.Add(out, 0.2, constant=True)
    grain = core.std.MaskedMerge(out, grain, adg_mask, 0)
    out = grain

    rescale_mask = vdf.drm(luma, b=b, c=c, sw=4, sh=4)
    ref, rescale_mask, src = [
        depth(x, 16) for x in [denoise, rescale_mask, src]
    ]
    credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, rescale_mask),
                     full_stuff)
    credit = lvf.rfs(credit, src, [(31707, 33937)])
    out = credit

    smooth = gf.JohnFPS(out[31707:33937 + 1], 60000, 1001)
    clips = [out[:31707], smooth, out[33937 + 1:]]
    vfr = muvf.VFRSplice(clips, 'symphogearg_13_timecode.txt')
    cfr = core.std.AssumeFPS(vfr, src)
    out = cfr

    return depth(out, 10)