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. |
23rd December 2011, 20:09 | #1 | Link |
The speed of stupid
Join Date: Sep 2011
Posts: 317
|
DetailSharpen -> Sharpening, now with less edges!
A quick (and perhaps pretty fast) filter that I cooked up some time ago.
Now I decided to make a function out of it, and voila. Example: Before/After (Str=6) Code:
function DetailSharpen(clip orig,int "str",int "thr") { # Another filter by, oh you guessed it, Bloax. # Requirements: RedAverage, RemoveGrain and ASharp. # A sharpening filter, that unlike usually, doesn't sharpen edges. # Instead it sharpens the details, and thus it avoids the classic haloing. # Not my idea of course, but anyways, enjoy. # "str" Is the sharpening strength. # "thr" Is the threshold for detecting edges. The higher, the more "edges" are caught, and less details are sharpened. # 5 Is the best value, because 4 starts sharpening edges, and 6 sharpens way too little. str = Default(str, 5) thr = Default(thr, 5) Threshold = Pow(2,thr) clp = orig.IsYV12() ? orig.ConvertToYV12() : orig msk=RAverageW(clp,Threshold,clp.RemoveGrain(19,-1),Threshold*-1,u=0,v=0,sse=8,bias=128).RemoveGrain(2,-1).Mt_Inpand(mode="both").Mt_Deflate() RMerge(clp,clp.ASharp(str,-1),msk) } Last edited by Bloax; 24th December 2011 at 15:24. |
23rd December 2011, 20:42 | #2 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
With all due respect for your enthusiasm for RedAverage.
But if you would use mt_edge for edge masking, you'd have better chances of your masking actually making sense.
__________________
- 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!) |
24th December 2011, 10:26 | #3 | Link |
The speed of stupid
Join Date: Sep 2011
Posts: 317
|
Well, maybe it's all because of my limited stuff to test it on.
But I can't find a case where Mt_Edge detects more edges that this, unless it's prewitt, which is way overkill. Not that they're useless, it's just that I'd like to have as many edges as possible, with the least non-edge coverage. Laplace is useless, Sobel is really thick and Roberts detects too many details before it's in the same league. But yeah, it's pretty much nonsense, but it works. I should probably add a bias control too. |
24th December 2011, 14:40 | #4 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
Maybe I've a different view or something, dunno ...
You want to sharpen much where edges are little, and sharpen little where edges are much? Here's a frame: Here's the mask from your script: Black= do nothing, white= do sharpen, gray= sharpen somewhat. The edges are excluded. But there are vast areas of non-edges that are black too, and don't get any sharpening though they should. And there's almost no "white", the majority is a 50% mask. There are some white spots getting full sharpening, but those spots are, well, random. Prewitt edge mask: This is an edge mask that maskes edges. Wanna some sharpening that causes no haloing, without any edge masking? Code:
mt_lutxy(o,o.removegrain(20),"x x y - abs 4 / 1 4 / ^ 4 * 1.51 * x y - x y - abs 1.001 + / * +",U=2,V=2) # 1.51 = "strength" multi Merry Christmas.
__________________
- 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!) |
24th December 2011, 15:26 | #5 | Link |
The speed of stupid
Join Date: Sep 2011
Posts: 317
|
That's certainly a nice lutxy function, too bad I have no idea what's the actual math. ("abs 4 / 1 4 / ^ 4 * str" is machine code to me.)
But anyways, I added a RemoveGrain(2,-1) to the mask, just to reduce the amount of random black dots. (Those are nasty.) |
24th December 2011, 17:19 | #8 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
Reverse polish notation is a form of notation that's easier to be machine-evaluated. Look at what Sapo84 posted above: can you immediately see the structure, which open/close brackets actually belong together, etc? Yeah, it's not that easy to read either....
The math behind is exactly the same, no matter if rev.polish or regular expression. If you speak math, you can use either form of expression. If you don't speak math, then regular expression is the same chinese as rev.polish. The above expression is a "gamma-style reduction term", a simplified version of what is used in SeeSaw. The idea simply is to amplify small differences stronger, amplify big differences not so strong. (Oversharpening usually occurs in areas where the blur operator causes rather "big" changes, which is always in the spots where local contrast is big to start with.) red: "linear sharpening" blue: "nonlinear sharpening" - small differences amplified more, big differences amplified less.
__________________
- 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; 24th December 2011 at 17:21. |
24th December 2011, 17:58 | #9 | Link | |
Avisynth language lover
Join Date: Dec 2007
Location: Spain
Posts: 3,431
|
Quote:
What is the purpose of the 1.001 - why not 1.0? |
|
24th December 2011, 19:26 | #10 | Link |
LaTo INV.
Join Date: Jun 2007
Location: France
Posts: 701
|
Some graphs of non linear sharpening here (used in LSFmod).
And you can use "edgemode=2" in LSFmod to sharpen only details and not edges. PS: Merry Christmas everyone Last edited by LaTo; 24th December 2011 at 19:32. |
24th December 2011, 20:05 | #11 | Link | |
Registered User
Join Date: Sep 2011
Posts: 86
|
Quote:
I can see that this is equivalent to "x + (((abs(x-y) * 64)^0.25) * 1.51) * ( (x - y) / (abs (x - y) + 1.001))" using infix, but I can barely use r.polish when there is a stack of numbers, algebraic simplification would fry my brain. Luckily there is an infix->r.polish function in the masktools library. |
|
24th December 2011, 22:39 | #12 | Link | ||
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
Quote:
Quote:
When set at 1.001, the next time I want to use 0.001, I need to edit only one char instead of the whole number.
__________________
- 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!) |
||
3rd October 2012, 16:46 | #15 | Link |
Warm and fuzzy
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
|
Didee
Bloax . Code:
mt_lutxy(o,o.removegrain(20),"x x y - abs 4 / 1 4 / ^ 4 * 1.51 * x y - x y - abs 1.001 + / * +",U=2,V=2) # 1.51 = "strength" multi Where could I put this string, see upper, to function DetailSharpen(...) ? . Bloax . Questions to you. What is Min, Max value of "Str" parameter in function DetailSharpen(...) ? What is Min, Max value of "Thr" parameter in function DetailSharpen(...) ?
__________________
Warm and fuzzy (white and fluffy) Last edited by Jenyok; 3rd October 2012 at 16:50. |
3rd October 2012, 19:06 | #16 | Link |
The speed of stupid
Join Date: Sep 2011
Posts: 317
|
The first is a separate function, as for the second question - Str goes 0 for disabled and is only practical up to about 6, or until you start to see some nasty haloed banding. (And you will.)
Thr is probably around 4-6 it seems, less if you can take the extra haloing, more is kind of pointless. |
5th October 2012, 05:11 | #17 | Link |
Warm and fuzzy
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
|
Bloax
. I need that more small details in video would be sharpened. Is parameter "THR = 2" ok for this reason in function DetailSharpen(...) ?
__________________
Warm and fuzzy (white and fluffy) |
5th October 2012, 05:16 | #18 | Link |
Warm and fuzzy
Join Date: Apr 2010
Location: Moscow, Russia
Posts: 201
|
Some changes for function SharpenDetail(clip orig, int "str", int "thr") .
. Code:
# # http://forum.doom9.org/showthread.php?t=163598 # # Function name DetailSharpen() is replaced by SharpenDetail() name function ... # function SharpenDetail(clip orig, int "str", int "thr") { # # Another filter by, oh you guessed it, Bloax. # Requirements: RedAverage, RemoveGrain and ASharp. # # A sharpening filter, that unlike usually, doesn't sharpen edges. # Instead it sharpens the details, and thus it avoids the classic haloing. # Not my idea of course, but anyways, enjoy. # # "str" Is the sharpening strength. # "thr" Is the threshold for detecting edges. The higher, the more "edges" are caught, and less details are sharpened. # Value 5 Is the best value, because 4 starts sharpening edges, and 6 sharpens way too little. # str = Default(str, 5) thr = Default(thr, 5) Threshold = Pow(2, thr) sse0 = 0 # change this constant for limits the processor capabilities. # -1 = use all (bitwise... 16, 8, 4 = SSE4.1, SSSE3, SSE2), # 0 = no asm, which is veeeeryyyy sloooow. clp = orig.IsYV12() ? orig.ConvertToYV12() : orig msk = RAverageW(clp, Threshold, clp.RemoveGrain(19, -1), (-1) * Threshold, u=0, v=0, sse=sse0, bias=128). \ RemoveGrain(2, -1).Mt_Inpand(mode="both").Mt_Deflate() return (RMerge(clp, clp.ASharp(str, -1), msk, sse=sse0)) # # for debugging only # # return (msk) # return (clp) }
__________________
Warm and fuzzy (white and fluffy) |
|
|