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)
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])
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src if out.num_frames < 34046: while out.num_frames != 34046: out += out[-1] opstart, opend = 0, 2157 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, [(2187, 2195)]) ref = decomb out = decomb from adptvgrnMod import adptvgrnMod first_denoise = hybrid_denoise(out, 0.35, 1.5) regrain = adptvgrnMod(first_denoise, 0.275, 0.175, 1.25, 45) regrain = lvf.rfs(out, regrain, [(28691, 28818)]) out = regrain 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 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() antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic) credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask), [(2188, 2305), (33926, src.num_frames-1)]) credit = lvf.rfs(credit, core.std.MaskedMerge(out, ref, credit_mask), [(31684, 33925)]) out = credit src_c, ncop = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut]] opening_mask = vdf.dcm(out, src_c[opstart:opend+1], ncop[:opend-opstart+1], opstart, opend, 3, 3) credit_mask = opening_mask.std.Convolution([1]*9) credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask), [(opstart, opend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src opstart, opend = 3106, 5263 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, [(10171, 10179)]) ref = decomb 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 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() antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic) credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask), [(10178, 10248), (21423, 22764)]) out = credit src_c, ncop = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut]] opening_mask = vdf.dcm(out, src_c[opstart:opend + 1], ncop[:opend - opstart + 1], opstart, opend, 3, 3).std.Convolution([1] * 9) credit = lvf.rfs(out, core.std.MaskedMerge(out, src, opening_mask), [(opstart, opend)]) out = credit logo_mask = lvf.src('credit_mask_logo.png', out).std.Convolution([1] * 9) credit = lvf.rfs(out, core.std.MaskedMerge(out, ref, logo_mask), [(20992, 23225)]) credit = lvf.rfs(credit, src, [(97766, src.num_frames - 1)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_cut src = depth(src, 16) out = src if out.num_frames < 34046: while out.num_frames != 34046: out += out[-1] opstart, opend = 456, 2613 edstart, edend = 31767, 33924 h = 720 w = get_w(h) fixedges = awf.bbmod(out, 2, 2, 2, 2, 64<<8, 999) out = fixedges 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 = fixedges 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() antialias = lvf.sraa(ref, 2, 13, downscaler=core.resize.Bicubic) credit = lvf.rfs(out, core.std.MaskedMerge(out, antialias, credit_mask), [(2660, 2733), (33925, src.num_frames-1)]) out = credit src_c, ncop, nced = [clip.std.Median() for clip in [src, JPBD_NCOP.src_cut, JPBD_NCED.src_cut]] opening_mask = vdf.dcm(out, src_c[opstart:opend+1], ncop[:opend-opstart+1], opstart, opend, 3, 3) ending_mask = vdf.dcm(out, src_c[edstart:edend+1], nced[:edend-edstart+1], edstart, edend, 3, 3) credit_mask = core.std.Expr([opening_mask, ending_mask], 'x y +').std.Convolution([1]*9) credit = lvf.rfs(out, core.std.MaskedMerge(out, src, credit_mask), [(opstart, opend), (edstart, edend)]) out = credit return depth(out, 10)
def do_filter(): """Vapoursynth filtering""" src = JPBD.src_clip src = depth(src, 16) src = src[:34016] + src[34016 + 24 * 2 + 22:-24] 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, [(756, 764)]) ref = decomb out = decomb from adptvgrnMod import adptvgrnMod first_denoise = hybrid_denoise(out, 0.35, 1.5) regrain = adptvgrnMod(first_denoise, 0.275, 0.175, 1.25, 45) regrain = lvf.rfs(out, regrain, [(23709, 23786), (30397, 30546)]) out = regrain 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_b = core.neo_f3kdb.Deband(out, 31, 18, 18, 18, 0, 0, 4) import placebo deband_c = placebo.deband(out, 18, 6, 1, 2) deband = lvf.rfs(deband, deband_b, [(16328, 16607), (17272, 17447)]) deband = lvf.rfs(deband, deband_c, [(23709, 23786), (30397, 30546), (31115, 31353)]) deband = core.std.MaskedMerge(deband, out, deband_mask) out = deband grain_org = core.std.MergeDiff(out, diff_den) out = grain_org 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, 661), (26731, 34015)]) credit = lvf.rfs(credit, src, [(34016, src.num_frames - 1)]) out = credit return depth(out, 10)