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. |
12th February 2008, 22:29 | #1 | Link |
Registered User
Join Date: Dec 2007
Posts: 639
|
"Reverse" mt_edge?
Is there a way to create an edgemask that will ignore more defined edges?
I want to only sharpen weak lines, so I need to somehow set the threshold very low and then ignore the strong lines in the mask... is this possible? |
12th February 2008, 23:04 | #2 | Link |
Registered User
Join Date: Nov 2004
Location: Spain
Posts: 408
|
Hi,
I use this chain: Code:
clip.mt_edge(mode="prewitt",chroma="128",thy1=10,thy2=255).mt_lut(yexpr="x 0 > 256 x - 0 ?",chroma="copy") Good luck |
31st July 2011, 14:43 | #4 | Link | |
Registered User
Join Date: Oct 2009
Posts: 212
|
Quote:
Hello Sorry to bring this thread back, but I was wondering if anyone can explain a little bit how this works. I 'm still a novice at Masktools. TIA |
|
1st August 2011, 13:37 | #7 | Link |
Registered User
Join Date: Oct 2009
Posts: 212
|
I undserstand. Could one sharpen only the weak edges this way using Masktools and maybe later overlaying or merging that edgemask with the original source so at the end strong edges are left alone while the weak egdes are enhanced. I know this sounds a little bit out of the blue, but what I learned is that with Avisynth there are many possibilities.
|
2nd August 2011, 11:59 | #8 | Link |
Registered User
Join Date: Feb 2004
Posts: 1,348
|
Weak edges aren't usually edges. The problem I think is that the concept of an edge as seen by most edge detectors may be ill-formed. Its likely that higher order statistical models of correlation, direction and spatial isolation of discontinuities between areas of spatial or frequency domain correlation are needed to provide a robust enough line detector for this scenario.
Best case scenario for this code fragment would be to take an already well behaved sharpener, and use the mask as an additional limiter, so that 0=no sharpening, and 255=allow all sharpening. |
2nd August 2011, 13:08 | #9 | Link |
Registered User
Join Date: Oct 2009
Posts: 212
|
Thanks Mp4guy. That is actually what I had in mind. But I have no idea where to begin. Yesterday I just started reading through Masktools2 documentation and realized its not going to be that simple. Learning, testing, learning. Could you post a sample of what you proposed please, if it is not too much?
|
2nd August 2011, 14:50 | #10 | Link |
Registered User
Join Date: Feb 2004
Posts: 1,348
|
Code:
Function InverseLimit(clip not_sharpened, clip Sharpened, float "thr1", float "thr2") { thr1 = Default(thr1, 1) thr2 = Default(thr2, 0.5) Edge = not_sharpened.mt_edge(mode="prewitt",u=1, v=1,thy1=10,thy2=255)#.mt_lut(yexpr="x 0 > 256 x - 0 ?",u=1, v=1) Difference = mt_makediff(sharpened, not_sharpened, u=1, v=1) Limited_Difference = mt_lutxy(Difference, Edge, " x 128 - 1 y 0 > y "+string(thr2)+" ^ 1 - "+string(thr1)+" * 1 + 511 ? / * 128 + ", u=1, v=1) Output = mt_adddiff(not_sharpened, Limited_Difference, u=1, v=1).mergechroma(not_sharpened, 1) Output } example usage: Code:
InverseLimit(last, limitedsharpenfaster(),1, 0.5) Code:
blurry = last sharp = blurry.limitedsharpenfaster() InverseLimit(blurry, sharp) |
2nd August 2011, 19:26 | #12 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
Seven Years in the past, LimitedSharpen saw the light of the world, and had the "edgemode" parameter. edgemode=2 is pretty much what is discussed here. (Except for the 'edgevalue==0' case, which however is neglectable in most cases - if for a given pixel the edgevalue is zero, then a 3x3 sharpener will do nothing to that pixel anyway.)
__________________
- 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!) |
2nd August 2011, 22:03 | #13 | Link | |
--preset WTF!
Join Date: Feb 2009
Posts: 86
|
Quote:
edgemode=2 was a on/off parameter.. sharpen all or sharpen only edges or sharpen non-edge area only(=>edgemode=2) Also the edgemode2 was not adjustable.. right? |
|
2nd August 2011, 22:35 | #14 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
It's the same principle. Create edgemask, thereby masking the "strong" edges, then use sharpening for the not-masked areas. I.e. "exclude strong edges from sharpening", which is exactly what was asked for in the OP. (And that's what I was referring to. Not *mp4 guy's function.)
Two common mistakes, often made by those who are not so deep into scripting & filtering: a) consider to be difficult what in fact is simple b) consider to be simple what in fact is difficult
__________________
- 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 August 2011, 07:53 | #15 | Link |
Registered User
Join Date: Feb 2004
Posts: 1,348
|
The value I saw in creating the function is its stand alone nature and reasonably simple design should make experimentation with, and understanding of the principle easier. I must confess I agree with Didée in that I do not see any immediate practical use for it myself, but that's not why I wrote it.
On that note, I will try to write what the limiter does in plain english. The basic limiting principle is, if the edge magnitude is greater then zero, divide one by this magnitude and multiply the resulting number, which must be less then or equal to 1 with the difference created by the filter you are limiting. The thresholding is accomplished by directly raising the edge magnitude to the power of thr2, subtracting one, multiplying by thr1, then adding one again before 1 is divided by the modified edge magnitude, this gives some control of the limiting while ensuring that the limiting never results in increasing the effects of the underlying filter. Thinking on things now, the function would be much more useful if it accepted arbitrary edge detection masks as input as well, but it should be quite easy to deduce how to modify the script to do that. I was never trying to imply that such functionality was a needed addition to LSF. |
3rd August 2011, 16:34 | #16 | Link |
Registered User
Join Date: Oct 2009
Posts: 212
|
I asked for that script sample from Mp4guy, but not because I need to put in my next encode but rather because I'm interested in masktools. Of how much time I have on my hands when I'm not working I consider myself making a progress. As I said learning, testing, learning. My point of asking was "how" that can be done and not which script already has it.
Last edited by SilaSurfer; 3rd August 2011 at 16:37. |
3rd August 2011, 16:58 | #17 | Link |
Registered User
Join Date: Apr 2002
Location: Germany
Posts: 5,391
|
Okay, whatever.
I was about to note that the whole thing can be done without using explicit edgemasking at all, as can been seen in the SeeSaw script. But since you did not want to know "which script already has it", I respect you wish and won't mention it. You just reflect about possible relations between "edge magnitude" and "sharpening difference", then you'll surely discover it by yourself.
__________________
- 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 August 2011, 20:36 | #18 | Link | |
--preset WTF!
Join Date: Feb 2009
Posts: 86
|
Quote:
1- create a edge mask 2- sharpen all pixels in the frame 3- merge the non sharpened edge mask onto the sharpened frame Now you have a sharpened frame with non sharpened edges ;=) İf you wanna see how? then examine seesaw, mcgrmulti etc.. |
|
|
|