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 Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 1st August 2015, 07:30   #1  |  Link
ryrynz
Registered User
 
ryrynz's Avatar
 
Join Date: Mar 2009
Posts: 3,645
Psharpen using Masktools 2

Can Psharpen be updated to use the latest Masktools 2?
I assume it'd be a fairly quick task changing a few functions etc.

Last edited by ryrynz; 5th March 2016 at 04:59. Reason: fix link
ryrynz is offline   Reply With Quote
Old 1st August 2015, 19:13   #2  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
The conversion is pretty straightforward; all you need to do is to replace inpand/expand with mt_inpand/mt_expand, yv12subtract with mt_makediff, and yv12lutxy with mt_lutxy.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 2nd August 2015, 02:49   #3  |  Link
ryrynz
Registered User
 
ryrynz's Avatar
 
Join Date: Mar 2009
Posts: 3,645
Quote:
Originally Posted by colours View Post
The conversion is pretty straightforward; all you need to do is to replace inpand/expand with mt_inpand/mt_expand, yv12subtract with mt_makediff, and yv12lutxy with mt_lutxy.
Thanks. I did the inpand and expand changes but got stuck on the yv12subtract. Does the command itself stay the same? ie do I simply just cut and paste yv12subtract with mt_makediff?
ryrynz is offline   Reply With Quote
Old 2nd August 2015, 07:42   #4  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
I just checked the MaskTools v1 docs (probably should've done this before writing the first post) and apparently that's not quite right. (Four different calculation modes depending on the options?! v1 is pure insanity.)

Code:
function pSharpen   (clip clp,
                    \int "strength", int "threshold",
                    \float "ss_x", float "ss_y",
                    \int "dest_x", int "dest_y")
{
    # getting the input image size
    ox = clp.width()
    oy = clp.height()

    # parsing the input values
    strength = default(strength, 25)
    threshold = default(threshold, 75)
    ss_x = default(ss_x, 1.0)
    ss_y = default(ss_y, 1.0)
    dest_x = default(dest_x, ox)
    dest_y = default(dest_y, oy)

    strength = strength<0 ? 0 : strength>100 ? 100 : strength
    threshold = threshold<0 ? 0 : threshold>100 ? 100 : threshold
    ss_x = ss_x<1.0 ? 1.0 : ss_x
    ss_y = ss_y<1.0 ? 1.0 : ss_y

    # oversampling
    val =   ss_x!=1.0 || ss_y!=1.0 ?
            \clp.lanczosresize(round(ox*ss_x/8)*8,round(oy*ss_y/8)*8) :
            \clp

    # calculating the max and min in every 3*3 square
    max = val.mt_expand()
    min = val.mt_inpand()

    # normalizing max and val to values from 0 to (max-min)
    nmax = average(max, 1, min, -1)
    nval = average(val, 1, min, -1)

    # initializing the strings used to obtain the output luma value
    s = string(strength/100.0)
    t = string(threshold/100.0)
    x0 = string((threshold/100.0)*(1.0-strength/100.0)/(1.0-(1.0-threshold/100.0)*(1.0-strength/100.0)))
    expr = \
        "x y / 2 * 1 - abs "+x0+" < "                   +\
            s+" 1 = "                                   +\
                "x y 2 / = 0 y 2 / ? "                  +\
                "x y / 2 * 1 - abs 1 "+s+" - / "        +\
            "? "                                        +\
            "x y / 2 * 1 - abs 1 "+t+" - * "+t+" + "    +\
        "? "                                            +\
        "x y 2 / > 1 -1 ? * 1 + y * 2 /"

    # calculates the new luma value pushing it towards min or max
    nval = mt_lutxy(nval, nmax, expr)

    # normalizing val to values from min to max
    val = average(nval, 1, min, 1)

    # applying the new luma value to the original clip &
    # resizing the image to the output values
    val = val.lanczosresize(dest_x, dest_y)
    clp = clp.lanczosresize(dest_x, dest_y).mergeluma(val)

    return clp
}
You'll need the Average plugin for this.

Edit (2016-03-07): changed dest_x/dest_y to be ints instead of floats.
Edit (2016-03-16): actually make it work when ss_x and ss_y are not both 1, because I broke the script when I originally ported it.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!

Last edited by colours; 16th March 2016 at 11:25.
colours is offline   Reply With Quote
Old 9th August 2015, 13:59   #5  |  Link
ryrynz
Registered User
 
ryrynz's Avatar
 
Join Date: Mar 2009
Posts: 3,645
Working a treat, thank you very much!
ryrynz is offline   Reply With Quote
Old 1st March 2016, 06:12   #6  |  Link
Disturbance
Registered User
 
Join Date: Mar 2007
Posts: 26
Hi, I am trying to use the updated Masktools2 version on Win10, and I get this error when I try to use it in a script "

pSharpen(strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=1.0, dest_y=1.0)

Script error: Invalid arguments to function 'lanczosresize'.
(C:/Program Files (x86)/AviSynth+/plugins64/pSharpen.avsi, line 60)
(D:\Downloads\Clip Output\Clip.avs, line 5)"

Line 60 being " clp = ss_x!=1.0 || ss_y!=1.0 || dest_x!=ox || dest_y!=oy ? clp.lanczosresize(dest_x,dest_y) : clp"
Line 5 being "pSharpen(strength=25, threshold=75, ss_x=1.0, ss_y=1.0, dest_x=1.0, dest_y=1.0)"

any thoughts on what could be causing that?
Disturbance is offline   Reply With Quote
Old 1st March 2016, 08:36   #7  |  Link
Disturbance
Registered User
 
Join Date: Mar 2007
Posts: 26
Quote:
Originally Posted by HolyWu View Post
The width and height arguments of *Resize must be integer for obvious reason. So it's mysterious why dest_x and dest_y are declared as float type. It's also mysterious why you want the final result be resized to 1x1 size.
it was the example given on the "http://avisynth.nl/index.php/PSharpen" wiki for it, so that is what I tried to use ("pSharpen with default settings:"). The line 60 was from the avsi script.

Ok so just changing it to pSharpen() in the script at least lets it load. Just seems the example usage of the script should have added a bit of clarity to the line stating that the Dest_x+y should be the final video size. Thanks for pointing me in the right direction
Disturbance is offline   Reply With Quote
Old 1st March 2016, 14:56   #8  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Disturbance View Post
Just seems the example usage of the script should have added a bit of clarity to the line stating that the Dest_x+y should be the final video size.
The wiki page does say that dest_x and dest_y give the final image size.
However, it wrongly says they default to 1.0 - the defaults are the original input dimensions (see the code in post #4 above).

Like HolyWu, I am puzzled about them being declared as float, when they must be integers for the function to work properly.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino is offline   Reply With Quote
Old 1st March 2016, 15:09   #9  |  Link
Reel.Deel
Registered User
 
Join Date: Mar 2012
Location: Texas
Posts: 1,664
Quote:
Originally Posted by Gavino View Post
The wiki page does say that dest_x and dest_y give the final image size.
However, it wrongly says they default to 1.0 - the defaults are the original input dimensions (see the code in post #4 above).
Fixed the wiki page. Thanks for pointing that out.
Reel.Deel is offline   Reply With Quote
Old 7th March 2016, 10:13   #10  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
Quote:
Originally Posted by Gavino View Post
Like HolyWu, I am puzzled about them being declared as float, when they must be integers for the function to work properly.
Fixed.

(I do not claim authorship over this script and will not be offering further fixes/changes for it.)
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 8th March 2016, 12:06   #11  |  Link
Selur
Registered User
 
Selur's Avatar
 
Join Date: Oct 2001
Location: Germany
Posts: 7,255
btw. using 'pSharpen(ss_x=2.00,ss_y=2.00)' causes a 'MergeLuma: Images must have same width and height!'-error
adding clp=val in line 26 at the end of the oversampling part seems to fix it:
Code:
function pSharpen   (clip clp,
                    \int "strength", int "threshold",
                    \float "ss_x", float "ss_y",
                    \int "dest_x", int "dest_y")
{
    # getting the input image size
    ox = clp.width()
    oy = clp.height()
    
    # parsing the input values
    strength = default(strength, 25)
    threshold = default(threshold, 75)
    ss_x = default(ss_x, 1.0)
    ss_y = default(ss_y, 1.0)
    dest_x = default(dest_x, ox)
    dest_y = default(dest_y, oy)
    
    strength = strength<0? 0 : strength>100? 100 : strength
    threshold = threshold<0? 0 : threshold>100? 100 : threshold
    ss_x = ss_x<1.0? 1.0 : ss_x
    ss_y = ss_y<1.0? 1.0 : ss_y
    
    # oversampling
    val =   ss_x!=1.0 || ss_y!=1.0 ?
            \clp.lanczosresize(round(ox*ss_x/8)*8,round(oy*ss_y/8)*8) :
            \clp
    clp=val

    # calculating the max and min in every 3*3 square
    max = val.mt_expand()
    min = val.mt_inpand()
    
    # normalizing max and val to values from 0 to (max-min)
    nmax = average(max,1,min,-1)
    nval = average(val,1,min,-1)
    
    # initializing the strings used to obtain the output luma value
    s = string(strength/100.0)
    t = string(threshold/100.0)
    x0 = string((threshold/100.0)*(1.0-strength/100.0)/(1.0-(1.0-threshold/100.0)*(1.0-strength/100.0)))
    expr = \
        "x y / 2 * 1 - abs "+x0+" < "                   +\
            s+" 1 = "                                   +\
                "x y 2 / = 0 y 2 / ? "                  +\
                "x y / 2 * 1 - abs 1 "+s+" - / "        +\
            "? "                                        +\
            "x y / 2 * 1 - abs 1 "+t+" - * "+t+" + "    +\
        "? "                                            +\
        "x y 2 / > 1 -1 ? * 1 + y * 2 /"
    
    # calculates the new luma value pushing it towards min or max
    nval = mt_lutxy(nval,nmax,expr)
    
    # normalizing val to values from min to max
    val = average(nval,1,min,1)
    
    # applying the new luma value to the original clip
    clp = clp.mergeluma(val)
    
    # resizing the image to the output values
    clp = ss_x!=1.0 || ss_y!=1.0 || dest_x!=ox || dest_y!=oy ? clp.lanczosresize(dest_x,dest_y) : clp
    
    return clp
}
__________________
Hybrid here in the forum, homepage

Last edited by Selur; 8th March 2016 at 12:09.
Selur is offline   Reply With Quote
Old 8th March 2016, 20:12   #12  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
This may behave differently in v2.58 and v2.6 (2.6 enforces eg conversion client supplied ss_x as int to type float, v2.58 will evaluate as int).

Code:
    ss_x = default(ss_x, 1.0)
    ss_y = default(ss_y, 1.0)
Code:
    ss_x = Float(default(ss_x, 1.0))
    ss_y = Float(default(ss_y, 1.0))
would make 2.58 and v2.6 behave the same.

EDIT: Whether the rest of the function behaves ok, I have no idea (I dont want to look at it any further).
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???

Last edited by StainlessS; 8th March 2016 at 20:26.
StainlessS is offline   Reply With Quote
Old 16th March 2016, 11:30   #13  |  Link
colours
Registered User
 
colours's Avatar
 
Join Date: Mar 2014
Posts: 308
Quote:
Originally Posted by Selur View Post
btw. using 'pSharpen(ss_x=2.00,ss_y=2.00)' causes a 'MergeLuma: Images must have same width and height!'-error
adding clp=val in line 26 at the end of the oversampling part seems to fix it
Fixed, because this was a bug I introduced while porting that seemingly no one ever noticed.

StainlessS: Nobody should still be using 2.5.8 or any earlier version when upgrading is as simple as stuffing a newer DLL in system32/syswow64. Don't suggest nonsolutions to nonproblems.
__________________
Say no to AviSynth 2.5.8 and DirectShowSource!
colours is offline   Reply With Quote
Old 16th March 2016, 11:35   #14  |  Link
StainlessS
HeartlessS Usurer
 
StainlessS's Avatar
 
Join Date: Dec 2009
Location: Over the rainbow
Posts: 10,980
Quote:
Originally Posted by colours View Post
Nobody should still be using 2.5.8
Yeh well tell that to the people that are still using v2.57. (there are some)
__________________
I sometimes post sober.
StainlessS@MediaFire ::: AND/OR ::: StainlessS@SendSpace

"Some infinities are bigger than other infinities", but how many of them are infinitely bigger ???
StainlessS 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 05:28.


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