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 6th September 2005, 15:28   #1  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Soothe() - small helper function for sharpening with less temporal jitter

Hello friends,

this is a small postprocessor function for sharpening filters. The goal is temporal stabilization of clips that have been sharpened before. It is reasonably fast (contains 3 different YV12Lutxy operations and one TemporalSoften - that's about the cheapest possibility for what is done. Plugin coders are welcome ), and seems to work pretty well.

The introduction of jitter on the temporal axis is a general problem of sharpening operations, since sharpening (usually) considers spatial aspects only. Therefore, Soothe() does a very simple job: get the difference between [source] and [sharpened source], apply a TemporalSoften on this difference BUT allow only changes towards 128 ("neutral"), and then apply this temporally calmed difference back to the original clip.
Effectively, this will reduce the overall effect of sharpening - less in static areas, and more in moving areas.

Advantages:

- more steady appearance (less "nervous")
- less bitrate required
- somewhat positive effect on detail that is, due to the sharpening, prone to aliasing
- smoother motion compaired to plain-sharpening, since motion-blurred edges will be less sharpened
- less artefacts in moving areas
- LimitedSharpen can run faster, since one can get away with less supersampling
- should only help, never harm

Disadvantages:

- overall sharpening effect is reduced, but this can be compensated by a little more initial sharpening.


Syntax:

Soothe( [sharpclip], [sourceclip], keep )

"keep" is an integer, range 0 - 100, that tells how much percent of the original sharpening will be kept at least. Default is 25.


Example:

We use LimitedSharpen() as sharpener, and we'll keep at least 20% of its result:
Code:
dull   = last
sharp  = dull.LimitedSharpen( ss_x=1.25, ss_y=1.25, strength=150, overshoot=1 )

Soothe( sharp, dull, 20 )
Easy, isn't it?


Script function: (needs the MaskTools, as usual)

edit 21 Nov 05: corrected LUT expression! (old one could cause weird blurring in certain places!)
Code:
function Soothe(clip sharp, clip orig, int "keep")
{
keep  = default(keep, 24)
keep  = (keep>100) ? 100 : (keep<0) ? 0 : keep
KP    = string(keep)
diff  = yv12lutxy(orig,sharp,"x y - 128 +", U=1,V=1)
diff2 = diff.temporalsoften(1,255,255,32,2)
diff3 = yv12lutxy(diff,diff2,  "x 128 - y 128 - * 0 < x 128 - 100 / "  + KP 
 \                           + " * 128 + x 128 - abs y 128 - abs > x " + KP 
 \                           + " * y 100 " + KP + " - * + 100 / x ? ?",  U=1,V=1)
return( yv12lutxy(orig,diff3,"x y 128 - -",U=2,V=2) )
}
Note: Basically, the function is as dumb as it can only be ... but that doesn't seem to hold it back from doing a nice job.


Feel free to post your impressions, and/or if you think something should be altered or improved.
__________________
- 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; 21st November 2005 at 17:37.
Didée is offline   Reply With Quote
Old 6th September 2005, 16:04   #2  |  Link
unskinnyboy
Registered User
 
unskinnyboy's Avatar
 
Join Date: Feb 2004
Location: NTSC R1
Posts: 2,046
Whoa! Another Didée product! Can't go wrong, I'm sure. Can't wait to see the effects of this with my own eyes. This seems to effectively address some of the concerns I had with LS() usage. Will be testing soon..

Thanks!
__________________
unskinnyboy is offline   Reply With Quote
Old 6th September 2005, 17:29   #3  |  Link
Pookie
Registered User
 
Join Date: Apr 2005
Posts: 1,339
Thank You, Thank You, Thank You !

Just tried it. Works with other, less sophisticated sharpeners as well. Great job.

Last edited by Pookie; 6th September 2005 at 18:29.
Pookie is offline   Reply With Quote
Old 6th September 2005, 17:46   #4  |  Link
shaolin95
Registered User
 
Join Date: Aug 2005
Posts: 293
Didee will this help the problem I posted I have with LimitedSharpen with some DVDs. I created a post about it recently. Some DVDs like Two Towers, Die Another Day looks simply awesome almost HD in perceived detail but others show many artifacts like the superbit titles Underworld and Fifth Element. They show artifacts mainly along vertical lines.
shaolin95 is offline   Reply With Quote
Old 6th September 2005, 19:15   #5  |  Link
MOmonster
Registered User
 
Join Date: May 2005
Location: Germany
Posts: 495
Thanks for this new function, Didee.
I´ll test it tomorrow. This is the first time I can fully understand how your function works (thanks for the explaination of the reverse polish notation ).
Keep on the good work.
MOmonster is offline   Reply With Quote
Old 7th September 2005, 07:39   #6  |  Link
shaolin95
Registered User
 
Join Date: Aug 2005
Posts: 293
I just tried it like you posted here in the example and I like it! It helped me fix those DVDs I was having issues with when using LimitedSharpen (the artifacts in vertical lines).
This is my call:

Import("C:\Program Files\AviSynth 2.5\plugins\LimitedSharpen.avs")

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\MaskTools.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\WarpSharp.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\colormatrix.dll")

dull = last
sharp = dull.LimitedSharpen( ss_x=1.0, ss_y=1.0,
\ Smode=3, strength=90, radius=2,
\ Lmode=1, wide=false, overshoot=1,
\ soft=false, edgemode=0, special=false,
\ exborder=0 )

ColorMatrix()

Soothe( sharp, dull, 20 )

I am a Avisynth super noob so most of my calls are copy paste and stich them together style. I am still able to resize 2.5x and get smooth playback with this Soothe and LS so to me is a keeper. Gonna try some other settings this weekend as my wife wasnt to happy I had yet another thing to try tonight with my projector...women!!!
shaolin95 is offline   Reply With Quote
Old 7th September 2005, 09:12   #7  |  Link
Firesurfer
Registered User
 
Join Date: Jul 2005
Posts: 15
@shaolin95:
I hope you are aware, that the call of ColorMatrix() is not affecting the video in this script. Also ColorMatrix() should be used as first filter in the chain. (Im not sure with interlaced material, though.)
Firesurfer is offline   Reply With Quote
Old 7th September 2005, 09:50   #8  |  Link
Audionut
Registered User
 
Join Date: Nov 2003
Posts: 1,281
I can't get it to work with limited sharpen.

error:

Invalid arguments to function "width"
test.avs, line 19

Script:

Code:
import("g:\x\ltsmc.avs")
import("g:\x\soothe.avs")
import("g:\x\blinddehalo3.avs")
import("g:\x\lsharpen2.avs")
source=mpeg2source("D:\test.d2v")
source=crop(source,8,8,-8,-8)
source=lanczos4resize(source,704,384)
video=mpeg2source("D:\test.d2v")
video=crop(video,8,8,-8,-8)
video=ltsmc(video,apmode=4,blcksze=4,chromame=true,sharpness=100)
video=lanczos4resize(video,704,384)
video=BlindDeHalo3(video, rx=3.0, ry=3.0, strength=50, 
 \            lodamp=0.0, hidamp=0.0, sharpness=1.0, tweaker=0.0,
 \            PPmode=1, PPlimit=0, interlaced=false)
video=LimitedSharpen(video,ss_x=1.5,   ss_y=1.5,     dest_x=last.width, dest_y=last.height,
 \                    Smode=3,    strength=300, radius=3,
 \                    Lmode=1,    wide=false,   overshoot=1,
 \                    soft=false, edgemode=0,   special=false,
 \                    exborder=0 )
soothe(video,source,10)

Last edited by Audionut; 7th September 2005 at 09:56.
Audionut is offline   Reply With Quote
Old 7th September 2005, 09:59   #9  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Even without Soothe(), *that* script will not load.

Educational question: Why?


edit: Oh, you cleaned up the script. Much better now ... almost good.

Remaining problem: you are assigning all sources directly to clip variables. Hence there's never anything assigned to the "last" variable, hence the "last.width" and "last.height" are causing the error. To make the script semantically correct, you have to write "source.width" and "source.height" in the LimitedSharpen line.

But even then, this is wrong usage. Actually, you're letting Soothe() reduce ALL effects that you have applied to "video", including the de-haloing and the noise reduction. Most probably that is not what you want to do ...

(BTW, opening the same source two times generally is not a smart idea.)

Code:
import("g:\x\ltsmc.avs")
import("g:\x\soothe.avs")
import("g:\x\blinddehalo3.avs")
import("g:\x\lsharpen2.avs")

video = mpeg2source("D:\test.d2v")
video = video.crop(8,8,-8,-8)
video = video.ltsmc(apmode=4,blcksze=4,chromame=true,sharpness=100)
video = video.lanczos4resize(704,384)
video = video.BlindDeHalo3(rx=3.0, ry=3.0, strength=50, 
 \                         lodamp=0.0, hidamp=0.0, sharpness=1.0, tweaker=0.0,
 \                         PPmode=1, PPlimit=0, interlaced=false)
video2= video.LimitedSharpen(ss_x=1.5,   ss_y=1.5,
 \                           Smode=3,    strength=300, radius=3,
 \                           Lmode=1,    wide=false,   overshoot=1,
 \                           soft=false, edgemode=0,   special=false,
 \                           exborder=0 )
soothe(video2,video,10)
Now Soothe() is postprocessing only LS's sharpening and nothing else, like intended.
__________________
- 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; 7th September 2005 at 10:13.
Didée is offline   Reply With Quote
Old 7th September 2005, 12:31   #10  |  Link
Audionut
Registered User
 
Join Date: Nov 2003
Posts: 1,281
Thanks for the clarification.

Works like a charm.
Audionut is offline   Reply With Quote
Old 7th September 2005, 13:13   #11  |  Link
psme
Registered User
 
Join Date: Mar 2005
Posts: 68
Will this work for REALTIME playback in FFDShow->avisynth, like LimitedSharpen? TIA.

regards,

Li On
psme is offline   Reply With Quote
Old 7th September 2005, 13:19   #12  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Depends on the horsepower you've available. My elderly Athlon1800 definetly is too weak for that.

Just try it, and report.
__________________
- 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 7th September 2005, 13:57   #13  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Didée,

Yay!

a little relating to this on that thread at

http://videoprocessing.11.forumer.co...r=asc&start=15

(Right at the end of page 2 and onwards)
mg262 is offline   Reply With Quote
Old 7th September 2005, 15:08   #14  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Note: Edited the thread title ("... helper function ...") to better reflect the function's purpose.


Clouded - yes, already saw it. Just can't dive into it ATM
__________________
- 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 7th September 2005, 16:11   #15  |  Link
psme
Registered User
 
Join Date: Mar 2005
Posts: 68
Initial test for realtime playback via FFDShow->avisynth:

Import("C:\Program Files\AviSynth 2.5\plugins\ModerateSharpen.avs")
Import("C:\Program Files\AviSynth 2.5\plugins\Soothe.avs")
dull = last
sharp = dull.ModerateSharpen(0.3)

Soothe( sharp, dull, 20 )

VERY interesting. Need to test more....

regards,

Li On
psme is offline   Reply With Quote
Old 7th September 2005, 17:16   #16  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
Quote:
Clouded - yes, already saw it. Just can't dive into it ATM
No hurry! As you may have noticed I'm being very slow at my end as well...
mg262 is offline   Reply With Quote
Old 7th September 2005, 20:15   #17  |  Link
shaolin95
Registered User
 
Join Date: Aug 2005
Posts: 293
Sup Li On (I am Luis Gabriel Gerena from AVSFORUM),
I am already using it together with LimistedSharpen, check my previous post here and it works fine even using resize 2.5 x but I do need to run my CPU at 2660MHZ (stock is 2.4).

One question, why doesnt the ColorMatrix work in my call script? I just copied that from another thread about Limited Sharpen and all the scripts there had Color Matrix at the end. What is it for anyway and how do I use it?
Regards
shaolin95 is offline   Reply With Quote
Old 7th September 2005, 20:44   #18  |  Link
communist
Registered User
 
Join Date: Jul 2003
Posts: 1,152
Quote:
Originally Posted by shaolin95
ColorMatrix (...) What is it for anyway and how do I use it?
Regards
http://forum.doom9.org/showthread.php?t=82217
communist is offline   Reply With Quote
Old 8th September 2005, 02:50   #19  |  Link
mg262
Clouded
 
mg262's Avatar
 
Join Date: Jul 2003
Location: Cambridge, UK
Posts: 1,148
As anyone who peeked at that link may have seen, I'm trying to write some auxiliary filter-lets to speed up LimitedSharpen and Soothe. Unfortunately, all the content I have at hand at present is a)animation and b) very noisy, which means that it's very hard to tell whether things are working correctly or not. So this is a plea for some small source on which the effect of both filters is very clear -- doesn't matter how small -- even five or 10 frames would be great. [I can keep working by using subtract, etc, but it does make life easier to be able to see what's happening!]

I can receive anything at blendarchive@gmail.com -- and anything will be very gratefully received! (But no 18-rated material or the like please!)

Last edited by mg262; 8th September 2005 at 03:02.
mg262 is offline   Reply With Quote
Old 8th September 2005, 10:05   #20  |  Link
Firesurfer
Registered User
 
Join Date: Jul 2005
Posts: 15
First: My Apologies to Shaolin95. I typed my comment in a hurry without clarifying what I meant. I guess there's even a forum rule against that

Second:
To make my point I repeat your script first:

Code:
Import("C:\Program Files\AviSynth 2.5\plugins\LimitedSharpen.avs")

LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\MaskTools.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\WarpSharp.dll")
LoadPlugin("C:\Program Files\AviSynth 2.5\plugins\colormatrix.dll")

dull = last
sharp = dull.LimitedSharpen( ss_x=1.0, ss_y=1.0,
\ Smode=3, strength=90, radius=2,
\ Lmode=1, wide=false, overshoot=1,
\ soft=false, edgemode=0, special=false,
\ exborder=0 )

ColorMatrix()

Soothe( sharp, dull, 20 )
You use the variables dull and sharp for your video, but you don't specify on which of these variables you want to use colormatrix(), so it uses implicit last, which could be sharp or even the unfiltered stream that AviSource gives (I would presume the second). both are not what you want. After that Sothe() is used on sharp and dull, but not on the stream that ColorMatrix() has filtered.
AviSynth documentation on variables should give you further clarification about this.

After all, I guess you read the ColorMatrix()-thread by now and know if you should be using it and why you should use it as the first filter after ...Source().

Last edited by Firesurfer; 8th September 2005 at 10:42.
Firesurfer 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:25.


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