PDA

View Full Version : "Reverse" mt_edge?


Comatose
12th February 2008, 22:29
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?

AVIL
12th February 2008, 23:04
Hi,

I use this chain:

clip.mt_edge(mode="prewitt",chroma="128",thy1=10,thy2=255).mt_lut(yexpr="x 0 > 256 x - 0 ?",chroma="copy")

mt_lut reverses prewitt detection, so the more strong is the edge, the less is their final influence (except flat areas that are neglected in all the cases).

Good luck

Comatose
15th February 2008, 00:16
Thanks!

SilaSurfer
31st July 2011, 15:43
Hi,

I use this chain:

clip.mt_edge(mode="prewitt",chroma="128",thy1=10,thy2=255).mt_lut(yexpr="x 0 > 256 x - 0 ?",chroma="copy")

mt_lut reverses prewitt detection, so the more strong is the edge, the less is their final influence (except flat areas that are neglected in all the cases).



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

dansrfe
31st July 2011, 16:28
clip.mt_edge(mode="prewitt",chroma="128",thy1=10,thy2=255).mt_lut(yexpr="x 0 > 256 x - 0 ?",chroma="copy")

I'm very interested in this as well...

*.mp4 guy
1st August 2011, 04:28
If mt_edge detects an edge (output does not equal 0) then its 8 bit magnitude becomes reversed, a "strength" 5 edge becomes 250, and 250 would become 5.

SilaSurfer
1st August 2011, 14:37
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.

*.mp4 guy
2nd August 2011, 12:59
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.

SilaSurfer
2nd August 2011, 14:08
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?

*.mp4 guy
2nd August 2011, 15:50
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
}

Raising thr1 increases the amount of limiting applied to strong edges linearly, decreasing does the opposite. Raising thr2 increases the limiting of strong edges exponentially, decreasing does the opposite.

example usage:InverseLimit(last, limitedsharpenfaster(),1, 0.5)blurry = last
sharp = blurry.limitedsharpenfaster()
InverseLimit(blurry, sharp)

SilaSurfer
2nd August 2011, 18:06
Thanks Mp4Guy for all of your help.;)

Didée
2nd August 2011, 20:26
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.)

Nephilis
2nd August 2011, 23:03
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.)

IMO the only diffrerence is;
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?

Didée
2nd August 2011, 23:35
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

*.mp4 guy
3rd August 2011, 08:53
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.

SilaSurfer
3rd August 2011, 17:34
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.

Didée
3rd August 2011, 17:58
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. :)

Nephilis
3rd August 2011, 21:36
My point of asking was "how" that can be done and not which script already has it.

Basicly;

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..