Welcome to Doom9's Forum, THE in-place to be for everyone interested in DVD conversion. Before you start posting please read the forum rules. By posting to this forum you agree to abide by the rules.

 Doom9's Forum Super Slow Sharpen
 Register FAQ Calendar Search Today's Posts Mark Forums Read

 2nd December 2007, 03:52 #1  |  Link *.mp4 guy Registered User     Join Date: Feb 2004 Posts: 1,350 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.
 2nd December 2007, 08:44 #2  |  Link TheRyuu warpsharpened   Join Date: Feb 2007 Posts: 787 I can't find 2 plugins needed for the script: unsharp, and gaussianblur. And I always though I had all the filters I'd ever need :P
 2nd December 2007, 10:04 #3  |  Link *.mp4 guy Registered User     Join Date: Feb 2004 Posts: 1,350 They are both part of the variableblur plugin by tsp.
 2nd December 2007, 13:28 #4  |  Link Didée Registered User   Join Date: Apr 2002 Location: Germany Posts: 5,394 There is a possible speed improvement, target is MedianBlur. MedianBlur alas is rather slow compared to the available faster alternatives. MedianBlur(1) can be replaced by RemoveGrain(4). That's 2.5 to 3 times faster. With radii > 1, MedianBlur(r) can be replaced by Quantile(), which is part of kassandro's new RemoveGrainHD filter package. The parameters are a bit unintuitive at first glance, however Quantile runs at least 2.5 times as fast as MedianBlur, if not more. Not sure how much impact this has in the context of the whole script (it seems very very slow just by looking at the script's code), but at least this particular filter is an obvious target for optimization. __________________ - We´re at the beginning of the end of mankind´s childhood - My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)
 2nd December 2007, 23:01 #5  |  Link tsp Registered User     Join Date: Aug 2004 Location: Denmark Posts: 807 also using binomialBlur instead of gaussianblur might be worth a try. __________________ Get my avisynth filters @ http://www.avisynth.org/tsp/
 3rd December 2007, 05:47 #6  |  Link *.mp4 guy Registered User     Join Date: Feb 2004 Posts: 1,350 @ tsp How big is the difference between a vary=1 guassianblur and a var=1 binomialblur? @Didée Do you know if removegrain(4) has higher or lower ram usage then medianblur(1)?  I tried to implement removegrain instead of medianblur for aplicable radii, but avisynth is barfing on all of the if : then's, I might just split out a separate function for it. Last edited by *.mp4 guy; 3rd December 2007 at 06:26.
3rd December 2007, 13:17   #7  |  Link
Didée
Registered User

Join Date: Apr 2002
Location: Germany
Posts: 5,394
Quote:
 Originally Posted by *.mp4 guy How big is the difference between a vary=1 guassianblur and a var=1 binomialblur?
Big enough to make a noticeable difference.

Quote:
 Do you know if removegrain(4) has higher or lower ram usage then medianblur(1)?
From testing with your function: a bit lower, it seems.

Quote:
 I tried to implement removegrain instead of medianblur for aplicable radii, but avisynth is barfing on all of the if : then's,
Hmm, I cannot reproduce that. To make use of the alternative filters, I changed two lines in HaloMask():

Code:
```	s = c
mask3 = mt_lutxy(Ablur, Gblur, "y x - abs "+string(hthr)+" * "+string(hbias)+" +", U=1, V=1)```
- That's all. No crashes or anything, even with insane settings.

Measures with SetMemoryMax(300) on a 2.8GHz Core2, 720x576 PAL smaple:
(Note that it's frames per *minute* ...)

SSSharp()
original: 23fpm
modded: 53 fpm

original: 3.4 fpm
modded: 6.5 fpm

Those were quick'n dirty tests - short sample, only one repetition, no reboot inbetween, etc. Short of time, sorry. Still, it seems that the speed is roughly doubled by those changes, perhaps even more.
__________________
- We´re at the beginning of the end of mankind´s childhood -

My little flickr gallery. (Yes indeed, I do have hobbies other than digital video!)

 3rd December 2007, 20:01 #8  |  Link *.mp4 guy Registered User     Join Date: Feb 2004 Posts: 1,350 Thanks Didée, the way I was trying to implement it was pretty braindead... which is, I'm sure why I had problems.
 4th December 2007, 23:37 #9  |  Link Soulhunter Bored...     Join Date: Apr 2003 Location: Unknown Posts: 2,812 Wow! After seeing the long aWarpSharp chain, I was a bit shocked... But looking at your example n considering how blurry the source is, the result surprises me... Looks almost like some sort of deconvolution! How does it look in motion? [Is the effect "stable"?] Can you give some more samples? [Different content, less blurry -> less filtering, a source with higher resolution...] :] Thx n' Bye __________________ Visit my IRC channel Last edited by Soulhunter; 4th December 2007 at 23:46.
4th December 2007, 23:53   #10  |  Link
*.mp4 guy
Registered User

Join Date: Feb 2004
Posts: 1,350
Quote:
 Originally Posted by Soulhunter Wow! After seeing the long aWarpSharp chain, I was a bit shocked... But looking at your example n considering how blurry the source is, the result surprises me... Looks almost like some sort of deconvolution! How does it look in motion? [Is the effect "stable"?] Can you give some more samples? [Different content, less blurry -> less filtering, a source with higher resolution...] Thx n' Bye
The effect is completely stable (aslong as super sampling is used during mask generation, as it was in the example). To answer your second question, yes I can provide some more samples using a higher quality source, but the effect will be more subtle because there isn't as much room for improvement with good sources. I should also mention that this sharpening method sharpens halos just as much as it sharpens everything else, so given a source with haloig, sharpening it with SSSharp will make it worse, just to a much lesser extent then a regular unsharp mask.

I'm currently running a very ram hungry script, it should be done soon, and when it is I'll edit this post with a few more examples.

script:
Code:
```MPEG2Source("J:\THANKYOUFORSMOKING_WS\VIDEO_TS\TYFS.d2v", cpu=0, info=3).colormatrix(hints=true).crop(0, 60, 0, -60)

SSSharp(denoise=1, iter=2, ssw=true)```
SSSharp, no processing
SSSharp, no processing
SSSharp, no processing

Keep in mind that these examples are actualy very oversharp, and wouldn't look good after being scaled up to fullscreen, realistically this source doesn't need such strong sharpening.

Last edited by *.mp4 guy; 5th December 2007 at 01:00.

 6th December 2007, 17:27 #11  |  Link foxyshadis ангел смерти     Join Date: Nov 2004 Location: Lost Posts: 9,529 I vote for calling it GlacialSharpen, though thanks to Didée it's no longer EpochSharpen. (EpicSharpen?) Works great for scans, though waiting 10 seconds every attempt while finding the right settings can be rather frustrating. __________________ There are four boxes to be used in defense of liberty: soap, ballot, jury, and ammo. Please use in that order.
 9th December 2007, 07:12 #12  |  Link 序列人 Registered User   Join Date: Jul 2006 Posts: 23 Very Very Very Slow!
 14th December 2007, 06:09 #13  |  Link EasyStart Registered User   Join Date: Apr 2002 Posts: 47 I get an error message when I tried the script - no function named "unsharp". Where can I download the unsharp filter. Easystart
 14th December 2007, 06:22 #14  |  Link EasyStart Registered User   Join Date: Apr 2002 Posts: 47 Sorry guys. Forget my previous post. I didn't read the posts correctly from the beginning. Easystart
 10th January 2008, 12:42 #15  |  Link xbox360 Registered User     Join Date: Aug 2006 Location: Region 3 with NDS Encryption Posts: 355 May you please list down all the plugin's needed to run this Super Slow Sharpen script please, thank you.
 10th January 2008, 18:54 #16  |  Link *.mp4 guy Registered User     Join Date: Feb 2004 Posts: 1,350 removegrain, quantile, variableblur, masktools 2, awarpsharp, degrainmedian and dctfun4b.
 11th January 2008, 02:33 #17  |  Link xbox360 Registered User     Join Date: Aug 2006 Location: Region 3 with NDS Encryption Posts: 355 Can you give a sample full working script with all the loaded plugins + syntax & everything else please, thank you.
 12th January 2008, 00:15 #18  |  Link *.mp4 guy Registered User     Join Date: Feb 2004 Posts: 1,350 Just put the plugins in the autoload directory. The only thing you should bother changing is the strength parameter, 4, the default value, is very strong.
12th January 2008, 03:15   #19  |  Link
xbox360
Registered User

Join Date: Aug 2006
Location: Region 3 with NDS Encryption
Posts: 355
Quote:
 Originally Posted by *.mp4 guy Just put the plugins in the autoload directory. The only thing you should bother changing is the strength parameter, 4, the default value, is very strong.
I do not compute, seriously I dont understand, can you give a step by step guide please, thank you. I hope it's not too troublesome. Also I get this error -> unsharp unknown command

12th January 2008, 03:31   #20  |  Link
Shinigami-Sama
Solaris: burnt by the Sun

Join Date: Oct 2004
Location: /etc/default/moo
Posts: 1,923
Quote:
<3
+1

also
this looks really cool
I've got some lame scans and such laying around that would benefit from this
'course that means I'd have to set avisynth again
__________________
Quote:
 Originally Posted by benjust interlacing and telecining should have been but a memory long ago.. unfortunately still just another bizarre weapon in the industries war on image quality.