View Full Version : DEdgeSharpPP
GerSoft
22nd June 2006, 22:19
I'm writing a litle Script to sharpen DVD Source with low grain.
The sript is trying to limit oversharpen on borders.
You can use a PixelPlus Effect for great sharpen.
http://forum.gleitz.info/showthread.php?p=275400#post275400
Didée
23rd June 2006, 20:23
Nice to know that you are writing a script. Even more nice would be to actually post it ... sharing thoughts is what we do a lot in this forum. But without a script, there's not much to talk about ... ;)
(Exept for your pictures still showing some noticeable oversharpening.)
Oh, btw,
The sript is trying to limit oversharpen on borders
did you ever happen to stumble about this here (http://forum.doom9.org/showthread.php?t=84196&highlight=limitedsharpen), or eventually
a PixelPlus Effect for great sharpen
about this here (http://forum.doom9.org/showthread.php?t=104701&highlight=SeeSaw)?
Guest
23rd June 2006, 20:36
... or even here:
http://neuron2.net/msharpen/msharpen.html
Didée
23rd June 2006, 20:45
Shot from offside, Don. ;)
MSharpen tries to bypass >noise< during sharpening ... oversharpening on edges it may produce very well.
Guest
23rd June 2006, 21:01
Oh, sorry for the confusion, I thought he might find it useful as a starting point for a native solution, rather than a scripted one.
GerSoft
24th June 2006, 12:21
I know "LimitedSharpen" and "SeaSaw". They are great, the best scripts arround !!
But very complex. (slow?)
I wanted to use limitedsharpen but I allways get some strange edges like this (http://forum.doom9.org/showthread.php?t=87514&page=2).
I've found no way to fix this.
So I've tried to find an easy way to get the same effect. I'm shure the quality is not as good as limitedsharpen. The script is very easy, but I'm using the same idear. I'm newbe in scripting and using Avisynth, so I'm just proud of the result.
I wan't to speed up the sript with GPU_Resize and GPU_fft3dfilter.
Sorry for strange English (german user).
So here's the Script:
function DEdgeSharpPP(clip clp,int "PixelPlus",float "SharpenValue")
{
SharpenValue=default (SharpenValue, 0.55)
PixelPlus=default (PixelPlus, 0)
clp_x=clp.width
clp_Y=clp.height
SharpenValue=SharpenValue + (0.0021 * Pixelplus)
clp=clp.lanczos4resize(clp_x + PixelPlus,clp_Y + PixelPlus)
clp=clp.DeGrainMedian(limitY=2,limitUV=3,mode=1)
clp=clp.asharp(SharpenValue,0,0).awarpsharp(3,1,bm=3,cm=0,0.25).asharp(SharpenValue,0,0)
clp=clp.lanczos4resize(clp_x,clp_y)
tmp=clp
mask=clp.EdgeMask(8, 0, 0, 0,"special")
MaskedMerge (clp,tmp,mask)
}
GerSoft
24th June 2006, 12:35
(Exept for your pictures still showing some noticeable oversharpening.)
Yes, thats true. The pictures are taken from VirtualDub (no overlay mode)
I'm using this testscript to reencode with CCE. In the new mpeg file, u can't sea the oversharpen anymore.
But it would be great to fix this a better way.
Didée
24th June 2006, 14:18
"LimitedSharpen" and "SeaSaw" [..] are [..] very complex. (slow?)
Depends on what you call "complex". E.g. for LS, the plain core boils down to
upsize() # optional supersampling
sharpen().repair(last,1)
re-downsize()
which isn't too complex, I'd say. ;)
All the rest, which makes the script so long, is to give the user some options ... and all of these options are answers to questions of the kind
it would be great to fix this a better way
because that's the usual crux: a plain, simple method that shows promising potential, often has shortcomings because of its simplicity. And once one has taken sufficient care of all of the shortcomings to make the method really usable, the plain simple method has turned into a long and "complex" script ...
Then:
I wanted to use limitedsharpen but I allways get some strange edges like this (http://forum.doom9.org/showthread.php?t=87514&page=2).
I've found no way to fix this.
The "strange edges" as seen on the chair's border should NOT be produced by the original LimitedSharpen. (LimitedSharpen, used in sane range, will never produce anything like that!) They are produced by "a hacked version of LimitedSharpen", including some "hacked" versions of known filters. Could well be that those artefacts are related to all these "hacks" (about the nature of which we were left mostly alone in the dark, anyway), but I can't say for sure. It was mostly because of these "hacks" that I never confirmed that version of LimitedSharpen ... how could I, if I can't judge what's *really* in it. Still, the naming "LimitedSharpen2" may cause misconfusion. It does, as we see here, and I'm not all that pleased with such a situation.
OTOH, the kind of posterization that can be seen in the background of that screenshot - this is something that indeed might be produced by LimitedSharpen, too. That's one of the reasons why I implemented the new-style "soft" option in LS, which helps in not producing this kind of unnatural result.
But enough of that ... LimitedSharpen is not the topic here.
***
So I've tried to find an easy way to get the same effect. I'm shure the quality is not as good as limitedsharpen. The script is very easy, but I'm using the same idear. I'm newbe in scripting and using Avisynth, so I'm just proud of the result.
In fact, your script is much more similar to MSharpen than to LimitedSharpen. (Don: offside has been cancelled, your goal counts ;) )
What you script actually is doing is: to apply some sharpening, and copy the sharpened result only onto the edges of the source. This is more or less the MSharpen strategy, and does not prevent oversharpening. Plus, the mask you are using is not all that well suited for natural video content, since the mask of EdgeMask("special") tries to cover "1 pixel wide" edges, and is not continuous. Therefore it will cover some parts of some edges, but not the rest. That's why you see some "reduction of oversharpening" - because most edges are not covered fully, but only partly. The result, in this respect, is kind of random, however.
Get me right, I don't want to discourage you in any way. It's just that in the area of video filtering, poking-in-the-blue is not a fruitful strategy. (Mostly. Sometimes it is. ;) )
Generally, the flow of questions is s-th like
- what is the basic problem (to human's eye)
- what's the characteristics of this problem on a per-pixel level, so that
-- we can isolate the problematic areas by means of algorithms / basic filters / masks / whatever,
- how to treat the problematic areas so that we improve on the problem,
- look out whether the final improvement strategy may have other unwanted side effects.
For the given case (avoiding oversharpening), you could try for example:
- build a mask of the local range (min/max of pixel neighborhood)
- build mask how "extreme" the current pixel is (100% at min & at max, 0% at (min+max)/2 )
- apply the sharpening with an percentage of (100-extremety)
This has been tried, it's a method that can be used.
GerSoft
24th June 2006, 21:20
Wow,
what a post... I'll think i must register me to the german doom9 forum...
Yes, the Script is just a trie and test.
Masktools scripting is not so easy...
So the idear was to get the edges as mask....
Sharpen the original picture.
Then using the sharpen one and replace edges (+ 2 Pixel or more...) with the original picture.
Aber du hast recht. I realy don't know what exactly is detected by the mask.
So edgemask only detect edges (not all...but most)
and dedgemask detects the rest without edges ?? mhhhhh
So you think the script is not a good way to sharpen....
Didée
24th June 2006, 22:27
Ooops! Now I see the problem: the script is not doing what you want to do:
using the sharpen one and replace edges (+ 2 Pixel or more...) with the original picture
To do this, you need the variable "tmp" to contain the original input ... but you're assigning "tmp = clp" *after* all the sharpening filters that have been applied to "clp". Therefore, the final MaskedMerge effectively is doing nothing.
Corrected script, with slight improving on the edgemask (probably) :
function DEdgeSharpPP(clip clp,int "PixelPlus",float "SharpenValue")
{
SharpenValue=default (SharpenValue, 0.55)
PixelPlus=default (PixelPlus, 0)
clp_x=clp.width
clp_Y=clp.height
SharpenValue=SharpenValue + (0.0021 * Pixelplus)
tmp=clp
clp=clp.lanczos4resize(clp_x + PixelPlus,clp_Y + PixelPlus)
clp=clp.DeGrainMedian(limitY=2,limitUV=3,mode=1)
clp=clp.asharp(SharpenValue,0,0).awarpsharp(3,1,bm=3,cm=0,0.25).asharp(SharpenValue,0,0)
clp=clp.lanczos4resize(clp_x,clp_y)
mask=clp.EdgeMask(8, 0, 0, 0,"special") .expand().blur(1)
MaskedMerge (clp,tmp,mask)
}
... and in fact, the script is doing the exact *opposite* of what MSharpen is doing. ;)
GerSoft
24th June 2006, 23:17
You are right,
in the first script the "tmp" contained the original input.
i've testet this, but it was not working. ?????
I'll think, it's because the mask must be taken from the original clip to.
I'm just testing...
What tdo you think about this line:
clp=clp.asharp(SharpenValue,0,0).awarpsharp(3,1,bm=3,cm=0,0.25).asharp(SharpenValue,0,0)
Are you the same Didée as in the German forum ??
GerSoft
25th June 2006, 00:17
Yes that's it...
now it's working:
function DEdgeSharpPP(clip clp,int "PixelPlus",float "SharpenValue")
{
SharpenValue=default (SharpenValue, 0.62)
PixelPlus=default (PixelPlus, 0)
#-------------------------------------------------
clp_x=clp.width
clp_Y=clp.height
SharpenValue=SharpenValue + (0.0025 * Pixelplus)
#-------------------------------------------------
tmp=clp
mask=clp.EdgeMask(9, 0, 0, 0,"special").blur(1.5)
#-------------------------------------------------
clp=clp.lanczos4resize(clp_x + PixelPlus,clp_Y + PixelPlus)
clp=clp.DeGrainMedian(limitY=2,limitUV=3,mode=1)
clp=clp.asharp(SharpenValue,0,0).awarpsharp(3,1,bm=3,cm=0,0.25).asharp(SharpenValue,0,0)
clp=clp.lanczos4resize(clp_x,clp_y)
#-------------------------------------------------
MaskedMerge (clp,tmp,mask)
}
The mask must be taken from the original clip to. First i thought it would be better to take it after sharpen. But the mask was to big, the sharpen amplifies to much i think.
So the result was nothing...
The "Expand" is slow. So i just set a higher value to blur.
I think it's working great. What do you think ?
GerSoft
25th June 2006, 00:57
So, the speed test is ok. Supersampling is very slow. If there is any need i will try to use GPU-filters.
Without supersampling i can get 21 fps. (Sreenshot):rolleyes:
Soulhunter
25th June 2006, 09:23
They are produced by "a hacked version of LimitedSharpen", which in fact has little-to-nothing to do with LimitedSharpen, except for the name...
No? I just added a additional sharpening mode iirc, aSharp+aWarpSharp... And, aSaWLimitedSharpen was thought as a speedy SSXSharpen replacement (hence the thread title) and not for strong enhancement like it was done by Socio!
PS: Still waiting for a reply to my last PM ;P
Bye
Didée
25th June 2006, 12:29
Are you the same Didée as in the German forum
Yes.
The "Expand" is slow. So i just set a higher value to blur.
Switch over to MaskTools v2. "mt_expand" will run much faster than the old "expand".
And, while there are enough "dinosaur" scripts that use old MaskTools since Adam & Eve, any new scripts better should be done with MaskTools v2, anyways.
BTW, just blurring the mask without expanding isn't quite the same thing than with expanding. Look out for thin edges...
@ Soulhunter
Hmh, strange thing. It seems that over time, that "hack" in my mind has mutated into something evil that it never has been ... looking at the script again, it's indeed fully valid. (Edited above post.)
Sorry!
Still the original should not produce those strange edges. :)
Related...
See, I won't use any filters when it is not clear what *exactly* they are doing. For most of what I am scripting, I need filters where the results are *predictable*. The "try & see if it looks OK"-strategy is of little use for me. Like you can't put just some random pieces into the engine of a Formula-1 car. "Try & see" just won't work there. Instead, you need pieces with well-defined specifications.
There, it were some nebulous "hacked versions" of aSharp and aWarpSharp. Lately, we had e.g. frfun, doing some denoising, probably with some fractal-based algorithms, but giving no clue what actually is happening. Similar is gradfun2db (though there, one can at least guess what is happening, okay). And probably more of that kind to come.
Sure, you may throw candies into the crowd, and those frivolous who are starving for "just some sugar" will happily pick them up.
But there are also those few that care for a wholesome and well-balanced nutrition. And those won't pick up just anything that's lying on the ground.
Me, I don't use black boxes. (And, btw, have never been seen on anything like IRC.)
GerSoft
1st July 2006, 22:10
So, here is the new script...
http://forum.gleitz.info/showthread.php?t=28716
Backwoods
2nd July 2006, 23:15
Where can I grab that AVS Editor?
GerSoft
3rd July 2006, 21:03
The Editor is just very very Beta.
I just coded it to test my scripts...
I've got not enough time to finish it. I'm sorry...
Backwoods
3rd July 2006, 21:33
May I try the beta?
GerSoft
5th July 2006, 17:36
it only imports d2v. The Editor-box is not automated, you just must write the code.
The only thing that's implemented is to switch between the written script and a clean on to compare.
You will need the .Net Framework 2.0
vBulletin® v3.8.11, Copyright ©2000-2026, vBulletin Solutions Inc.