Log in

View Full Version : FineSharp()


Pages : [1] 2

nibus
8th April 2012, 03:01
Didée, how would I go about making a nice .avsi out of that script so I could call it like


FineSharpen()

?

Sorry I have no scripting knowledge :o

Didée
8th April 2012, 13:04
Cracked up a function. Should work correctly, but more refinements about "usability" probably could be made. (In particular, there are no sanity checks for the parameters... - Quote IanB: "Give the user enough rope to hang himself" :) )

Required plugins: MaskTools, RemoveGrain, Repair.

# Small and relatively fast realtime-sharpening function,
# for 1080p, or after scaling 720p -> 1080p during playback (to make 720p look more like being 1080p)
# It's a generic sharpener. Only for good quality sources!
# (If the source is crap, FineSharp will happily sharpen the crap.) ;)
# Noise/grain will be enhanced, too. The method is GENERIC.
#
# Modus operandi: A basic nonlinear sharpening method is performed, then the *blurred* sharp-difference gets subtracted again.
#
# - Didée

function FineSharp(clip c, int "mode", float "sstr", float "cstr", float "xstr", float "lstr", float "pstr", float "ldmp")
{

mode = default(mode, 1 ) # 1 to 3, weakest to strongest. When negative -1 to -3, a broader kernel for equalisation is used.
sstr = default(sstr, 2.0 ) # strength of sharpening, 0.0 up to ??

_cstr = spline(sstr, 0,0, 0.5,0.1, 1.0,0.6, 2.0,0.9, 2.5,1.00, 3.0,1.09, 3.5,1.15, 4.0,1.19, 8.0,1.249, 255.0,1.5)
_cstr = (mode>0) ? _cstr : pow(_cstr,1./1.25)

cstr = default(cstr, _cstr) # strength of equalisation, 0.0 to ? 2.0 ? (recomm. 0.5 to 1.25, default AUTO)
xstr = default(xstr, 0.19 ) # strength of XSharpen-style final sharpening, 0.0 to 1.0 (but, better don't go beyond 0.249 ...)

# Viscera parameters
lstr = default(lstr, 1.49 ) # modifier for non-linear sharpening
pstr = default(pstr, 1.272) # exponent for non-linear sharpening
ldmp = default(ldmp, sstr+0.1) # "low damp", to not overenhance very small differences (noise coming out of flat areas)

str1 = sstr
str2 = cstr
SSTR = string(sstr)
CSTR = string(cstr)
LSTR = string(lstr)
PSTR = string(pstr)
LDMP = string(ldmp)
rg=mode>0?11:20

b = (abs(mode)==1) ? c.removegrain(11,-1).removegrain(4,-1)
\ : (abs(mode)==2) ? c.removegrain(4,-1).removegrain(11,-1)
\ : (abs(mode)==3) ? c.removegrain(4,-1).removegrain(11,-1).removegrain(4,-1) : c

shrpD = mt_lutxy(c,b,"x y - abs "+LSTR+" / 1 "+PSTR+" / ^ "+SSTR+" * x y - x y - abs 0.001 + / * x y - 2 ^ x y - 2 ^ "+LDMP+" + / * 128 +")

shrp = (str1<0.01) ? c : c.mt_adddiff(shrpD,U=2,V=2)

shrp = (str2<0.01) ? shrp : shrp.mt_makediff(shrpD.mt_lut("x 128 - "+CSTR+" * 128 +").removegrain(rg,-1),U=2,V=2)

shrp = (xstr<0.01) ? shrp
\ : mt_lutxy(shrp,shrp.removegrain(20,-1),"x x y - 9.9 * +",U=2,V=2).repair(shrp,12,0).mergeluma(shrp,1.0-xstr)

return(shrp)
}
Edit 2012-04-12 - added "ldmp" parameter, and slightly modified the (auto) cstr defaults

TheSkiller
8th April 2012, 15:09
Looks interesting. Didée, you say it's for HD sources of high quality, but what about SD sources of high quality? Is it a good idea to use this script with SD? :)
Can't test it right now, so I'm just asking without checking it myself.

travolter
9th April 2012, 15:54
@Didée

Pal your new sharpener scripts based in mt_lutxy are simply great. I using them since you posted a way to increase sharp on the inside of images and not borders... I have to test the ones posted in this topic VS the ones that you posted to create local constrast enhancement...

I dont see reason to go back to LSF.. this new sharpener way is best good looking (for my taste).

A little request.. can you post the scripts that you use daily for realtime playback. Im sure that we will learn so much with this info ;)
In my case I only apply framedoubling with SVP and then add your local contrast enhancement script

travolter
9th April 2012, 17:16
@didée

Im testing the "finesharp" script and the result is very similar to this old script that you posted and I continue using

str =1.49
o = last
b = o.removegrain(11).removegrain(4)
mt_lutxy(o,b,"x x y - abs 4 / 1 1.4 / ^ 4 * "+string(str)+" * x y - x y - abs 0.9 + / * +",U=2,V=2)


I also use this contrast mask to increase image quality

z = 6 # z = zero point
p = 1.6 # p = power
str = 1.0 # str = strength
rad = 3.0 # radius for "gauss"
o = last
g = o.bicubicresize(round(o.width()/rad/4)*4,round(o.height()/rad/4)*4).bicubicresize(o.width(),o.height(),1,0)
mt_lutxy(o,g,"x x y - abs "+string(z)+" / 1 "+string(p)+" / ^ "+string(z)+" * "+string(str)+" * x y - x y - abs 1.500 + / * +",U=2,V=2)

Question:

Its posible to rewrite these two scripts into one to save cpu cycles?
Im not sure if some processing is repeated twice or can be reused.

@annovif

for blueray content try these two scripts.. localcontrast mask and then the "finesharp" resize of didee.. for my taste it looks much better than using LSF

Didée
9th April 2012, 18:50
Compare to a comparison of two hifi-sets, fairly equal, one has slightly better sound fidelity, one has slightly less fidelity. If you cheat the comparison by upp'ing the volume of the slightly worse one, many people will conclude that the lesser-fidelity set sounds better. Simply because louder sounds better.

It's a similar story here. Sharpening and contrast enhancement do introduce "more energy" into the picture. Usually this is observed as being "better", simply because the picture is getting more "BOOM!".
However, the well-trained eye often can see that enhancement is just that: an enhancement. The picture tends to get this "fat" unsharp-masking look. Some say "woot! Rulez!", others say "oh, the poorness".

The operation of fineSharp can be looked at from two different angles. Basically it is a highpass-sharpener - perform sharpening, but don't use the lower frequencies of the obtained difference. Viewed from another angle, the operation is "energy conservation": perform sharpening, sample the introduced energy, and reduce the (blurred) local energy again, to keep local energy more close to the original. This way you don't get the "BOOM!" into the picture. But it avoids the dreaded "fat" unsharp-masking appearance.

It largely depends on the source characteristics, and it largely depends on personal taste. (And even on your personal "state of the day" - today this may look better, but tomorrow the other one ...) ;)


To recap, the method really was born by the matter of 720p playeback. Many 1080p sources are so that you really can keep almost everything in just 720p. But for playback you need to upsample again, and that's where the problem lies. Even if it's only a faint effect, 720p scaled to 1080p looks like ... something that has been upscaled. That why the three-liner (now FineSharp) did creep into ffdshow's Avisynth tab: make 720p look a little more close to 1080p during playback. Enhance sharpness wile reducing or avoiding the "fattness" introduced by the upsampling.

travolter
9th April 2012, 19:55
This FineSharp is working pretty good.. I have to test it with SD resized to 720.. and probably is so good as applied to 720->1080

Thanks for your explanations ;).. Agree that my "state of the day" varies on each day.. but this way of sharper catched me than the traditional ways of sharp edges.. (aliasing problems when abused is the mainly nightmare in HD content)

GEfS
12th April 2012, 06:27
LSFmod(ss_x=1.5,ss_y=1.5,Smode=3,Smethod=3,Lmode=3,strength=70,overshoot=2,undershoot=1)
I'm using this now. And it's make my m-720p releases looks better.

Gser
12th April 2012, 12:50
FineSharp is just the kind of sharpening I've been looking for.

Didée
12th April 2012, 14:12
I've just added the "ldmp" parameter ("low damp"). It mostly didn't bother me during realtime usage, but upon closer inspection of still snapshots, there really was quite some noise coming up in almost-flat areas.
Default values for "cstr" have been slightly modified too. (Less destructive now for too big sstr values - but you shouldn't go too high with sstr to start with.)

Gser
13th April 2012, 00:23
Now it just stopped working for me. Using newest Avisynth 2.6 MT x86 on win 7 x64.

Didée
13th April 2012, 08:11
Did you change anything else at the same time? The script is structurally unchanged, and works for me. (Though, still running the 2009-09-19 build of 2.6 MT)

Taurus
13th April 2012, 17:17
Now it just stopped working for me. Using newest Avisynth 2.6 MT x86 on win 7 x64.
Works here...
Maybe simple copy and paste error ?:confused::D
Avisynth 2.6 MT x86 WinXP32bit

travolter
13th April 2012, 21:33
thanks for the update Didée. I stopped using local contrast script in favor of FineSharp now

Gser
14th April 2012, 11:41
Works here...
Maybe simple copy and paste error ?:confused::D
Avisynth 2.6 MT x86 WinXP32bit

Yeah probably, works fine now.

handsomejack
17th May 2012, 05:04
I am encoding anime with crf 21.5 for small filesize and use LimitedSharpenFaster + FastLineDarkenMOD.
I wonder if Finesharp have the same effect as LimitedSharpenFaster? Should I change to Finesharp in my situation?
Thanks in advance, I'm no good in this.

malmsteen81
18th June 2012, 08:14
i have a question for Didée. What's the difference between mode=1 and mode=2, i try but i didn't see any difference. And what is the maximum value for sstr before introduce artifcat?

thanks

Andrea

Didée
18th June 2012, 11:45
Generally and technically, the difference is "first gaussian blur, then median filter" (mode 1) -vs.- "fist median filter, then gaussian blur" (mode 2). Due to the either-or nature of median, it changes the behaviour on certain pixel constellations (i.e. extremely fine/thin detail, or e.g. DCT artifacts).

On most sources, the differences between mode 1 and 2 are pretty minute. If you don't see a difference, then it doesn't matter. That simple. :)
___

There is no hard rule when artifacts start to appear. (Speaking strictly, artifacts are introduced already at the weakest notch.);)

Keep in mind that the apparent strength of sharpening, as well as introduction of artifacts, also depend strongly on the "cstr" value. If you want to get more "BOOM" into the picture, you should rather reduce cstr, instead of raising sstr by too much. Also, switching the cstr operation from gaussian-kernel (positive sstr) to box-kernel (negative sstr) can make some gentle difference.

malmsteen81
18th June 2012, 15:07
thanks Didée i will try...
this morning i have tried to set sstr=10 and i made some test with 1080p trailer, with prometeus's trailer looked amazing but with MIB 3 it was crappy. I don't know why because the bitrate is the same but the result was like night and day...

Andrea

Didée
18th June 2012, 15:37
Sure, sstr=10 is insane. The default settings for cstr are adaptive to sstr. Effectively, cstr is "tearing down again" sstr, by applying the reverse of sstr's lowpass. The higher you set sstr, the higher the default cstr-reduction will be. That's why you should rather decrease cstr, instead of increasing sstr.

And again, this filter is meant for realtime playback. Not for encoding. The filter cares a crap about small hi-frequency artifacts on a per-pixel level. During normal watching, you probably won't notice them anyway. The encoder, however, sees each and every darn pixel and has to deal with it.

Boulder
20th June 2012, 17:23
Do you have a similar idea for encoding stuff? From what I've noticed, most 1080p material can safely be downscaled to 720p but the result is a bit softer than the original when rescaled to 1080p on the TV/BD player/Media player. I wouldn't say that there's any actual detail lost in the process with most movies, it's just reduced sharpness.

malmsteen81
22nd June 2012, 11:17
Also, switching the cstr operation from gaussian-kernel (positive sstr) to box-kernel (negative sstr) can make some gentle difference.
do you mean positive or negative "mode" value? right? i tried to reduce cstr to 0.5 but the difference are subtle. the default values are ok for almost cases.

Didée
22nd June 2012, 13:34
Oh, yes, sorry. The switch is build into "mode", not into "sstr". My bad memory.;)

@Boulder:
That's pretty much how I see it. The actual detail loss from 1080p > 720p usually is quite little, and the issue mostly is just edge sharpness when 720p is upscaled during playback. (Given you've made a good 720p rip in the first place, of course.)

Boulder
22nd June 2012, 16:10
That's pretty much how I see it. The actual detail loss from 1080p > 720p usually is quite little, and the issue mostly is just edge sharpness when 720p is upscaled during playback. (Given you've made a good 720p rip in the first place, of course.)So simply using LSFMod with edgemode=1 could actually be a good solution for compensating the difference between the two resolutions? I have used that in some cases but I'm unsure whether there are better alternatives.

Didée
22nd June 2012, 17:46
It's quite feasable, but most likely not optimal. (But frankly: I've almost never really used the given LSFmod function. Somehow I always end up with manual code to sharpen).

After being guilty for the original LimitedSharpen, nowadays I don't like the limiting operation too much anymore. It is somewhat valid for broad edges, but comes with downsides upon thin detail, and risk of uglyness if slight halo'ing is alread pesent. Thinking over it, today I'd rather see working with referencing a gaussian blend (to reduce present edge halos) plus a median cut (both together to "empty" flat areas & weak detail), get an edgemask from that, then use limited sharpening gotten from the gaussian blend on masked edges, and SeeSaw-style impulse sharpening on non-masked areas.

Btw, for downsizing I'm often in favour of "bicubic with negative 'b' ", like e.g. bicubicresize(1280,720,-.5,.25). Neagtive b is hideous for upscaling, but comes very nice for downsizing. New rule: "b + 2c = 1 // for upsizing", and "b + 2c = 0 // for downsizing".

turbojet
15th July 2012, 22:17
Thanks for finesharp, it's the best sharpener I've used. It has much more of an effect then lsf(mod) while still looking natural without adding artifacts, although it emphasizes artifacts in the source. Unfortunately it's really buried in this thread, Didée do you think it deserves it's own thread like most great scripts get?

Also thanks for mentioning negative 'b' parameters in bicubicresize, it's the first time I've seen them mentioned outside of the avisynth wiki which says negative values are undesirable but it also suggests bilinear over bicubic for downsizing. I've settled on (-1,0.75) for encoding.

ryrynz
15th July 2012, 23:50
Yeah, the topic could probably be updated to "Finesharp : The definitive sharpening script for bluray'" :D or given a new thread. It's not everyday Didée spits out a new sharpening script.


Thinking over it, today I'd rather see working with referencing a gaussian blend (to reduce present edge halos) plus a median cut (both together to "empty" flat areas & weak detail), get an edgemask from that, then use limited sharpening gotten from the gaussian blend on masked edges, and SeeSaw-style impulse sharpening on non-masked areas.


Sounds good, I'd like to see it. Could be something that replaces Seesaw & LSF.

Gser
16th July 2012, 17:23
Personally I use ResampleHQ(width=x, height=y, srcmatrix="xyz", kernel="Spline64", chroma_kernel="Spline36") to downsize.

Budtz
16th July 2012, 18:42
Could some1 point me to a guide for making this work?

Adub
17th July 2012, 02:22
Threw FineSharp on the Avisynth wiki, just in case: http://avisynth.org/mediawiki/FineSharp

Sp00kyFox
19th July 2012, 01:44
Thinking over it, today I'd rather see working with referencing a gaussian blend (to reduce present edge halos) plus a median cut (both together to "empty" flat areas & weak detail), get an edgemask from that, then use limited sharpening gotten from the gaussian blend on masked edges, and SeeSaw-style impulse sharpening on non-masked areas.
sounds interesting. is there a implementation already available for this idead or could you post an example script?

gioppatta
6th October 2012, 15:38
Is it usable with a denoiser? what's a good combo?

THX-UltraII
12th October 2012, 12:16
Is there newbie step-by-step guide somewhere that helps me config. this script?

What I already have installed on my HTPC:
- Avisynth 2.5.8
- ffdShow rev.4453 x86 (set as RAW output, needed for SVP frame)
- Microsoft Visual C++ 2008 SP1 MFC Security Update
- MPC-HC 1.6.2.4472
- LAV Filters 0.50.1
- madVR 0.84.2

djmasturbeat
23rd October 2012, 00:19
I keep trying to use this but get the error:
there is no function named "mt_lutxy".

It seems to be that is something from masktools, which I have.
In fact I have tried numerous versions of masktools2, from
incl:
masktools-v2.0a
masktools-v2.0a35
masktools-v2.0a44
masktools-v2.0a48
can someone tell me which version to use specifically (if it matters)
and if that isn't the issue, please, will someone help me out. This looks like a promising tool, but this seems to be some strange error people get randomly with different scripts, and all people usually say is to "have masktools" (which not so helpful with so many builds, and less helpful if people do have mt2).

Bloax
23rd October 2012, 04:54
Well that's strange, because it definitely works with a48.

Might be another case of Avisynth bugging out hard with plugin loading, because I have witnessed that before. (The solution being long forgotten also.)

djmasturbeat
23rd October 2012, 05:40
I guess I can try a fresh install of Avisynth
may be I screwed smth up in there, but otherwise I don't get a lot of errors in AVSPm,
I am not too experienced of an encoder nor with filters and avs, so generally I use very few filters to minimize self-inflicted wounds, tho I do on occasion try some out (mostly in testing and tinkering, as I am not experienced enough to know what all the settings are in some of these big mega avsi files).

I guess I will see what happens from fresh avs install, and me backing up scripts and plugins elsewhere.

@mFY
23rd October 2012, 06:55
how do I use it?it has dll?

Didée
23rd October 2012, 07:09
@ djmasturbeat: You're sure to use the correct masktools-dll for your Avisynth version?

Avisynth v2.5.8 --> mt_masktools-25.dll
Avisynth v2.6 ----> mt_masktools-26.dll

The issue of "there is no function named XYZ" is known to appear when the -26.dll is loaded under Avisynth 2.5.8.

jmac698
23rd October 2012, 13:24
Didee, in the german board you posted some years ago shots of VHS, one was a young woman in a uniform, another had train tracks.. but it looked amazingly sharper. What sharpening script was that? I thought it was a miracle :)

Didée
23rd October 2012, 15:15
If it was years ago, then maybe it was the iiP dinosaur. But I really can't remember what pictures you're talking about.

Selur
25th October 2012, 07:50
I think those were images in the context where everyone experimented with oversharpening and BlindDeHalo but to be frank I'm not sure either,... :)

jmac698
25th October 2012, 13:33
Yeah I know it's hard to identify, I'm searching for the pictures but my files are a bit ... disorganized :)

THX-UltraII
1st November 2012, 20:13
Isn t there really nobody who can provide me with a step by step guide how to config Finesharp?

I m using MPC-HC with madVR renderer and LAV Audio & Video filter.

turbojet
2nd November 2012, 06:46
If you are talking about tweaking finesharp I found the defaults to be the best for my eyes but I only spent about 30 minutes tweaking.

If you are talking about setting it up to be used during playback:

- install ffdshow
- configure ffdshow to decode the video (if using a different decoder set ffdshow to decode raw video)
- get avisynth 2.6 mt dll and put it in ffdshow directory
- in mpc-hc external filters page, add ffdshow, set to prefer, and move it to the top or just below the preferred decoder
- go to avisynth page in ffdshow and uncheck 'add ffdshow video source'
- set buffer back/ahead to 0 back/4-20 ahead (I buffer 6 ahead)
- paste this into the avisynth page of ffdshow
setmemorymax(64)
SetMTMode(2)
ffdshow_source()
FineSharp()
SetMTMode(1)
GetMTMode(false) > 0 ? distributor() : last

THX-UltraII
2nd November 2012, 09:00
This was exactly what I was looking for. Thanks a lot!

If you are talking about tweaking finesharp I found the defaults to be the best for my eyes but I only spent about 30 minutes tweaking.I ll try the default setting first.

If you are talking about setting it up to be used during playbackYes, want real-time playback config.

install ffdshowhttp://sourceforge.net/projects/ffdshow-tryout/
This version?

configure ffdshow to decode the video (if using a different decoder set ffdshow to decode raw video)I use LAV Video decoder so I ll set the RAW filter in MPC-HC as prefered filter and set input to 'all supported' correct?

go to avisynth page in ffdshow and uncheck 'add ffdshow video source'CHECK! (I m @work now but I ll try it tonight)

get avisynth 2.6 mt dll and put it in ffdshow directoryWhere can I get this file? Can t find it with Google :stupid:

set buffer back/ahead to 0 back/4-20 ahead (I buffer 6 ahead)I have a pretty fast CPU (i7 2600K oced@5Ghz). Do you also recommend this '0 back/4-20 ahead' for my CPU?

setmemorymax(64)
SetMTMode(2)
ffdshow_source()
FineSharp()
SetMTMode(1)
GetMTMode(false) > 0 ? distributor() : lastSo I just past this into the Avisyth page in ffdshow? On the posting of Didee (http://forum.doom9.org/showpost.php?p=1569035&postcount=2) I see another (extended) script not? And Didee also says ''Required plugins: MaskTools, RemoveGrain, Repair''. Don t I need to download these plugins and install them?

Bloax
2nd November 2012, 15:48
You do, and you need MaskTools2. (And if you by some miracle didn't know already, "installing" plugins is dumping them into the plugins directory.)

THX-UltraII
2nd November 2012, 16:46
MaskTools2
I found this download link at the top right of this page http://avisynth.org/mediawiki/MaskTools2. There are 4 .dll files in the extracted main folder:
'mt_masktools-25.dll'
'mt_masktools-25-x64.dll'
'mt_masktools-26.dll'
'mt_masktools-26-x64.dll'
Which of these do I copy paste in ?? directory?

RemoveGrain
Do I use this http://avisynth.org/mediawiki/Removegrain site and 'v1.0 pre-release' download?

Repair
Can t find this one......

avisynth 2.6 mt dll
Can t find this one either......

turbojet
5th November 2012, 23:30
mt_masktools-26.dll is the one you want, place in avisynth\plugins directory, 25 means avisynth 2.5x, 26= 2.60

I use the pre-release with sse3 fix of removegrain, repair is also included

2.6 mt (http://forum.doom9.org/showthread.php?t=148782)

hdboy
6th November 2012, 01:35
How can I get it to process only the right half of the image so I can more easily see what effect it is having? The option in ffdshow is disabled (cannot be checked). Thanks.

djmasturbeat
6th November 2012, 03:29
Btw, for downsizing I'm often in favour of "bicubic with negative 'b' ", like e.g. bicubicresize(1280,720,-.5,.25). Neagtive b is hideous for upscaling, but comes very nice for downsizing. New rule: "b + 2c = 1 // for upsizing", and "b + 2c = 0 // for downsizing".


can you explain this equation better for a noob like me, please? :)
specifically:
what are b and c (what do they represent)?

If the answer above doesn't touch upon this, I also want to know: If I downscale from 1080p to 480p or 540p, is this equation the same as if just scaling down to 720?

thanks for all the expert advice :)