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 22nd July 2010, 14:14   #41  |  Link
Archimedes
Registered User
 
Join Date: Apr 2005
Posts: 213
I've changed the posted function santiag a little bit.

Santiag has now three parameters: type, strh and strv. Type means the anti aliasing type. Possible values are "EEDI3", "NNEDI2" and "NNEDI3". strh is the strength for the horizontal anti aliasing and strv is the strength for the vertical anti aliasing. Default values are: type="nnedi3", strh=1 and strv=1.

Contrary to the first posted function, santiag(strh=0, strv=0) now means no anti aliasing. I've also corected the center shift. With NNEDI3 as type, the center shift now works correct for all possible input clips (YV12, YUY2 and RGB24).

Requirements:
Code:
LoadPlugin("plugins\EEDI3\eedi3.dll")
LoadPlugin("plugins\GScript\GScript.dll")
LoadPlugin("plugins\NNEDI2\nnedi2.dll")
LoadPlugin("plugins\NNEDI3\nnedi3.dll")
Code:
function SantiagMod(clip input, string "type", int "strh", int "strv") {
  type = Default(type, "NNEDI3")
  strh = Default(strh, 1)
  strv = Default(strv, 1)

  input

  strh > 0 ? AntiAliasing(type=type, strength=strh) : NOP()
  TurnLeft()
  strv > 0 ? AntiAliasing(type=type, strength=strv) : NOP()
  TurnRight()

  function AntiAliasing(clip input, string "type", int "strength") {
    input

    GScript("""
      if (type == "EEDI3") {
        EEDI3(dh=True, field=0)
        for (i = 2, strength) {
          EEDI3(dh=False, field=(i + 1) % 2)
        }
      }
      else if (type == "NNEDI2") {
        NNEDI2(dh=True, field=0)
        for (i = 2, strength) {
          NNEDI2(dh=False, field=(i + 1) % 2)
        }
      }
      else {
        NNEDI3(dh=True, field=0)
        for (i = 2, strength) {
          NNEDI3(dh=False, field=(i + 1) % 2)
        }
      }
    """)

    Spline36Resize(input.Width(), input.Height(), 0, 0.5, input.Width(), input.Height() * 2)
  }
}
Quote:
Originally Posted by Gavino View Post
Also it looks to me that strh and strv are the wrong way round - strh affects vertical and strv horizontal.
For me, it looks correct.

Source:


santiag(strh=2, strv=0):


santiag(strh=0, strv=2):

Last edited by Archimedes; 22nd July 2010 at 22:14.
Archimedes is offline   Reply With Quote
Old 22nd July 2010, 18:08   #42  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Archimedes View Post
For me, it [ie strh, strv] looks correct.
OK, I understand your terminology now.
I was confused because I saw that strh affected vertical resampling and strv horizontal resampling. However, by horizontal anti-aliasing, I think you mean fix (near-)horizontal lines, which requires vertical resampling, and vice versa. Correct?

The code can actually be simplified a bit. The Evals are redundant and, since string comparison is case insensitive, there is no need to convert the type string to upper case. In santiag_dir and santiag_stronger, 'type' and 'strength' should not really be in quotes, since they are not optional parameters there.

For example, santiag_stronger could be rewritten (according to taste) as
Code:
function santiag_stronger(clip c, string type, int strength) {
  c

  type == "EEDI3" ?
\   (strength <= 1) ? EEDI3(dh=true, field=0) : santiag_stronger(type=type, strength=strength - 1).EEDI3(dh=false, field=(strength + 1) % 2)
\ :
\ type == "NNEDI2" ?
\   (strength <= 1) ? NNEDI2(dh=true, field=0) : santiag_stronger(type=type, strength=strength - 1).NNEDI2(dh=false, field=(strength + 1) % 2)
\ :
\ type == "NNEDI3" ?
\   (strength <= 1) ? NNEDI3(dh=true, field=0) : santiag_stronger(type=type, strength=strength - 1).NNEDI3(dh=false, field=(strength + 1) % 2)
\ : NOP()

  last
}
Gavino is offline   Reply With Quote
Old 22nd July 2010, 22:24   #43  |  Link
Archimedes
Registered User
 
Join Date: Apr 2005
Posts: 213
Quote:
Originally Posted by Gavino View Post
I was confused because I saw that strh affected vertical resampling and strv horizontal resampling. However, by horizontal anti-aliasing, I think you mean fix (near-)horizontal lines, which requires vertical resampling, and vice versa. Correct?
Yes.

In the meanwhile, I have changed the function again. Now it is an iterative (non recursive) function, called "SantiagMod". It is easier to unterstand than the recursive function. This version looks also more pleasant to me.

Last edited by Archimedes; 23rd July 2010 at 10:58.
Archimedes is offline   Reply With Quote
Old 1st August 2010, 05:04   #44  |  Link
Heaud
Registered User
 
Join Date: Apr 2008
Posts: 58
Is there any documentation on aaf()? I want to know what each value does before I start tweaking some settings.
Heaud is offline   Reply With Quote
Old 27th August 2010, 00:03   #45  |  Link
markanini
Registered User
 
Join Date: Apr 2006
Posts: 299
^^+1!

BTW Results with aaf() look good and it runs in realtime on my machine, so please tell us more about it.
markanini is offline   Reply With Quote
Old 28th August 2010, 10:15   #46  |  Link
Mystery Keeper
Beyond Kawaii
 
Mystery Keeper's Avatar
 
Join Date: Feb 2008
Location: Russia
Posts: 724
I'm glad that script we assembled is still being improved. But let me remind you the original idea behind it.

I needed a script that would:
  • Anitalias anime. Resulting script did marverls on anime, but looked weird on real video. See why below.
  • Only work on edges and lines. For that I spent some time searching for a good mask. Don't remember what script I took it out from, but it was quite unique and much better than usual Sobel. Now anime contains a lot of contrasting edges and lines. Real video doesn't contain as much. It is unpredictable, which part is affected by script in each frame.
  • Make lines thiner and finer. For that warpsharp is used. I see no reason to use it on real video.
  • Darken the lines, so they are still visible after everything done on them. Again, why would someone do that on real video?
  • Do some postsharpening. That just needed to be done. Unrelated to video type.
  • Soothe lines shaking. In some anime horisontal scene moving introduces vertical lines shaking. The script we had so far made that shaking much more noticable. That's where motion compensation is used for soothing (great thanks, Didee!) Never seen vertical lines shaking in real video.
So you guys testing it on real video is confusing to me. Is new script tuned for it? Got to test it for anime and see if settings are good for it.

Now what the hell with all the interpolators? I used to use EEDI2 for antialiasing real video. Really smoothes some lines, but also blures the picture. In this script Sangnom did just as good as EEDI2, worked twice as fast and didn't introduce a shift like EEDI2 does. So I just threw EEDI2 out of it, it really wasn't needed. But in your script I see all kind of edge-directed interpolators. Apart from EEDI2 they are all quite sharp. They don't do any antialiasing at all. Look at the small AA functions you use. They all use Sangnom. I suggest you take out EDIs from your script at least for the sake of stopping confusing newcomers, making them think that EDIs are good for antialiasing.
__________________
...desu!
Mystery Keeper is offline   Reply With Quote
Old 6th December 2011, 22:40   #47  |  Link
Leinad4Mind
Please, DeInterlace me!
 
Leinad4Mind's Avatar
 
Join Date: Jan 2007
Location: Portugal, Porto
Posts: 81
I've share the last version of it. Topic updated! I'll in the future try to update more, and do some new stuff.

Cheers
__________________
Who am I?! I'm GOD... 8for it... father of my godchilds.
Leinad4Mind is offline   Reply With Quote
Old 1st January 2012, 10:14   #48  |  Link
Edge343
Registered User
 
Join Date: Dec 2011
Posts: 4
I've been trying to add AA to screenshots/videos from an old XBox game, and though LSharpAAF certainly makes things easier I could still use some help in getting good results. The XBox game in question is called Panzer Dragoon Orta, and I'm currently running it from an Xbox360 (the Xbox360 is capable of emulating certain original Xbox games, this is one of them). I'm capturing the game over HDMI in 720P, and I assume the XBox360 is simply upscaling the image since the original game didn't run in HD resolutions. So basically this is what I'm getting:

Screenshot 1
Screenshot 2

From what I've tried on these images LSharpAAF(aatype="eedi3") seems to deliver the best results:

Screenshot 1 - EEDI3
Screenshot 2 - EEDI3

But given how little I know about all these AA methods being used I though someone here might be able to help me get better results. Any help would be appreciated.
Edge343 is offline   Reply With Quote
Old 1st January 2012, 13:31   #49  |  Link
Bloax
The speed of stupid
 
Bloax's Avatar
 
Join Date: Sep 2011
Posts: 317
Does the whole game look like that?
If so, let me cook something alternate up.

Meanwhile:
Code:
TurnRight()
Merge(SangNom(0,255).SangNom(1,255),Merge(SangNom(1,255),SangNom(0,255),0.5),0.25)
TurnLeft()
Seems to look "alright".

Edit: And if that's how it looks, here's another:
Code:
PointResize(Width/2,Height/2)
TurnRight()
Merge(SangNom(0,255),SangNom(1,255),0.5)
TurnLeft()
NNEDI3_rpow2(2,0,0,1).SangNom(0,255)
Which looks less messy.

Last edited by Bloax; 1st January 2012 at 13:35.
Bloax is offline   Reply With Quote
Old 1st January 2012, 17:15   #50  |  Link
Edge343
Registered User
 
Join Date: Dec 2011
Posts: 4
Thanks Bloax. This is basically how the game looks yes, although I uploaded some actual gameplay footage here.

The second script does seem to deal with the aliasing nicely, although it also softens the image more, which I understand is somewhat inevitable when adding anti-aliasing. Here's a comparison, from left to right is the original, LSharpAAF(aatype=eedi3), your first and then second script. I didn't notice it at first but eedi3 does something weird to the background as well. The last script seems to lose a bit more detail than I'd like. An unfortunate side-effect is also that the game has subtitles at some points and your two scripts seem to add artifacts to those...
Edge343 is offline   Reply With Quote
Old 1st January 2012, 17:49   #51  |  Link
Bloax
The speed of stupid
 
Bloax's Avatar
 
Join Date: Sep 2011
Posts: 317
The big blurring I'd guess comes from NNEDI3, since it's rather soft.
As for subtitles, it'd be nice with a picture to mess around with.
Bloax is offline   Reply With Quote
Old 1st January 2012, 17:57   #52  |  Link
Edge343
Registered User
 
Join Date: Dec 2011
Posts: 4
Quote:
Originally Posted by Bloax View Post
The big blurring I'd guess comes from NNEDI3, since it's rather soft.
As for subtitles, it'd be nice with a picture to mess around with.
Here's an example. There's also one in the video I linked to.
Edge343 is offline   Reply With Quote
Old 1st January 2012, 18:21   #53  |  Link
Bloax
The speed of stupid
 
Bloax's Avatar
 
Join Date: Sep 2011
Posts: 317
This script really is only "usable" for this. Which is aliased and upscaled stuff.
Anything else, and it wrecks it. No exaggeration.


I think it's a bit overkill by now. (Way, way overkill - to be exact.) ;P
Edit: Updated to look cool now.
Code:
orig = last
msk=RAverageW(last,32,last.RemoveGrain(19,-1),-32,u=0,v=0,sse=8,bias=-255).RemoveGrain(4,-1).Mt_Deflate()
PointResize(Width/2,Height/2)
NNEDI3(0,true,true,true,true,0,0,1).PointResize(Width,Height)
TurnLeft()
Merge(SangNom(1,30),SangNom(0,30),0.5)
TurnRight()
NNEDI3_rpow2(2,0,0,1)
TurnRight().SangNom(0,64).TurnLeft()
RMerge(last,orig,msk)
RemoveGrain(2) # Fixing up stuff
In my little opinion, I think it'd be best just to do this:
Code:
PointResize(Width/2,Height/2)
TurnLeft()
Merge(SangNom(1,30),SangNom(0,30),0.5)
TurnRight()
And call it a day.
Hm, actually. Let me see if I can fix it up. (Seems like parameter overkill.)

Edit: Woop! Be careful with them SangNom settings kids, they're daaangerous.
Anyways, fixed to look like a cool inflation-antialias instead of the uncool holey mess it was.

Last edited by Bloax; 1st January 2012 at 18:40.
Bloax is offline   Reply With Quote
Old 1st January 2012, 19:22   #54  |  Link
Edge343
Registered User
 
Join Date: Dec 2011
Posts: 4
Thanks Bloax, I have no idea what the first script does but the results seem to look good I'll try and compare it to the second one to see if the difference is worth it. I'd probably be better off capturing in 480P to begin with which I think would avoid the upscaling, but unfortunately my capture card can't capture the 480P output from the XBox360 (which I believe is 640x480).
Edge343 is offline   Reply With Quote
Old 1st February 2012, 13:43   #55  |  Link
kentafilo
Registered User
 
Join Date: Dec 2004
Posts: 13
Quote:
Originally Posted by Leinad4Mind View Post

Here is all the require dll or extra functions: http://www.megaupload.com/?d=HQ7NLMW0
Help me:magaupload is down
kentafilo is offline   Reply With Quote
Old 1st February 2012, 14:29   #56  |  Link
librarian
Registered User
 
Join Date: Nov 2011
Posts: 63
See here. Archive downloaded on December 23rd 2011.
librarian is offline   Reply With Quote
Old 8th February 2013, 08:26   #57  |  Link
x265
Registered User
 
Join Date: Oct 2012
Posts: 176
Which aatype should i use for anime?
x265 is offline   Reply With Quote
Old 10th February 2013, 21:14   #58  |  Link
GodRealm
Registered User
 
Join Date: Sep 2012
Posts: 13
Quote:
Originally Posted by librarian View Post
See here. Archive downloaded on December 23rd 2011.
Link is off.
GodRealm is offline   Reply With Quote
Old 4th April 2015, 18:28   #59  |  Link
Overdrive80
Anime addict
 
Overdrive80's Avatar
 
Join Date: Feb 2009
Location: Spain
Posts: 673
Hi, using mod by Dogway I have updated this filter: https://dl.dropboxusercontent.com/u/...arpAAF2.00.zip

Updates:
  • Remove LimitedSharpenFaster dependency
  • Remove Sangnom and Turn dependency
  • Added Sangnom2 and FTurn
  • Added maa2, Santiag and Sangnom2AA

Dependencies:
Attached Files
File Type: zip LSharpAAF2.00.zip (8.3 KB, 130 views)
__________________
Intel i7-6700K + Noctua NH-D15 + Z170A XPower G. Titanium + Kingston HyperX Savage DDR4 2x8GB + Radeon RX580 8GB DDR5 + ADATA SX8200 Pro 1 TB + Antec EDG750 80 Plus Gold Mod + Corsair 780T Graphite

Last edited by Overdrive80; 9th April 2015 at 01:20.
Overdrive80 is offline   Reply With Quote
Old 8th April 2015, 21:43   #60  |  Link
Great Dragon
Registered User
 
Great Dragon's Avatar
 
Join Date: Feb 2005
Location: Ukraine, Lviv
Posts: 121
@Overdrive80
LSharpAAF(aatype="maa2") - it doesn't work.

I get "Only YV12 colorspace is supported" and errors in 490, 439, 132 lines
Sure my source is in YV12 colorspace.

I'm using my own modification of LSharpAAF to use maa2 and it work as it should.
I've used official 1.50 version to modify.

Code:
# LSharpAAF() by Leinad4Mind
# v1.60 updated in 2015-03-23 by Great Dragon
# Requirements: awarpsharp2; EEDI2.dll; FastLineDarkenMOD.avsi; LSFmod.v1.9.avsi; MaskTools.dll; mt_masktools-26.dll; mvtools.dll;
# nnedi2.dll; RemoveGrain*.dll; Repair*.dll; SangNom.dll; UnFilter.dll
# * HD; HDS; S; SSE2; SSE3; T; TSSE2; TSSE3
#
# All AA Scripts are in this script, so there are no need to download them separately; Except some of them that you can find in AnimeIVTC, as maa, daa.
#
# This is an Anti-Aliasing Combo with some Extras like FastLineDarkenMOD, Presharpening, Postsharpening and Postsmoothing
# 
# Thanks to @ Didйe, thetoof, Mystery Keeper, Soulhunter, MisterHatt, martino, mf, Akirasuto, SpikeSpiegel, ScharfisBrain, LaTo & Sagekilla 
#
# Example: LSharpAAF(StrDrk=18, ShPre=100, ShPost=280, SmPost=80, aatype="ediaa")
# OR: LSharpAAF(18,100,280,80,"ediaa")

FUNCTION LSharpAAF(clip a, int "StrDrk", int "ShPre", int "ShPost", int "SmPost", bool "stabilize", int "tradius", bool "MT", int "aapel", int "aaov", int "aablk", string "aatype"){
StrDrk = default(StrDrk,38) #FastLineDarkenMOD
ShPre = default(ShPre,18) #Presharpening
ShPost = default(ShPost,300) #Postsharpening
SmPost = default(SmPost,100) #Postsmoothing
stabilize= default(stabilize,false ) # Use post stabilization with Motion Compensation
tradius	= default(tradius,2) # 2 = MDegrain2 / 3 = MDegrain3 
MT=default(MT,false) # Use josey_wells' branch of MVTools
aapel	= default(aapel,1) # accuracy of the motion estimation
# \ (Value can only be 1, 2 or 4. 1 means a precision to the pixel. 2 means a precision to half a pixel, 4 means a precision to quarter a pixel, produced by spatial interpolation (better but slower).)
aaov	= default ( aaov,(a.width>1100) ? 8 : 4 ) # block overlap value (horizontal). Must be even and less than block size. (Higher = more precise & slower)
aablk	= default ( aablk,(a.width>1100) ? 16 : 8 ) # Size of a block (horizontal). It's either 4, 8 or 16 ( default is 8 ). Larger blocks are less sensitive to noise, are faster, but also less accurate.
aatype = default(aatype,"EEDI2") # Use EEDI2() ; EEDI3() ; Sangnom() ; maa() ; daa() ; ediaa() ; aaa() ; saa() ; splinaa() ; supaa() ; naa() ; shaarp() ; aaf() ; laa() ; nnedi() ; nnedi2() ; nnedi3() ; antialiasing() ; nediaa() ; naa3mod(); for anti-aliasing.

a=a.AssumeTFF()
w=width(a)
h=height(a)
m=mt_logic(a.DEdgeMask(0,255,0,255,"5 10 5 0 0 0 -5 -10 -5", divisor=4,Y=3,U=3,V=3)
 \         ,a.DEdgeMask(0,255,0,255,"5 0 -5 10 0 -10 5 0 -5", divisor=4,Y=3,U=3,V=3)
 \       ,"max").mt_lut("x 128 / 0.86 ^ 255 *")

preaa=(ShPre==0 && StrDrk==0) ? a : (ShPre==0) ? a.fastlinedarkenmod(thinning=0, strength=StrDrk) : (StrDrk==0) ? a.lsfmod(defaults="slow",preblur="ON",strength=ShPre)
\ : a.fastlinedarkenmod(thinning=0, strength=StrDrk).lsfmod(defaults="slow",preblur="ON",strength=ShPre)

aa=(aatype=="EEDI2") ? preaa.TurnLeft().EEDI2().TurnRight().EEDI2().spline36resize(w,h,0.5,-0.5,2*w+.001,2*h+.001)
\ : (aatype=="EEDI3") ? preaa.TurnLeft().EEDI3().TurnRight().EEDI3().spline36resize(w,h)
\ : (aatype=="Sangnom") ? preaa.spline64resize(w*2,h*2).TurnLeft().SangNom(aa=255).TurnRight().SangNom(aa=255).spline36resize(w,h)
\ : (aatype=="maa") ? preaa.maa() : (aatype=="daa") ? preaa.daa() : (aatype=="ediaa") ? preaa.ediaa() : (aatype=="aaa") ? preaa.aaa()
\ : (aatype=="saa") ? preaa.SAA() : (aatype=="splinaa") ? preaa.splinaa() : (aatype=="supaa") ? preaa.supaa() : (aatype=="naa") ? preaa.naa()
\ : (aatype=="shaarp") ? preaa.shaarp() : (aatype=="aaf") ? preaa.aaf(aam=-0.7,rep=true) : (aatype=="laa") ? preaa.laa(96, 10, true, 2.0)
\ : (aatype=="nnedi") ? preaa.NNEDI(dh=true,field=1).TurnRight().NNEDI(dh=true,field=1).TurnLeft().Spline36Resize(w,h)
\ : (aatype=="nnedi2") ? preaa.NNEDI2(dh=true,field=1,nsize=2,qual=2).TurnRight().NNEDI2(dh=true,field=1,nsize=2,qual=2).TurnLeft().Spline36Resize(w,h,0.5,-0.5,2*w+.001,2*h+.001)
\ : (aatype=="nnedi3") ? preaa.NNEDI3(dh=true,field=1,nsize=2,qual=2).TurnRight().NNEDI3(dh=true,field=1,nsize=2,qual=2).TurnLeft().Spline36Resize(w, h)
\ : (aatype=="antialiasing") ? preaa.antialiasing()
\ : (aatype=="maa2") ? preaa.maa2()
\ : blankclip(pixel_type="YV12").subtitle("Please use Sangnom, EEDI2, EEDI3, maa, daa, ediaa, aaa, ssa, splinaa, supaa, naa, shaarp, aaf, laa,
 nnedi, nnedi2, nnedi3, or antialiasing for aatype")

postsh=(ShPost==0 && SmPost==0) ? aa : aa.LimitedSharpenFaster(edgemode=1,strength=ShPost,overshoot=1,soft=SmPost)

merged=mt_merge(a,postsh,m,Y=3,U=3,V=3)

sD=mt_makediff(a,merged)

asuper= a.MSuper(pel=aapel)
sDsuper  = sD.MSuper(pel=aapel, levels=1)

fv1 = tradius>=1 ? asuper.MAnalyse(isb=false,delta=1,overlap=aaov,blksize=aablk) : nop()
bv1 = tradius>=1 ? asuper.MAnalyse(isb=true, delta=1,overlap=aaov,blksize=aablk) : nop()
fv2 = tradius>=2 ? asuper.MAnalyse(isb=false,delta=2,overlap=aaov,blksize=aablk) : nop()
bv2 = tradius>=2 ? asuper.MAnalyse(isb=true, delta=2,overlap=aaov,blksize=aablk) : nop()
fv3 = tradius==3 ? asuper.MAnalyse(isb=false,delta=3,overlap=aaov,blksize=aablk) : nop()
bv3 = tradius==3 ? asuper.MAnalyse(isb=true, delta=3,overlap=aaov,blksize=aablk) : nop()

_thSAD = 600
_idx = 13

mbv1 = a.MVAnalyse(isb=true, delta=1,idx=_idx)
mbv2 = a.MVAnalyse(isb=true, delta=2,idx=_idx)
mfv2 = a.MVAnalyse(isb=false,delta=2,idx=_idx)
mfv1 = a.MVAnalyse(isb=false,delta=1,idx=_idx)
allv = (MT==false) ? a : a.MVAnalyseMulti(refframes=tradius,idx=_idx) 

sDD = (MT) ? sD.MVDegrainMulti(allv,idx=14) : sD.MVDegrain2(mbv1,mfv1,mbv2,mfv2,idx=14)
sDD2 = tradius==1 ? sDD.MDegrain1(sDsuper,bv1,fv1,thSAD=_thSAD) : tradius==2 ? sDD.MDegrain2(sDsuper,bv1,fv1,bv2,fv2,thSAD=_thSAD)
\ : sDD.MDegrain3(sDsuper,bv1,fv1,bv2,fv2,bv3,fv3,thSAD=_thSAD)

reduc = 0.4
sDD2 = mt_lutxy(sD,sDD2,"x 128 - abs y 128 - abs < x y ?").mergeluma(sDD2,1.0-reduc)

return stabilize ? a.mt_makediff(sDD2,U=2,V=2) : merged
}

#Simple Anti-aliasing by Soulhunter
FUNCTION saa(Clip Clp,Int"SS",Bool"CP") {
OX = Clp.Width
OY = Clp.Height
SS = Default(SS,2)
CP = Default(CP,True)
Clp = Clp.IsYV12() ? Clp : Clp.ConvertToYV12()
Clp.PointResize(OX*SS,OY*SS).SangNom().TurnRight()
\ .SangNom().TurnLeft().BilinearResize(OX,OY)
CP ? Last : MergeChroma(Clp)
Return(Last) }

#Normal Anti-aliasing by Didйe
FUNCTION antialiasing(clip orig,int "th_luma",int "th_croma",string "type",int "aath") {

# "th_luma" & "th_croma" are the edge detection thres.: lower values=more edges filtered
# "type" is the matrix used for edge detection: with "sobel" (default) only the 
# hi-contrast edges, where artefacts are more noticeable, are filtered. If you want
# to test other matrices, read the MaskTools Guide for more info.
# "aath" = anti-aliasing strenght (default should be fine)

th_luma = Default(th_luma, 20)
th_croma = Default(th_croma, 20)
type = Default(type, "sobel")
aath = Default(aath, 48)
ox = orig.width
oy = orig.height
dx = orig.width * 2
dy = orig.height * 2
clp = orig.IsYV12() ? orig : orig.ConvertToYV12()

a=clp
b=clp.Lanczos4Resize(dx,dy).TurnLeft().SangNom(aa=aath).TurnRight().SangNom(aa=aath) \
.LanczosResize(ox,oy)
c=clp.EdgeMask(th_luma,th_luma,th_croma,th_croma,type)
MaskedMerge(a,b,c) }

# Written by MisterHatt, based off of Soulhunter's SAA() and martino's excellent MAA(), and is slightly
# faster at times for some reason or another. These functions work by generally supersampling, usually with
# nnedi2, and then running a deinterlacer (sangnom and nnedi2 respectively) to get rid of most jaggies.
# I have no idea how destructive these are on whatever random thing people care to throw them at.
# For large supersamples, avs2yuv bitches for no real reason and requires assumeframebased() in your script.
# Requires nnedi2, sangnom, o9k hours of your life.
FUNCTION splinaa(Clip Clp,Int"SS",Bool"CP") {
OX = Clp.Width
OY = Clp.Height
SS = Default(SS,2)
CP = Default(CP,True)
Clp = Clp.IsYV12() ? Clp : Clp.ConvertToYV12()
Clp.PointResize(OX*SS,OY*SS).SangNom().TurnRight()
\  .SangNom().TurnLeft().Spline36Resize(OX,OY)
CP ? Last : MergeChroma(Clp)

Return(Last) }

FUNCTION supaa(Clip Clp,Int"SS",Bool"CP") {
OX = Clp.Width
OY = Clp.Height
SS = Default(SS,2)
CP = Default(CP,True)
Clp = Clp.IsYV12() ? Clp : Clp.ConvertToYV12()
Clp.nnedi2_rpow2(rfactor=SS,cshift="spline36resize",qual=3).SangNom().TurnRight()
\  .SangNom().TurnLeft().Spline36Resize(OX,OY)
CP ? Last : MergeChroma(Clp)

Return(Last) }

FUNCTION naa(Clip Clp,Int"SS",Bool"CP") {
OX = Clp.Width
OY = Clp.Height
SS = Default(SS,2)
CP = Default(CP,True)
Clp = Clp.IsYV12() ? Clp : Clp.ConvertToYV12()
Clp.nnedi3_rpow2(rfactor=SS,cshift="spline36resize",qual=2).nnedi3(nns=2).TurnRight().nnedi3(nns=2).TurnLeft().Spline36Resize(OX,OY)
CP ? Last : MergeChroma(Clp)

Return(Last) }

FUNCTION shaarp(clip input, int "mask", int "type") {
mask = Default(mask,1)
type = Default(type,1)
Assert(mask == 1 || mask == 2, "Please use mask = 1 or 2")
Assert(type == 1 || type == 2, "Please use type = 1 or 2")
aa_clip = (type == 1) ? input.spline36Resize(width(input)*2,height(input)*2) : input.nnedi2_rpow2(rfactor=2,qual=3)
aa_clip = aa_clip.TurnLeft().nnedi2().TurnRight().nnedi2().spline36Resize(width(input),height(input)).MergeChroma(input)
mask = (mask==1) ? input.mt_edge("sobel",7,7,5,5).mt_inflate() : input.mt_edge("roberts",0,4,0,4).mt_inflate()

return mt_merge(input,aa_clip,mask) }

function aaf(clip input, float "aam", int "aay", "aax", bool "rep")
{
input =	input.isYV12() ? input : input.converttoyv12()

aam	= default(aam, -0.6)
aar	= aam<0 ? (aam-1)*0.25 : (aam+1)*0.25
aay	= default(aay, 28)
aax	= default(aax, aay)
rep	= default(rep, true)

sx	= width(input)
sy	= height(input)

aa	= aar<0 ? input.LanczosResize(sx,int(sy*abs(aar))*4) :
	\	aar==0.5 ? input.Pointresize(sx*2, sy*2) :
	\	input.LanczosResize(int(sx*abs(aar)*4),int(sy*abs(aar))*4)
aa	= aay>0 ? aa.SangNom(aa=aax) : input
aa	= aar<0 && aax>0 ? aa.LanczosResize(int(sx*abs(aar))*4,sy) : aa
aa	= aax>0 ? aa.turnright().SangNom(aa=aax).Turnleft() : aa
aa	= aa.LanczosResize(sx,sy)

return rep==true ? aa.repair(input,18) : aa
}

### LaTo Antialiasing Script v2
### Need: asharp.dll & sangnom.dll
function LAA(clip input, int "strength", int "threshold", bool "sharp", float "ss") {

strength = default(strength, 96)
threshold = default(threshold, 10)
sharp = default(sharp, true)
ss = default(ss, 2.0)
aastr = int(strength) /2
asthr = float(strength) /100
ox = input.width
oy = input.height
ox2 = round(ox*ss/8)*8
oy2 = round(oy*ss/8)*8

process = input.spline36resize(ox2,oy2).turnleft().sangnom(aastr).turnright().sangnom(aastr)
process = ( sharp == true ) ? process.asharp(asthr,0,0).spline36resize(ox,oy) : process.spline36resize(ox,oy)
mask = mt_average(input,process,u=1,v=1).mt_edge(thy1=threshold,thy2=threshold,u=1,v=1)
output = mt_merge(input,process,mask,u=2,v=2)

return ( output ) 
}

function NediAA(clip c)
{   c.nnedi3(field=-2)
    merge(selecteven(),selectodd())  }

FUNCTION naa3mod(Clip Clp,Bool "CP")
{
OX = Clp.Width()
OY = Clp.Height()
CP = Default(CP,True)
Clp = Clp.IsYV12() ? Clp : Clp.ConvertToYV12()
Clpnn1 = Clp.nnedi3(1, dh=true,nsize=2,qual=2,U=CP,V=CP).nnedi3(0,nsize=2,qual=2,U=CP,V=CP)
Clpy1 = Clpnn1.Spline36Resize(OX,OY,0,-0.5,OX,OY*2)
Clps1 = CP ? Clpy1.MergeChroma(Clpnn1.Spline36Resize(OX,OY,0,-1,OX,OY*2)) : Clpy1.MergeChroma(Clp)
Clpnn2 = Clps1.turnright().nnedi3(1, dh=true,nsize=2,qual=2,U=CP,V=CP).nnedi3(0,nsize=2,qual=2,U=CP,V=CP)
Clpy2 = Clpnn2.Spline36Resize(OY,OX,0,-0.5,OY,OX*2)
CP ? Clpy2.MergeChroma(Clpnn2.Spline36Resize(OY,OX,0,-1,OY,OX*2)).turnleft() : Clpy2.turnleft().MergeChroma(Clp)
Return(Last)
}

function maa2(clip c, int "mask", bool "chroma", float "ss", int "aa", int "aac", int "threads", int "show", int "maskt")
{
    chroma = Default(chroma, false)
    mask   = Default(mask, 1)
    maskt   = Default(maskt, 1)
    mtresh = (mask < 0) ? -mask : 7
    show   = Default(show, 0)
    uv     = (chroma) ? 3 : 1
 
    Assert(c.IsY8 || c.IsYV12 || c.IsYV24 || c.IsYV16, "MAA2: Input must be Y8, YV12, YV16 or YV24")
    Assert(0 <= show <= 2, "MAA2: Parameter 'show' must be between 0 and 2")
 
    # create mask
    if (mask != 0) {
        m = (maskt != 1) ? c.mt_edge("min/max", 0, mtresh, 0, mtresh-6, u=uv, v=uv).mt_inflate(u=uv, v=uv) : c.mt_edge("sobel", mtresh, mtresh, mtresh-6, mtresh-6, u=uv, v=uv).mt_inflate(u=uv, v=uv)
    }
 
    # run sangnom2-based aa
    if (!chroma || show > 0) {
        c_aa = c.ConvertToY8().Sangnom2AA(ss, aa, threads=threads)
    }
    else if (c.IsYV16) {
        c_aa_u = c.UtoY8().Sangnom2AA(ss, aac, threads=threads)
        c_aa_v = c.VtoY8().Sangnom2AA(ss, aac, threads=threads)
        c_aa = YToUV(c_aa_u, c_aa_v, c.ConvertToY8().Sangnom2AA(ss, aa, threads=threads))
    }
    else { c_aa = c.Sangnom2AA(ss, aa, aac, threads) }
 
    # prepare chroma planes for mask overlay
    if (show == 1) {
        c_aa = (c.IsY8) ? c.ConvertToYV12().mt_lut(y=2, u=0, v=0)
                      \ : c.mt_lut("x 2 /", y=2, u=3, v=3)
    }
    else if (show == 2) {
        c_aa = (c.IsY8) ? c_aa.ConvertToYV12().mt_lut(y=2, u=0, v=0)
                      \ : YtoUV(c.UtoY8(), c.VtoY8(), c_aa).mt_lut("x 2 /", y=2, u=3, v=3)
    }
 
    # merge aa'ed lines into source
    if (mask == 0) {
        return mt_logic(c_aa, "and", y=4, u=2, v=2)
    }
    else if (show > 0) {
        if (c.IsYV16) {
            m_uv = BilinearResize(m, m.width/2, m.height)
            return mt_merge(c, c_aa, YtoUV(m_uv, m_uv, m), u=3, v=3)
        }
        else {
            return (c.IsYV24) ? mt_merge(c, c_aa, m.YtoUV(m,m), u=3, v=3)
                            \ : mt_merge(c.ConvertToYV12(), c_aa, m, u=3, v=3, luma=true)
        }
    }
    else {
        return (chroma) ? mt_merge(c, c_aa, m, u=3, v=3)
                      \ : mt_merge(c, c_aa, m, u=2, v=2)
    }
}
 
function Sangnom2AA(clip c, float "ss", int "aa", int "aac", int "threads")
{
    threads = Default(threads, 4)
    aa = Default(aa, 48)
    aac = Default(aac, aa-8)
    aac = (aac < 0) ? 0 : aac
    ss = Default(ss, 2.0)
    ss_w = int(round(c.width*ss/4.0)*4)
    ss_h = int(round(c.height*ss/4.0)*4)
 
    Assert(ss > 0, "MAA2: Supersampling factor must be > 0")
 
    return c.Spline36Resize(ss_w, ss_h).TurnLeft() \
            .SangNom2(threads=threads, aa=aa, aac=aac).TurnRight().SangNom2(threads=threads, aa=aa, aac=aac).Spline36Resize(c.width, c.height)
}

Last edited by Great Dragon; 8th April 2015 at 21:50.
Great Dragon is offline   Reply With Quote
Reply

Tags
antialiasing, fastlinedarken, lsf, lsharpaaf, sharpen

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 14:29.


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