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.

 

Go Back   Doom9's Forum > Capturing and Editing Video > Avisynth Usage

Reply
 
Thread Tools Search this Thread Display Modes
Old 8th April 2012, 03:01   #1  |  Link
nibus
Telewhining
 
Join Date: Mar 2010
Posts: 275
FineSharp()

Didée, how would I go about making a nice .avsi out of that script so I could call it like

Code:
FineSharpen()
?

Sorry I have no scripting knowledge
nibus is offline   Reply With Quote
Old 8th April 2012, 13:04   #2  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
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.

Code:
# 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
__________________
- 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!)

Last edited by Didée; 12th April 2012 at 14:07.
Didée is offline   Reply With Quote
Old 8th April 2012, 15:09   #3  |  Link
TheSkiller
Registered User
 
Join Date: Dec 2007
Location: Germany
Posts: 637
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.
TheSkiller is offline   Reply With Quote
Old 9th April 2012, 15:54   #4  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
@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 is offline   Reply With Quote
Old 9th April 2012, 17:16   #5  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
@didée

Im testing the "finesharp" script and the result is very similar to this old script that you posted and I continue using
Code:
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
Code:
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

Last edited by travolter; 9th April 2012 at 17:20.
travolter is offline   Reply With Quote
Old 9th April 2012, 18:50   #6  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
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.
__________________
- 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!)
Didée is offline   Reply With Quote
Old 9th April 2012, 19:55   #7  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
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)
travolter is offline   Reply With Quote
Old 12th April 2012, 06:27   #8  |  Link
GEfS
Registered User
 
Join Date: Aug 2011
Posts: 19
Code:
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.
GEfS is offline   Reply With Quote
Old 12th April 2012, 12:50   #9  |  Link
Gser
Registered User
 
Join Date: Apr 2008
Posts: 367
FineSharp is just the kind of sharpening I've been looking for.
Gser is offline   Reply With Quote
Old 12th April 2012, 14:12   #10  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
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.)
__________________
- 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!)
Didée is offline   Reply With Quote
Old 13th April 2012, 00:23   #11  |  Link
Gser
Registered User
 
Join Date: Apr 2008
Posts: 367
Now it just stopped working for me. Using newest Avisynth 2.6 MT x86 on win 7 x64.
Gser is offline   Reply With Quote
Old 13th April 2012, 08:11   #12  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
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)
__________________
- 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!)
Didée is offline   Reply With Quote
Old 13th April 2012, 17:17   #13  |  Link
Taurus
Registered User
 
Taurus's Avatar
 
Join Date: Mar 2002
Location: Krautland
Posts: 809
Quote:
Originally Posted by Gser View Post
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 ?
Avisynth 2.6 MT x86 WinXP32bit
Taurus is offline   Reply With Quote
Old 13th April 2012, 21:33   #14  |  Link
travolter
Registered User
 
Join Date: Apr 2009
Posts: 136
thanks for the update Didée. I stopped using local contrast script in favor of FineSharp now
travolter is offline   Reply With Quote
Old 14th April 2012, 11:41   #15  |  Link
Gser
Registered User
 
Join Date: Apr 2008
Posts: 367
Quote:
Originally Posted by Taurus View Post
Works here...
Maybe simple copy and paste error ?
Avisynth 2.6 MT x86 WinXP32bit
Yeah probably, works fine now.
Gser is offline   Reply With Quote
Old 17th May 2012, 05:04   #16  |  Link
handsomejack
Registered User
 
Join Date: Jun 2009
Posts: 13
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.
handsomejack is offline   Reply With Quote
Old 18th June 2012, 08:14   #17  |  Link
malmsteen81
Registered User
 
Join Date: May 2012
Posts: 15
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
malmsteen81 is offline   Reply With Quote
Old 18th June 2012, 11:45   #18  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
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.
__________________
- 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!)
Didée is offline   Reply With Quote
Old 18th June 2012, 15:07   #19  |  Link
malmsteen81
Registered User
 
Join Date: May 2012
Posts: 15
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
malmsteen81 is offline   Reply With Quote
Old 18th June 2012, 15:37   #20  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
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.
__________________
- 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!)
Didée is offline   Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 04:41.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2018, vBulletin Solutions Inc.