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 12th February 2008, 22:29   #1  |  Link
Comatose
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?
Comatose is offline   Reply With Quote
Old 12th February 2008, 23:04   #2  |  Link
AVIL
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")
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
AVIL is offline   Reply With Quote
Old 15th February 2008, 00:16   #3  |  Link
Comatose
Registered User
 
Join Date: Dec 2007
Posts: 639
Thanks!
Comatose is offline   Reply With Quote
Old 31st July 2011, 14:43   #4  |  Link
SilaSurfer
Registered User
 
SilaSurfer's Avatar
 
Join Date: Oct 2009
Posts: 212
Quote:
Originally Posted by AVIL View Post
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")
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
SilaSurfer is offline   Reply With Quote
Old 31st July 2011, 15:28   #5  |  Link
dansrfe
Registered User
 
Join Date: Jan 2009
Posts: 1,210
Quote:
Originally Posted by AVIL View Post
Code:
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...
dansrfe is offline   Reply With Quote
Old 1st August 2011, 03:28   #6  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
Join Date: Feb 2004
Posts: 1,348
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.
*.mp4 guy is offline   Reply With Quote
Old 1st August 2011, 13:37   #7  |  Link
SilaSurfer
Registered User
 
SilaSurfer's Avatar
 
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.
SilaSurfer is offline   Reply With Quote
Old 2nd August 2011, 11:59   #8  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
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.
*.mp4 guy is offline   Reply With Quote
Old 2nd August 2011, 13:08   #9  |  Link
SilaSurfer
Registered User
 
SilaSurfer's Avatar
 
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?
SilaSurfer is offline   Reply With Quote
Old 2nd August 2011, 14:50   #10  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
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
}
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:
Code:
InverseLimit(last, limitedsharpenfaster(),1, 0.5)
Code:
blurry = last
sharp = blurry.limitedsharpenfaster()
InverseLimit(blurry, sharp)
*.mp4 guy is offline   Reply With Quote
Old 2nd August 2011, 17:06   #11  |  Link
SilaSurfer
Registered User
 
SilaSurfer's Avatar
 
Join Date: Oct 2009
Posts: 212
Thanks Mp4Guy for all of your help.
SilaSurfer is offline   Reply With Quote
Old 2nd August 2011, 19:26   #12  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
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!)
Didée is offline   Reply With Quote
Old 2nd August 2011, 22:03   #13  |  Link
Nephilis
--preset WTF!
 
Join Date: Feb 2009
Posts: 86
Quote:
Originally Posted by Didée View Post
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?
Nephilis is offline   Reply With Quote
Old 2nd August 2011, 22:35   #14  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
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!)
Didée is offline   Reply With Quote
Old 3rd August 2011, 07:53   #15  |  Link
*.mp4 guy
Registered User
 
*.mp4 guy's Avatar
 
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.
*.mp4 guy is offline   Reply With Quote
Old 3rd August 2011, 16:34   #16  |  Link
SilaSurfer
Registered User
 
SilaSurfer's Avatar
 
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.
SilaSurfer is offline   Reply With Quote
Old 3rd August 2011, 16:58   #17  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
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!)
Didée is offline   Reply With Quote
Old 3rd August 2011, 20:36   #18  |  Link
Nephilis
--preset WTF!
 
Join Date: Feb 2009
Posts: 86
Quote:
Originally Posted by SilaSurfer View Post
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..
Nephilis 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 18:55.


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