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 4th March 2010, 12:02   #1  |  Link
rkalwaitis
Robert
 
Join Date: Jan 2008
Location: Stuttgart
Posts: 407
Motion Compensated Sharpening

I was hoping that someone could please help me find a motion compensated script similar to the process that is used in MC_Spuds.

Thanks
rkalwaitis is offline   Reply With Quote
Old 4th March 2010, 13:00   #2  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
Such can be found in several scripts - TGMC has something like that, MC_Spuds has (borrowed from dunno-where), TemporalDegrain has, ...

Some "basic" scripts to demonstrate the general principle ...

Basic script, variant#1: "spatial sharpen, temporally limited".

Code:
source = whatever
sup    = source.MSuper(pel=2,sharp=2)
bv1    = sup.MAnalyse(isb=true, delta=1, [more params to liking], ...)
fv1    = sup.MAnalyse(isb=false,delta=1, [more params to liking], ...)
bc1    = source.MCompensate(sup,bv1,thSAD=500)
fc1    = source.MCompensate(sup,fv1,thSAD=500)
max    = mt_logic(bc1,fc1,"max").mt_logic(source,"max")
min    = mt_logic(bc1,fc1,"min").mt_logic(source,"min")
sharp1 = source.sharpen(1).mergechroma(last) # chroma sharpen usually is unadvantageous

sharp1.mt_clamp(max,min,0,0,U=2,V=2)
edit: corrected vector naming: "bv" -> "bv1"



Basic script, variant#1a: "spatial sharpen, temporally limited, using median-sharpen for more headroom on temporal limiting"

Code:
source = whatever
sharp0 = source.mt_adddiff(mt_makediff(source,source.removegrain(4)),U=2,V=2) # "median sharpen" (won't create halos on its own, IF the source is halo-free)
sup1   = source.MSuper(pel=2,sharp=2)
sup2   = sharp0.MSuper(pel=2,sharp=2,levels=1)
bv1    = sup1.MAnalyse(isb=true, delta=1, [more params to liking], ...)
fv1    = sup1.MAnalyse(isb=false,delta=1, [more params to liking], ...)
bc1    = source.MCompensate(sup2,bv1,thSAD=500)  # using the super clip from the median-sharpener, to provide
fc1    = source.MCompensate(sup2,fv1,thSAD=500)  # more headroom for the limiting process
max    = mt_logic(bc1,fc1,"max").mt_logic(source,"max")
min    = mt_logic(bc1,fc1,"min").mt_logic(source,"min")
sharp1 = source.sharpen(1).mergechroma(last) # chroma sharpen usually is unadvantageous

sharp1.mt_clamp(max,min,0,0,U=2,V=2)
edit: corrected vector naming: "bv" -> "bv1"




Basic script, variant#2: "spatial sharpen, temporally averaged"

Code:
source = whatever
sharp0 = source.sharpen(1).mergechroma(source)
sup1   = source.MSuper(pel=2,sharp=2)
sup2   = sharp0.MSuper(pel=2,sharp=2,levels=1)
bv1    = sup1.MAnalyse(isb=true, delta=1, [more params to liking], ...)
fv1    = sup1.MAnalyse(isb=false,delta=1, [more params to liking], ...)
bv2    = sup1.MAnalyse(isb=true, delta=2, [more params to liking], ...)
fv2    = sup1.MAnalyse(isb=false,delta=2, [more params to liking], ...)

source.MDegrain2(sup2,bv1,fv1,bv2,fv2)
Note that the MDegrain has "source" as 1st input, not "sharp0". The idea is to use sharpening only in areas where the motion estimation found good matches. In places where no good motion-match was found, it's probably better to not use sharpening. If you want to be more aggressive with sharpening, type "sharp0.Mdegrain2(...)" there.

This method still does *denoise* the source on the way, more or less. May be wished, or it may be not. If denoising is not wished, adapt the script to use the sharp-difference instead:


Basic script, variant#2a: "spatial sharpen, temporally averaged, without denoising"

Code:
source = whatever
sharp0 = source.sharpen(1)
sharpD = mt_makediff(source,sharp0)
zeroD = sharpD.mt_lut("x",Y=-128)

sup1   = source.MSuper(pel=2,sharp=2)
sup2   = sharpD.MSuper(pel=2,sharp=2,levels=1)
bv1    = sup1.MAnalyse(isb=true, delta=1, [more params to liking], ...)
fv1    = sup1.MAnalyse(isb=false,delta=1, [more params to liking], ...)
bv2    = sup1.MAnalyse(isb=true, delta=2, [more params to liking], ...)
fv2    = sup1.MAnalyse(isb=false,delta=2, [more params to liking], ...)

zeroD.MDegrain2(sup2,bv1,fv1,bv2,fv2)

source.mt_makediff(last,U=2,V=2)
This code does "no sharpen on bad motion-match" in the same way. For the aggressive variant, type "sharpD.MDegrain2(...)".

Hope there are no errors due to the hurry of typing ... if you find some, do speak.
__________________
- 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 March 2010 at 14:45. Reason: added variant "1a", also cleared script 1 ('last' -> 'source')
Didée is offline   Reply With Quote
Old 4th March 2010, 13:20   #3  |  Link
rkalwaitis
Robert
 
Join Date: Jan 2008
Location: Stuttgart
Posts: 407
Thanks Didee,

Please forgive this question, but in example 1, how do I calculate or determine the min and the max.

Last edited by rkalwaitis; 4th March 2010 at 13:48.
rkalwaitis is offline   Reply With Quote
Old 4th March 2010, 13:54   #4  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
No problem, you're welcome. But let me point out these scripts really do only show the "barebone principle". For optimal results, things probably should be done a bit more artistic. E.g., none of those basics does care for "oversharpening" (halo creation).

With script#1, halos are a lesser problem. The problem rather is that you'll only get very little sharpening, due to the pretty strong constraint. For getting more effect, it's needed to provide more "headroom" that the sharpening can expand into. (I quite like median-sharpening for that task, but the available possibilities are countless.)

With script#2/2a, the sharpening can create halos quite easily, so in order to avoid that issue, the basic sharpening process should be more sophisticated than just "sharpen(1)".
But just replacing sharpen() with LimitedSharpen() isn't a too brilliant idea either - LS/F probably is too weak for that. Something in the spirit of SeeSaw's sharpening, used on a slightly pre-blurred input, is what often works good.


It's like it always is: the basic principle is not very hard. But tweaking it so that it works as good as possible in practice, and in as many different situations as possible - that's the harder task.
(And that's also why I find myself quite often just making a whole new script from scratch for any given source, rather then trying to come up with can-do-everything multi-purpose scripts, using two hundred different parameters, which most people wouldn't use anyway...)


Edit: just saw your edit - oh, there's a mistake in script#1. The min+max need also the current frame into account, of course! Script corrected.
__________________
- 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 4th March 2010, 14:23   #5  |  Link
rkalwaitis
Robert
 
Join Date: Jan 2008
Location: Stuttgart
Posts: 407
Thanks again, I understand that they are the bare bones, and to be honest that is what I was looking for. It helps me to understand the process better. Im gonna play with the toys you gave me. I dont know why I was thinking that a motion compensated sharpening would be more capable of fending of haloing. I must be motion compensated because I usually am the culprit of the artifacts.

Thanks again
rkalwaitis is offline   Reply With Quote
Old 4th March 2010, 18:03   #6  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
I have added script variant "1a", as an example for how to give more sharpening headroom via a median-sharpener.

Also cleared the syntax of variant#1 - the usage of "last" in two places was a bit muddy, "source" is more clear in syntax/logic.
__________________
- 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 4th March 2010, 18:53   #7  |  Link
rkalwaitis
Robert
 
Join Date: Jan 2008
Location: Stuttgart
Posts: 407
Thanks alot Didee, Im all over it after I finish taking care of the kids. Cool flickr gallery
rkalwaitis is offline   Reply With Quote
Old 5th March 2010, 11:02   #8  |  Link
rkalwaitis
Robert
 
Join Date: Jan 2008
Location: Stuttgart
Posts: 407
Didee does it make sense to compensate more than one frame forward and one frame backward when attempting the sharpening? Variant 2a worked well.
rkalwaitis is offline   Reply With Quote
Old 5th March 2010, 17:22   #9  |  Link
Undead Sega
Registered User
 
Join Date: Oct 2007
Posts: 711
wow there's such thing as Motion Compensated Sharpening? i dreamt of this and was thinking of mentioning it but was abit afraid of being tampered down for such silliness but this is quite suprising to me. May i ask how does this differ to other conventional sharpeners out there?
Undead Sega is offline   Reply With Quote
Old 5th March 2010, 17:42   #10  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
What I have showed is traditional spatial sharpen, plus motion-compensated postprocessing.

You shouldn't "dream" of things just because it "sounds so cooool". Do you want to have a motion-compensated "trim()" filter? Or perhaps a neural network that performs "AddBorders()"?

Before getting all too excited about funky terminology, it's always better to understand what it's supposed to mean (or to do).
__________________
- 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 6th March 2010, 05:33   #11  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 949
This is interesting, but why not make it motion-compensated contrasharpening?
Dogway is offline   Reply With Quote
Old 6th March 2010, 09:50   #12  |  Link
scharfis_brain
brainless
 
scharfis_brain's Avatar
 
Join Date: Mar 2003
Location: Germany
Posts: 3,607
maybe with motion compensated sharpening he meant a motion compensated temporal sharpener, which effectively will enhance grain and noise?
(it is the opposite of a temporal smoother (denoiser))
__________________
Don't forget the 'c'!

Don't PM me for technical support, please.
scharfis_brain is offline   Reply With Quote
Old 6th March 2010, 13:05   #13  |  Link
Soulhunter
Bored...
 
Soulhunter's Avatar
 
Join Date: Apr 2003
Location: Unknown
Posts: 2,812
So, sorta like UnSmooth back then?
__________________

Visit my IRC channel
Soulhunter is offline   Reply With Quote
Old 6th March 2010, 13:06   #14  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,390
Quote:
Originally Posted by scharfis_brain View Post
maybe with motion compensated sharpening he meant a motion compensated temporal sharpener
Experience has told that people oftentimes just do not know what they mean when saying "motion compensated sharpen".

Quote:
... which effectively will enhance grain and noise?
(it is the opposite of a temporal smoother (denoiser))
Exactly that. In theory, you would use a "mocomp temporal sharpen" principle when trying to squeeze additional information out of the "subpixel level". But in practice, you'll just enhance noise that way.


Quote:
Originally Posted by Dogway View Post
This is interesting, but why not make it motion-compensated contrasharpening?
Contra-sharpening implies that anything has been removed from the source beforehand.
And ... the basic principle is already included, namely in script#1.
__________________
- 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 11th March 2010, 12:26   #15  |  Link
Nephilis
--preset WTF!
 
Join Date: Feb 2009
Posts: 86
<< Basic script, variant#2: "spatial sharpen, temporally averaged" >> is the real deal. I use it since Didée posted it in another thread.. With SeeSaaw it works like a charm

Greetz fly out to Didée

Last edited by Nephilis; 11th March 2010 at 12:28.
Nephilis is offline   Reply With Quote
Old 11th March 2010, 21:22   #16  |  Link
rkalwaitis
Robert
 
Join Date: Jan 2008
Location: Stuttgart
Posts: 407
Nephilis, could you please post your seesaw script so I can see how you use variant#2. Thanks. I like the first script with mdegrain2. MP4.Guy also has a MedSharp that he is working on that is interesting. Its one of the newer posts. You should check it out.

http://forum.doom9.org/showthread.php?t=153201

Last edited by rkalwaitis; 11th March 2010 at 21:25.
rkalwaitis is offline   Reply With Quote
Old 12th March 2010, 06:14   #17  |  Link
Vitaliy Gorbatenko
viterra
 
Join Date: Feb 2003
Location: St. Peterburg, Russia
Posts: 142
Nephilis: Post a complete script, please!
Vitaliy Gorbatenko is offline   Reply With Quote
Old 26th March 2010, 23:46   #18  |  Link
Undead Sega
Registered User
 
Join Date: Oct 2007
Posts: 711
sample images by any chance?
Undead Sega is offline   Reply With Quote
Old 28th March 2010, 00:34   #19  |  Link
Nightshiver
Quality Freak
 
Join Date: Jun 2007
Location: Area 52
Posts: 597
Code:
source = whatever
sharp0 = source.sharpen(1).mergechroma(source)
sup1   = source.MSuper(pel=2,sharp=2)
sup2   = sharp0.MSuper(pel=2,sharp=2,levels=1)
bv1    = sup1.MAnalyse(isb=true, delta=1, [more params to liking], ...)
fv1    = sup1.MAnalyse(isb=false,delta=1, [more params to liking], ...)
bv2    = sup1.MAnalyse(isb=true, delta=2, [more params to liking], ...)
fv2    = sup1.MAnalyse(isb=false,delta=2, [more params to liking], ...)

b = source.MDegrain2(sup2,bv1,fv1,bv2,fv2)

a = last
SeeSaw(a, b, whatever settings you want)
Or, if going along with Didee's way of repacing Sharpen() with SeeSaw(), I think it would look something like this:

Code:
source = whatever
sharp0 = source.SeeSaw(whatever settings you want).mergechroma(source)
sup1   = source.MSuper(pel=2,sharp=2)
sup2   = sharp0.MSuper(pel=2,sharp=2,levels=1)
bv1    = sup1.MAnalyse(isb=true, delta=1, [more params to liking], ...)
fv1    = sup1.MAnalyse(isb=false,delta=1, [more params to liking], ...)
bv2    = sup1.MAnalyse(isb=true, delta=2, [more params to liking], ...)
fv2    = sup1.MAnalyse(isb=false,delta=2, [more params to liking], ...)

source.MDegrain2(sup2,bv1,fv1,bv2,fv2)

Last edited by Nightshiver; 28th March 2010 at 00:52.
Nightshiver is offline   Reply With Quote
Old 28th March 2010, 10:21   #20  |  Link
Dogway
Registered User
 
Join Date: Nov 2009
Posts: 949
How can I wrap it into a function?
Dogway 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 11:25.


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