def solarcurve(input): core = vs.get_core() clip = input funcName = 'solarcurve' clip = mvf.ToRGB(clip, depth=8) pi = 3.1415926535 t = 5 k = 5.5 A = -1 / 4194304 * (k * pi - 128 / t) B = 3 / 32768 * (k * pi - 128 / t) C = 1 / t def curveR(x): a = round(127.9999 * math.sin(A * (x)**3 + B * (x)**2 + C**(x)) + 127.5) return a def curveG(x): a = round(127.9999 * math.sin(A * (x - 5)**3 + B * (x - 5)**2 + C**(x - 5)) + 127.5) return a def curveB(x): a = round(127.9999 * math.sin(A * (x + 5)**3 + B * (x + 5)**2 + C**(x + 5)) + 127.5) return a clip = core.std.Lut(clip=clip, planes=[0], function=curveR) clip = core.std.Lut(clip=clip, planes=[1], function=curveG) clip = core.std.Lut(clip=clip, planes=[2], function=curveB) clip = mvf.ToYUV(clip, depth=8) return clip
def run(self, clip, chunk=False): # convert clip to RGB24 as it cannot read any other color space buffer = mvsfunc.ToRGB(clip, depth=8, kernel="spline36") # expecting RGB24 (RGB 8bpp) # send the clip array to execute() results = [] for c in self.chunk_clip(buffer) if chunk else [buffer]: results.append( core.std.FrameEval( core.std.BlankClip(clip=c, width=c.width * self.model_scale, height=c.height * self.model_scale), functools.partial(self.execute, clip=c))) # if chunked, rejoin the chunked clips otherwise return the result buffer = core.std.StackHorizontal([ core.std.StackVertical([results[0], results[1]]), core.std.StackVertical([results[2], results[3]]) ]) if chunk else results[0] # VSGAN used to convert back to the original color space which resulted # in a LOT of guessing, which was in-accurate and may not be efficient # depending on what the user is doing after running VSGAN, so in all # versions after 1.0.6-post1 we return it in the colorspace the GAN # provides which is always RGB24. # return the new frame return buffer
def random_compare(clips, seed1=33, seed2=66): random.seed(seed1) offs = random.randint(0, 10000) * 2 random.seed(seed2) every = random.randint(10000, 20000) * 2 cpr = core.std.Interleave(clips) cpr = sgf.SelectRangeEvery(cpr, offset=offs, every=every, length=2) cpr = mvf.ToRGB(cpr, depth=8, dither=6, full=False, matrix="709") return cpr
def camp(src): src16 = core.fmtc.bitdepth(src, bits=16) src_rgb = mvf.ToRGB(src16,depth=32) nr16_rgb = core.pdn.BM3DBasic(src_rgb, sigma=[0.5, 0.2, 0.2]) nr16 = mvf.ToYUV(nr16_rgb, css="420",depth=16) noise16 = core.std.MakeDiff(src16, nr16) pre16 = core.std.ShufflePlanes([nr16,src16],[0,1,2],vs.YUV) pre8 = mvf.Depth(pre16, depth=8, dither=5) eemask = core.tcanny.TCanny(pre8,sigma=0.6,op=2,gmmax=255,planes=[0,1,2],mode=1) eemask_u = core.std.ShufflePlanes(eemask, [1,1,1], vs.YUV).fmtc.resample(1920,1080,sx=0.25,css="420") eemask_v = core.std.ShufflePlanes(eemask, [2,2,2], vs.YUV).fmtc.resample(1920,1080,sx=0.25,css="420") weighted = core.std.Expr([eemask,eemask_u,eemask_v],["x 64 * y + z +",""],vs.YUV420P16) luma = core.std.ShufflePlanes(pre8, 0, vs.YUV).resize.Bilinear(format=vs.YUV420P8) eemask = core.std.Expr([eemask,luma],["x x * 20 * 255 y - dup * 0.2 * + 50000 min","x x * 30 * 255 y - dup * 0.3 * + 60000 min"],vs.YUV420P16) eemask = core.std.Maximum(eemask,planes=[0,1,2]) eemask = core.rgvs.RemoveGrain(eemask, [20,11]).rgvs.RemoveGrain([20,11]).rgvs.RemoveGrain([20,11]) aamask = core.std.Binarize(weighted, 8000, 0) Y = core.std.ShufflePlanes(src16, 0, vs.YUV).resize.Bicubic(1920, 1080, format=vs.YUV420P16, filter_param_a=0, filter_param_b=0.5) U = core.std.ShufflePlanes(src16, [1,1,1], vs.YUV).resize.Bicubic(1920, 1080, format=vs.YUV420P16, filter_param_a=0, filter_param_b=0.5) V = core.std.ShufflePlanes(src16, [2,2,2], vs.YUV).resize.Bicubic(1920, 1080, format=vs.YUV420P16, filter_param_a=0, filter_param_b=0.5) textmask0 = core.std.Expr([Y,U,V], ["x 60000 > y 32768 - abs 768 < and z 32768 - abs 768 < and 65535 0 ?","0"]) #textmasks = core.std.Expr([Y,U,V], ["x 58000 > y 32768 - abs 512 < and z 32768 - abs 512 < and 65535 0 ?","0"]) textmask1 = core.std.Minimum(textmask0, 0).std.Minimum(planes=0).std.Minimum(planes=0).std.Maximum(0).std.Maximum(0).std.Maximum(0) textmask2 = core.misc.Hysteresis(textmask1, textmask0, planes=0) textmask = core.std.Expr([textmask0, textmask2], "x y > x 0 ?") #textmask = core.misc.Hysteresis(textmasks, textmaskb, planes=0) textmask = core.std.Maximum(textmask,0).std.Maximum(0).std.Maximum(0)#.std.Maximum(0)#.std.Maximum(0)#.std.Maximum(0)#.std.Minimum(0) debd = bbf.deband_2pass(nr16) w = 1920 h = 1080 oaa_y = core.std.ShufflePlanes(nr16, 0, vs.GRAY) aa_y = core.eedi2.EEDI2(oaa_y,field=1,mthresh=10,lthresh=20,vthresh=20,maxd=24,nt=50).fmtc.resample(w,h,sy=-0.5, kernel='bicubic', a1=0, a2=0.5,).std.Transpose() aa_y = core.eedi2.EEDI2(aa_y,field=1,mthresh=10,lthresh=20,vthresh=20,maxd=24,nt=50).fmtc.resample(h,w,sy=-0.5, kernel='bicubic', a1=0, a2=0.5,).std.Transpose() aa_clip = core.std.ShufflePlanes([aa_y,debd], [0,1,2], vs.YUV) aaed = core.std.MaskedMerge(debd, aa_clip, aamask, 0, True) aaed = core.std.MaskedMerge(aaed, debd, textmask, 0, False) dif = core.std.MakeDiff(aaed, core.rgvs.RemoveGrain(aaed,20)) sharp = core.std.MergeDiff(aaed, dif) sharped = core.std.MaskedMerge(sharp, aaed, eemask, [0,1,2], False) noise16 = core.std.Expr(noise16,["x 32768 - 1.05 * 32768 +",""]) nullclip = core.std.Expr(src16,["32768",""]) nrweight = core.std.Expr(pre8, ["x 48 - 0 max dup * 5 * ",""], vs.YUV420P16) noise16 = core.std.MaskedMerge(noise16,nullclip,nrweight,0,True) res = core.std.MergeDiff(sharped,noise16,0) return res
def comparelist( sclip, eclip, savepath, Title, numb=12, style="sans-serif,20,&H00FFFFFF,&H000000FF,&H00000000,&H00000000,0,0,0,0,100,100,0,0,1,2,0,7,10,10,10,1" ): os.makedirs(savepath, exist_ok=True) flist = [] while len(flist) < numb: num = abs(len(flist) - numb) start = int(len(sclip) * random.random() * 0.06 + 0.05) end = int(len(sclip) * (random.random() * 0.1 + 0.8)) farmlist = range(start, end, int((end - start) / num)) for i in farmlist: if not eclip[1].get_frame(i).props._PictType.decode() == 'B': continue if sclip.get_frame(i).props._PictType.decode() == 'I': continue flist.append(i) sclip = FrameInfo(sclip, 'Source') sclip = mvf.ToRGB(sclip) sclip = core.imwri.Write(sclip, "png", os.path.join(savepath, '%d-A.png'), overwrite=True) for i in flist: sclip.get_frame(i) ecn = 0 for ec in eclip: ec = FrameInfo(ec, Title[ecn], style=style) ec = mvf.ToRGB(ec) ec = core.imwri.Write(ec, "png", os.path.join(savepath, f'%d-B-{ecn}.png'), overwrite=True) for i in flist: ec.get_frame(i) ecn = ecn + 1 return eclip
def pmf_output( clips : list , debug : bool = None , torgb : bool = None ) -> vs.VideoNode : funcName = "pmf_output" debug = True if debug is None else debug torgb = False if torgb is None else torgb if debug: for i in range(len(clips)): if not isinstance(clips[i], vs.VideoNode): raise TypeError(funcName + ': \"input should be a clip!\"') else: clips[i] = core.text.FrameNum(clips[i], 8) clips[i] = core.text.Text(clips[i], r"Clip"+str(i+1), alignment=5) res = core.std.Interleave(clips) if torgb: res = mvf.ToRGB(res, full=False, depth=8) else: res = clips[0] res.set_output()
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 resample(clip): # Resampling to 8bit and RGB to properly display how it appears on your screen return fvf.Depth(mvf.ToRGB(clip), 8)
useRGB = False scale = 2 linear_scale = False upfilter = 'bicubic' # data = '00003.m2ts' data = r'I:\Anime\The Garden of Words\BDROM\BDMV\STREAM\00000.m2ts' data_dim = 41 planes = 3 if useRGB else 1 # Get source and do format conversion core = vs.get_core() label_clip = core.lsmas.LWLibavSource(data) if useRGB: label_clip = mvf.ToRGB(label_clip, depth=32) else: label_clip = mvf.Depth(label_clip.std.ShufflePlanes(0, vs.GRAY), 32) # Prepare data down_lists = list(range(1, 8)) data_clip = core.std.Interleave([ resample(label_clip, scale, linear_scale, d, upfilter) for d in down_lists ]) label_clip = core.std.Interleave([label_clip for d in down_lists]) w = data_clip.width h = data_clip.height nb_frame = data_clip.num_frames assert w == label_clip.width assert h == label_clip.height
def w2c_denoise(clip: vs.VideoNode, noise: int, **kwargs) -> vs.VideoNode: clip = mvf.ToRGB(clip, depth=32) w2c = core.w2xc.Waifu2x(clip, noise, 1, **kwargs) return mvf.ToYUV(w2c, css='420', depth=32)
def OpenCV_Detail(clip, strength=100): enhance_core = cv2.detailEnhance # aliasing clip = mvs.ToRGB(clip, depth = 8) pclip = mufnp.numpy_process(clip, enhance_core, input_per_plane=False, output_per_plane=False) return core.std.Merge(clip, pclip, (strength * 0.01))
def mts(src): src8 = mvf.ToYUV(src, css='420') src16 = core.fmtc.bitdepth(src8,bits=16) # Denoise src_rgb = mvf.ToRGB(src16,depth=32) #nr16_rgb = core.pdn.BM3DBasic(src_rgb, sigma=[0.5, 0.2, 0.2],group_size=16, bm_range=8) nr16_rgb = core.pdn.BM3DBasic(src_rgb, sigma=[1.0, 0.5, 0.5]) nr16 = mvf.ToYUV(nr16_rgb, css="420",depth=16) noise16 = core.std.MakeDiff(src16, nr16) # Mask pre16 = core.std.ShufflePlanes([nr16,src16],[0,1,2],vs.YUV) pre8 = mvf.Depth(pre16, depth=8, dither=5) eemask = core.tcanny.TCanny(pre8,sigma=0.6,op=2,gmmax=255,planes=[0,1,2],mode=1) eemask_u = core.std.ShufflePlanes(eemask, [1,1,1], vs.YUV).fmtc.resample(1920,1080,sx=0.25,css="420") eemask_v = core.std.ShufflePlanes(eemask, [2,2,2], vs.YUV).fmtc.resample(1920,1080,sx=0.25,css="420") weighted = core.std.Expr([eemask,eemask_u,eemask_v],["x 64 * y + z +",""],vs.YUV420P16) luma = core.std.ShufflePlanes(pre8, 0, vs.YUV).resize.Bilinear(format=vs.YUV420P8) eemask = core.std.Expr([eemask,luma],["x x * 20 * 255 y - dup * 0.2 * + 50000 min","x x * 30 * 255 y - dup * 0.3 * + 60000 min"],vs.YUV420P16) eemask = core.std.Maximum(eemask,planes=[0,1,2]) eemask = core.rgvs.RemoveGrain(eemask, [20,11]).rgvs.RemoveGrain([20,11]).rgvs.RemoveGrain([20,11]) aamask = core.std.Binarize(weighted, 12000, 0) nrmasks = core.std.Binarize(weighted, 4500, 0) dmaskb = core.std.Binarize(weighted, 3000, 0) dmaskm = core.std.Binarize(weighted, 3500, 0) dmasks = core.std.Binarize(weighted, 3800, 0) dmask_dark = core.misc.Hysteresis(dmaskm, dmaskb) dmask_bright = core.misc.Hysteresis(dmasks, dmaskm) dmask = core.std.Expr([src16, dmask_dark, dmask_bright], "x 24672 < y z ?") nrmaskg = core.tcanny.TCanny(pre8,sigma=1.5,t_l=8,t_h=15,op=2,planes=0) nrmaskb = core.tcanny.TCanny(pre8,sigma=1.2,t_l=8,t_h=11,op=2,planes=0) nrmask = core.std.Expr([nrmaskg,nrmaskb,nrmasks,pre8,dmask],["a 20 < 65535 a 64 < x 257 * b max a 160 < y 257 * z ? ? ?","",""],vs.YUV420P16) nrmask = core.std.Maximum(nrmask,0).std.Maximum(0).std.Minimum(0).std.Minimum(0) nrmask = core.rgvs.RemoveGrain(core.rgvs.RemoveGrain(nrmask,[20,0]),[20,0]) Y = core.std.ShufflePlanes(src16, 0, vs.YUV).resize.Bicubic(1920, 1080, format=vs.YUV420P16, filter_param_a=0, filter_param_b=0.5) U = core.std.ShufflePlanes(src16, [1,1,1], vs.YUV).resize.Bicubic(1920, 1080, format=vs.YUV420P16, filter_param_a=0, filter_param_b=0.5) V = core.std.ShufflePlanes(src16, [2,2,2], vs.YUV).resize.Bicubic(1920, 1080, format=vs.YUV420P16, filter_param_a=0, filter_param_b=0.5) textmask0 = core.std.Expr([Y,U,V], ["x 60000 > y 32768 - abs 768 < and z 32768 - abs 768 < and 65535 0 ?","0"]) #textmasks = core.std.Expr([Y,U,V], ["x 58000 > y 32768 - abs 512 < and z 32768 - abs 512 < and 65535 0 ?","0"]) textmask1 = core.std.Minimum(textmask0, 0).std.Minimum(planes=0).std.Minimum(planes=0).std.Maximum(0).std.Maximum(0).std.Maximum(0) textmask2 = core.misc.Hysteresis(textmask1, textmask0, planes=0) textmask = core.std.Expr([textmask0, textmask2], "x y > x 0 ?") #textmask = core.misc.Hysteresis(textmasks, textmaskb, planes=0) textmask = core.std.Maximum(textmask,0).std.Maximum(0).std.Maximum(0)#.std.Maximum(0)#.std.Maximum(0)#.std.Maximum(0)#.std.Minimum(0) debd = core.f3kdb.Deband(nr16,8,48,32,32,0,0,output_depth=16) debd = core.f3kdb.Deband(debd,15,32,24,24,0,0,output_depth=16) debd = mvf.LimitFilter(debd,nr16,thr=0.7,thrc=0.5,elast=2.0) debd = core.std.MaskedMerge(debd, nr16, nrmask, first_plane=1) w = 1920 h = 1080 oaa_y = core.std.ShufflePlanes(nr16, 0, vs.GRAY) aa_y = core.eedi2.EEDI2(oaa_y,field=1,mthresh=10,lthresh=20,vthresh=20,maxd=24,nt=50).fmtc.resample(w,h,sy=-0.5, kernel='bicubic', a1=0, a2=0.5,).std.Transpose() aa_y = core.eedi2.EEDI2(aa_y,field=1,mthresh=10,lthresh=20,vthresh=20,maxd=24,nt=50).fmtc.resample(h,w,sy=-0.5, kernel='bicubic', a1=0, a2=0.5,).std.Transpose() aa_clip = core.std.ShufflePlanes([aa_y,nr16], [0,1,2], vs.YUV) aaed = core.std.MaskedMerge(debd, aa_clip, aamask, 0, True) aaed = core.std.MaskedMerge(aaed, debd, textmask, 0, False) dif = core.std.MakeDiff(aaed, core.rgvs.RemoveGrain(aaed,20)) sharp = core.std.MergeDiff(aaed, dif) sharped = core.std.MaskedMerge(sharp, aaed, eemask, [0,1,2], False) noise16 = core.std.Expr(noise16,["x 32768 - 1.05 * 32768 +",""]) nullclip = core.std.Expr(src16,["32768",""]) nrweight = core.std.Expr(pre8, ["x 48 - 0 max dup * 5 * ",""], vs.YUV420P16) noise16 = core.std.MaskedMerge(noise16,nullclip,nrweight,0,True) res = core.std.MergeDiff(sharped,noise16,0) return res