View Single Post
Old 2nd December 2007, 03:52    |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
Super Slow Sharpen

Code:

#version 0.1, optimizations by Didée


function halomaskM(clip c, int "hthr", int "hbias", int "agmrad"){

	hthr = default(hthr, 256)
	hbias = default(hbias, -128)
	agmrad = default(agmrad, 1)

	s = c
	Mblur = (agmrad==1) ? s.removegrain(4,-1) : s.Quantile(radius_y=agmrad,radius_u=-1,radius_v=-1)
	gblur = (agmrad<=5) ? s.binomialblur(vary=agmrad, varc=0) : s.gaussianblur(vary=agmrad, varc=0)
	maskM = mt_lutxy(Mblur, Gblur, "y x - abs "+string(hthr)+" * "+string(hbias)+" +", U=1, V=1)
	
return(maskM)}

function halomaskMR(clip c, int "hthr", int "hbias"){

	hthr = default(hthr, 256)
	hbias = default(hbias, -128)
	
	s = c
	Ablur = s.removegrain(4)
	gblur = s.gaussianblur(vary=1, varc=0)
	mask3 = mt_lutxy(Ablur, Gblur, "y x - abs "+string(hthr)+" * "+string(hbias)+" +", U=1, V=1)

return(mask3)}


function SSW(clip c){
c#.unsharp()
w = width
h = height

spline36resize(w*3, h*3)

awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)

awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)
awarpsharp(cm=0, depth=3, blurlevel=1, thresh=0.99)

spline36resize(w, h)}

function SSSharp(clip c, float "rad", bool "ssw", float "strength", int "iter", bool "ss", int "denoise"){

rad = default(rad, 0.25)
ssw = default(ssw, true)
strength = default(strength, 4)
iter = default(iter, 1)
ss = default(ss, true)
denoise = default(denoise, iter)

c
w = width(c)
h = height(c)


sswc = ssw ? c.ssw() : c
(iter >= 1) ? MT_Merge(unsharp(vary=rad, varc=1, strength=strength), sswc, spline36resize((ss ? w*4 : w), (ss ? h*4 : h)).halomaskM(hbias=-128, hthr=256, agmrad=(ss ? round(rad*4) : round(rad))).spline36resize(w, h)) : last
(denoise >=1) ? degrainmedian(mode=3).dctfun4b(2,2) : last
(iter >= 2) ? MT_Merge(unsharp(vary=rad, varc=1, strength=strength), sswc, spline36resize((ss ? w*4 : w), (ss ? h*4 : h)).halomaskM(hbias=-128, hthr=256, agmrad=(ss ? round(rad*4)  : round(rad))).spline36resize(w, h)) : last
(denoise >=2) ? degrainmedian(mode=3).dctfun4b(2,2) : last
(iter >= 3) ? MT_Merge(unsharp(vary=rad, varc=1, strength=strength), sswc, spline36resize((ss ? w*4 : w), (ss ? h*4 : h)).halomaskM(hbias=-128, hthr=256, agmrad=(ss ? round(rad*4)  : round(rad))).spline36resize(w, h)) : last
(denoise >=3) ? degrainmedian(mode=3).dctfun4b(2,2) : last
(iter >= 4) ? MT_Merge(unsharp(vary=rad, varc=1, strength=strength), sswc, spline36resize((ss ? w*4 : w), (ss ? h*4 : h)).halomaskM(hbias=-128, hthr=256, agmrad=(ss ? round(rad*4)  : round(rad))).spline36resize(w, h)) : last
(denoise >=4) ? degrainmedian(mode=3).dctfun4b(2,2) : last
return(last)
}
Rad must be a multiple of 0.25 when ss=true, or 1 when ss=false. usable range is 0.25 to ~8, using a rad that is not close to the radius of the bluring present in your source will give suboptimal results. Higher iter, with lower strength will give more precise masking (less halos for same sharpening) but will be very slow.


example usage:
Code:
source = MPEG2Source("J:\GITS_D1\VIDEO_TS\GITS.d2v", cpu=0, info=3).colormatrix(hints=true, interlaced=true).crop(8,8,-8,-8).assumetff()
Deint = Source.securedeint().selecteven
IVTC = source.TFM(mode=7, clip2=deint, pp=7, slow=2, d2v="J:\GITS_D1\VIDEO_TS\GITS.d2v")
IVTC

SSSharp(ssw=true, iter=1, strength=1, rad=1)
SSSharp(ssw=true, iter=2, strength=3)

deen("m2d", 20, 12, 0)
example pic
no processing

Last edited by *.mp4 guy; 3rd December 2007 at 20:52.
*.mp4 guy is offline   Reply With Quote