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 Development

Reply
 
Thread Tools Search this Thread Display Modes
Old 13th June 2010, 08:22   #321  |  Link
JEEB
もこたんインしたお!
 
JEEB's Avatar
 
Join Date: Jan 2008
Location: Finland / Japan
Posts: 512
Thank you, that indeed did help. I guess this is A) indeed intended behavior, and B) what I get from not RTFM'ing enough.
__________________
[I'm human, no debug]
JEEB is offline   Reply With Quote
Old 23rd July 2010, 05:37   #322  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
I'd like to know whether I'm correct in believing that mt_makediff is supposed to be commutative, so that this will produce the original input:
Code:
s=Source()
dn=s.Denoise()
df=mt_makediff(s,dn,chroma="process")
rn=mt_makediff(dn,df,chroma="process")
s+rn+df
However, when I do this, s is very different from rn. It might be saturating instead of wrapping, but the change is never more than +-20. Is this intended?

Last edited by foxyshadis; 23rd July 2010 at 05:41.
foxyshadis is offline   Reply With Quote
Old 23rd July 2010, 09:47   #323  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
mt_makediff is not commutative - what makes you think it should be? (Subtraction is not a commutative operation.)

Loosely speaking, df = s-dn+128 and rn = dn-df+128, ie dn+dn-s.
To reconstitute s, use mt_adddiff(df, dn).
(Or mt_adddiff(dn, df), since mt_adddiff is commutative.)
Gavino is offline   Reply With Quote
Old 23rd July 2010, 21:41   #324  |  Link
foxyshadis
ангел смерти
 
foxyshadis's Avatar
 
Join Date: Nov 2004
Location: Lost
Posts: 9,558
Ah, once I think through the math, it's obvious. Here I've been using mt_makediff as an equivalent to xor for ages now, because it looks close enough. That's my fault for not ever actually thinking all the way through it - I probably munged a few projects that way. Thanks.

Now of course there's mt_logic with a real xor.
foxyshadis is offline   Reply With Quote
Old 24th July 2010, 01:40   #325  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Quote:
Originally Posted by foxyshadis View Post
Now of course there's mt_logic with a real xor.
Depending on what exactly you want to to. All the "AND", "OR" / "XOR" of mt_logic are only well-defined for clips' values of [0] and [255]. For values [1,254], the behaviour isn't well-defined. After all, those are binary operators.

For general-case usage (i.e: difference clips), the equivalent of "OR" is "max", the equivalent of "AND" is "min". There is no equivalent for "XOR", since that doesn't make sense if the argument is a field/range of possible values.

(Slight possibility that Manao was aware and made AND/OR also working that way, I never actually checked. But per documentation, IIRC, AND/OR are really laid out for binary logic.)
__________________
- 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 24th July 2010, 09:12   #326  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by Didée View Post
All the "AND", "OR" / "XOR" of mt_logic are only well-defined for clips' values of [0] and [255]. For values [1,254], the behaviour isn't well-defined.
The documentation suggests they work bit-wise for all values [0,255].
It even uses pixel values of 11 and 5 as an example, eg for xor, 11 ^ 5 = 1011 ^ 101 = 1110 = 14.

Edit: I thought this conversation seemed familiar, and after some searching I found this.

Last edited by Gavino; 24th July 2010 at 09:28.
Gavino is offline   Reply With Quote
Old 7th September 2010, 13:44   #327  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
*Bump*

In store, a fix to a problem with mt_clamp and SSE2, pointed out by tp7 on IRC. I also implemented Bi11 proposal to mt_lutspa conundrum. There's now a "mode" parameter, which takes the positional place of the "relative" parameter, which is in turn, together with the "biased" parameter, moved further away and shouldn't be used anymore. Consequently, backward compatibility with named parameters is preserved, but is (yet again) broken with positional parameters.
__________________
Manao is offline   Reply With Quote
Old 9th September 2010, 00:50   #328  |  Link
TurboPascal7
Registered User
 
TurboPascal7's Avatar
 
Join Date: Jan 2010
Posts: 270
Looks like my first post here. ^^
Since I work a lot with HD video, I have a realy stupid question about scripts optimization.
Is there any possibility to replace mt_**pand with predefined custom modes (i.e. mt_square) with multiple calls of mt_**pand internally in masktools?
For example, in gradfun2dbmod, one can replace
Code:
mt_luts(input,input,mode="range",pixels=mt_square(radius),expr="y",u=1,v=1)
with something like
Code:
mt_lutxy(input.mt_expand(mode=mt_square(radius)),input.mt_inpand(mode=mt_square(radius)),"x y -",u=1,v=1)
(gives ~same speed as original), wich is equal to
Code:
mt_lutxy(input.mt_expand().mt_expand(),input.mt_inpand().mt_inpand(),"x y -",u=1,v=1)
(radius=2, about 10 times faster).
Works good, but without *for* statement totaly unoptimal and nonuniversal.
It's still possible to optimize script for some often usable modes, but it looks too silly for me.
Code:
GFmask = radius==1 ? input.mt_edge(mode="min/max",thY1=0,thY2=255,u=1,v=1)
\ : radius==2?    mt_lutxy(input.mt_expand().mt_expand(),input.mt_inpand().mt_inpand(),"x y -",u=1,v=1)
\ : radius==3?    mt_lutxy(input.mt_expand().mt_expand().mt_expand(),input.mt_inpand().mt_inpand().mt_inpand(),"x y -",u=1,v=1)
\ : radius==4?    mt_lutxy(input.mt_expand().mt_expand().mt_expand().mt_expand(),input.mt_inpand().mt_inpand().mt_inpand().mt_inpand(),"x y -",u=1,v=1)
\ : radius==5?    mt_lutxy(input.mt_expand().mt_expand().mt_expand().mt_expand().mt_expand(),input.mt_inpand().mt_inpand().mt_inpand().mt_inpand().mt_inpand(),"x y -",u=1,v=1)
\ :  mt_luts(input,input,mode="range",pixels=mt_square(radius),expr="y",u=1,v=1)
P.S. My english isn't so good as I want it to be, sorry about that.

Last edited by TurboPascal7; 9th September 2010 at 01:02.
TurboPascal7 is offline   Reply With Quote
Old 9th September 2010, 05:34   #329  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
There are no "for" statements, but you can still do recursive functions :
Code:
function mt_inpand_rec(clip c, int radius)
{
   return radius <= 0 ? c : radius <= 1 ? c.mt_inpand : mt_inpand_rec(c.mt_inpand, radius - 1)
}
Also, mode="range" is equivalent to "x y - abs", not "x y -".
__________________
Manao is offline   Reply With Quote
Old 9th September 2010, 05:45   #330  |  Link
TurboPascal7
Registered User
 
TurboPascal7's Avatar
 
Join Date: Jan 2010
Posts: 270
Oh, I haven't thought about recursion, my fault.
Quote:
Originally Posted by Manao View Post
Also, mode="range" is equivalent to "x y - abs", not "x y -".
is there any case when maximum value can be smaller then minimal value and x y - gives negative result?
TurboPascal7 is offline   Reply With Quote
Old 9th September 2010, 07:47   #331  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Quote:
is there any case when maximum value can be smaller then minimal value and x y - gives negative result?
Not really, unless it's very early in the morning and you just woke up
__________________
Manao is offline   Reply With Quote
Old 11th September 2010, 11:46   #332  |  Link
cretindesalpes
͡҉҉ ̵̡̢̛̗̘̙̜̝̞̟̠͇̊̋̌̍̎̏̿̿
 
cretindesalpes's Avatar
 
Join Date: Feb 2009
Location: No support in PM
Posts: 712
It made me think about two helper functions I wrote for this kind of task, and I thought that I could share them:

Code:
#=============================================================================
#	mt_expand_multi
#	mt_inpand_multi
#
#	Calls mt_expand or mt_inpand multiple times in order to grow or shrink
#	the mask from the desired width and height.
#
#	Parameters:
#	- sw   : Growing/shrinking shape width. 0 is allowed. Default: 1
#	- sh   : Growing/shrinking shape height. 0 is allowed. Default: 1
#	- mode : "rectangle" (default), "ellipse" or "losange". Replaces the
#		mt_xxpand mode. Ellipses are actually combinations of
#		rectangles and losanges and look more like octogons.
#		Losanges are truncated (not scaled) when sw and sh are not
#		equal.
#	Other parameters are the same as mt_xxpand.
#=============================================================================

Function mt_expand_multi (clip src, int "thY", int "thC", string "mode",
\	int "offx", int "offy", int "w", int "h", int "y", int "u", int "v",
\	string "chroma", int "sw", int "sh")
{
	sw   = Default (sw, 1)
	sh   = Default (sh, 1)
	mode = Default (mode, "rectangle")

	mode_m =
\	  (sw > 0 && sh > 0) ? (
\		  (mode == "losange" || (mode == "ellipse" && (sw % 3) != 1))
\		? "both" : "square"
\	                       )
\	: (sw > 0          ) ? "horizontal"
\	: (          sh > 0) ? "vertical"
\	:                      ""

	(mode_m != "") ? src.mt_expand (
\		thY=thY, thC=thC, mode=mode_m,
\		offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma
\	).mt_expand_multi (
\		thY=thY, thC=thC, mode=mode,
\		offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma,
\		sw=sw-1, sh=sh-1
\	) : src
}

Function mt_inpand_multi (clip src, int "thY", int "thC", string "mode",
\	int "offx", int "offy", int "w", int "h", int "y", int "u", int "v",
\	string "chroma", int "sw", int "sh")
{
	sw   = Default (sw, 1)
	sh   = Default (sh, 1)
	mode = Default (mode, "rectangle")

	mode_m =
\	  (sw > 0 && sh > 0) ? (
\		  (mode == "losange" || (mode == "ellipse" && (sw % 3) != 1))
\		? "both" : "square"
\	                       )
\	: (sw > 0          ) ? "horizontal"
\	: (          sh > 0) ? "vertical"
\	:                      ""

	(mode_m != "") ? src.mt_inpand (
\		thY=thY, thC=thC, mode=mode_m,
\		offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma
\	).mt_inpand_multi (
\		thY=thY, thC=thC, mode=mode,
\		offx=offx, offy=offy, w=w, h=h, y=y, u=u, v=v, chroma=chroma,
\		sw=sw-1, sh=sh-1
\	) : src
}
Though I don't know if the "common" parameters are in the right order (I'm too lazy to check the mt source code).
__________________
dither 1.28.1 for AviSynth | avstp 1.0.4 for AviSynth development | fmtconv r30 for Vapoursynth & Avs+ | trimx264opt segmented encoding
cretindesalpes is offline   Reply With Quote
Old 21st September 2010, 17:51   #333  |  Link
yup
Registered User
 
Join Date: Feb 2003
Location: Russia, Moscow
Posts: 854
Hi all!
I want organize following calculation:
source data
prefiltered prefiltered clip
3 masks center, backward and forward,
3 filtered clip centerfiltered, backwardfiltered and forwardfiltered
output=prefiltered
if (center<backward)&(center<forward) then output=centerfiltered
if (backward<center)&(backward<forward) then output=backwardfiltered
if (forward<bacward)&(forward<center) then output=forwardfiltered
Can this make using masktools?
Please advice.
yup.
yup is offline   Reply With Quote
Old 21st September 2010, 18:17   #334  |  Link
Didée
Registered User
 
Join Date: Apr 2002
Location: Germany
Posts: 5,389
Sure, that can be done. But sorry, the description of the chain is not clear enough.

- you create "3 masks center, backward and forward", but don't explain what is done with those masks

- how exactly are centerfiltered, backwardfilterd and forwardfiltered created? (Probably with the three masks from above...)

- what means "(center<backward)" etc.? Do you mean "pixel value is smaller"? Or rather "difference to prefiltered", or "difference to source", or ...

For "pixel value is smaller", you can use mt_logic(mode="min"). If it's really the difference-to-something, then you can use the Corrector() plugin.
__________________
- 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 22nd September 2010, 04:54   #335  |  Link
yup
Registered User
 
Join Date: Feb 2003
Location: Russia, Moscow
Posts: 854
@Didée
It is very long story, hope you remember
http://forum.doom9.org/showthread.php?t=121197
3 masks center, backward and forward is min SAD value from both predictors (for center is backward1 and forward1, for backward backward1 and backward2, for forward forward1 and forward2 )
centerfiltered is median from 3 value center, backward and forward predictors.
backwardfiltered is median from 3 value center, backward and backward2 predictors.
forwardfiltered in a similar.
center<backward mean less by value and this try find better motion predictor from 3 variants.
yup.
yup is offline   Reply With Quote
Old 24th September 2010, 08:04   #336  |  Link
yup
Registered User
 
Join Date: Feb 2003
Location: Russia, Moscow
Posts: 854
I think need use cascade mt_lutxyz

if (center<backward)&(center<forward) then output=centerfiltered

masktools equivalent

mt_lutxyz(center,backward,forward,'x y < x z < &')
output=mt_lutxy(last,centerfiltered,output, 'x y z?')

Please advice.
yup.

Last edited by yup; 25th September 2010 at 05:56. Reason: uderstanding how work if operator
yup is offline   Reply With Quote
Old 21st November 2010, 17:23   #337  |  Link
Manao
Registered User
 
Join Date: Jan 2002
Location: France
Posts: 2,856
Yet another bugfix, which concerns mt_lutf and "std" mode. Thanks again to TurboPascal7 for pointing out the bug.
__________________
Manao is offline   Reply With Quote
Old 1st December 2010, 11:57   #338  |  Link
kypec
User of free A/V tools
 
kypec's Avatar
 
Join Date: Jul 2006
Location: SK
Posts: 826
Quote:
Originally Posted by Manao View Post
Yet another bugfix, which concerns mt_lutf and "std" mode. Thanks again to TurboPascal7 for pointing out the bug.
The download link in your first page still points to v2.0a45, please update it as well, thanks.
kypec is offline   Reply With Quote
Old 6th December 2010, 15:40   #339  |  Link
ChrisBeringB
Registered User
 
Join Date: Nov 2010
Posts: 14
How are the luts organized?
I'm asking because I'm worried about CPU cache locality.

Considering 'mask' is 99% zeros, which is better, speedwise:
a: MT_Lutxyz(mask, frame1, frame2, yexpr="some expression f(x,y,z)")
b: MT_Lutxyz(frame2, mask, frame1, yexpr="some expression f(y,z,x)")
c: MT_Lutxyz(frame1, frame2, mask, yexpr="some expression f(z,x,y)")

Same question could be asked for MT_Lutxy, but since the lut is small, it's not a big deal.

In the same vein, while trying to measure the speed difference, I noticed x264 didn't give exactly the same output for options a,b,c.
This suggests a fundamental bug.

Chris
ChrisBeringB is offline   Reply With Quote
Old 6th December 2010, 16:41   #340  |  Link
Gavino
Avisynth language lover
 
Join Date: Dec 2007
Location: Spain
Posts: 3,431
Quote:
Originally Posted by ChrisBeringB View Post
a: MT_Lutxyz(mask, frame1, frame2, yexpr="some expression f(x,y,z)")
b: MT_Lutxyz(frame2, mask, frame1, yexpr="some expression f(y,z,x)")
c: MT_Lutxyz(frame1, frame2, mask, yexpr="some expression f(z,x,y)")
...
I noticed x264 didn't give exactly the same output for options a,b,c.
This suggests a fundamental bug.
Perhaps just a typo, but you seem to have the expressions for b and c the wrong way round: b should be f(z,x,y) and c should be f(y,z,x). That might explain why you get different results.
__________________
GScript and GRunT - complex Avisynth scripting made easier
Gavino 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 16:21.


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