Log in

View Full Version : mt_lutxy


lisztfr9
11th May 2012, 15:07
Hi,

I can't get started with this function...

mt_lutxy

mt_lutxy : clip clip1, clip clip2, string expr("x"), string yexpr("x"), string uexpr("x"), string vexpr("x")

It applies a two-parameters function defined by expr to all the pixels. The function is written is reverse polish notation.
If yexpr, uexpr or vexpr isn't defined, expr is used instead.

1) How pixels of the clip 2 are used for calculation ?

- expr("x")

I guess the other expressions applies to Y, U, V ?

mt_lutxy(o,g,"x x y - abs "+string(z)+" / 1 "+string(pow)+" / ^ "+string(z)+" * "+string(str)+
\ " * x y - 2 ^ x y - 2 ^ "+string(ldmp)+" + / * x y - x y - abs 0.001 + / * +",U=2,V=2)


Ok, i know what reverse polish notation is, but i'm unable to understand this. It would be nice to have at least 1 example somewhere, to start with, explaining how the function is working on a simple task....

x y looks like Cartesian coordinates...

what does x x y ?

* x y - 2 ^ x y - 2 where comes clip2 in calculation ... ?

reverse notation, why is the * before the x, y :

* x y - x y ?

TIA, L

lisztfr9
11th May 2012, 15:26
mt_average

mt_average : clip clip1, clip clip2

Equivalent to mt_lutxy("x y + 2 /"), but faster.

Ok, this is x + y / 2.

Gavino
11th May 2012, 16:39
How pixels of the clip 2 are used for calculation ?
For each pixel, the output value is calculated from the relevant expression, with x as the value of the pixel in clip1 and y the pixel in clip2.

For RPN, see http://en.wikipedia.org/wiki/Reverse_Polish_notation.

Note also the functions mt_polish and mt_infix for converting between RPN and 'normal' (infix) expression form.

lisztfr9
12th May 2012, 09:46
Ok, but why is it so confusing ?

because this is not RPN :

(o,g,"x x y - abs "+string(z)+"

The first "x" must belong to the syntax of the function, but seems also be a part of an RPN expression.

But for being RPN, it would need 2 operators behind, where there is only 1.

Also, there are 2 levels of quotes, around variables and around expressions ! The "abs" statement, applies to a parameter inside quotes, which usually enclose strings variables.

And finally, x y usually refer to coordinated along X and Y axis in a plan...

Gavino
12th May 2012, 10:55
this is not RPN :

(o,g,"x x y - abs "+string(z)+"

The first "x" must belong to the syntax of the function, but seems also be a part of an RPN expression.

But for being RPN, it would need 2 operators behind, where there is only 1.

Also, there are 2 levels of quotes, around variables and around expressions ! The "abs" statement, applies to a parameter inside quotes, which usually enclose strings variables.
The added source of confusion here is that the expression string is being constructed dynamically by string concatenation. This is necessary because it needs to include the literal value of 'z' which is a script variable, so the string() function is used. Similarly for the other variables in the original expression.

You cannot in general make sense of a fragment of RPN without considering the whole string. The operator that goes with a particular operand may be much further on in the string.

And finally, x y usually refer to coordinated along X and Y axis in a plan...
They have that interpretation in mt_lutspa, but forget that here - in mt_lutxy, they refer to the pixels from the two clips.

StainlessS
12th May 2012, 17:34
For anyone wanting to play with RPN, there is a FreeWare RPN calculator Excalibur v2.00
(from 2006), have not as yet played with it much but it looks quite good.
Below from text on SoftPedia (home site no longer on-line).


Excalibur description
A full featured RPN-only calculator

The Excalibur application was designed to be a full featured RPN-only calculator. This is a serious calculator for serious users.
Excalibur takes up a small amount of resources for all it does so well.

Here are some key features of "Excalibur":

· Powerful RPN entry. 300 Functions (scientific, business, conversion, computer science, physics, complex numbers, geometry, vectors, etc).
Full 4 or 8-level stack.
· International support for different comma and decimal point formats. Programmable, macros, registers, custom button banks, etc.


http://www.softpedia.com/get/Science-CAD/Excalibur.shtml

06_taro
12th May 2012, 17:39
mt_polish( any_infix_notation ) returns reverse polish notation
mt_infix( any_rpn ) returns infix notation
e.g., mt_lutxy(a, b, "x y +") equals to mt_lutxy(a, b, mt_polish("x + y"))

Overdrive80
12th May 2012, 18:17
mt_polish( any_infix_notation ) returns reverse polish notation
mt_infix( any_rpn ) returns infix notation
e.g., mt_lutxy(a, b, "x y +") equals to mt_lutxy(a, b, mt_polish("x + y"))

If I only use mt_polish("x + y"), will shows it in screen infix result??? Or I would need other more function as subtitle(....)?

Regards

Gavino
12th May 2012, 18:40
If I only use mt_polish("x + y"), will shows it in screen infix result??? Or I would need other more function as subtitle(....)?
mt_polish() returns a string, so if you want to see it on the screen you can use Subtitle(mt_polish("x + y")).

Note that you can get away with never learning RPN at all and just use mt_polish("...") instead for your expressions.
I don't know why more people don't use it in published scripts - it's much easier to understand.

Overdrive80
12th May 2012, 19:08
Thanks Gavino.

lisztfr9
13th May 2012, 14:38
Thanks to all.

ScriptClip("""subtitle("<other_variable>" + string(mt_polish("x + y")))""")

(many quotes...)

Subtitle(last, mt_polish("x + y"),10, 20)

Gavino
13th May 2012, 14:59
ScriptClip("""subtitle("<other_variable>" + string(mt_polish("x + y")))""")
Not sure if you were asking a question there.

string() is unnecessary as mt_polish already returns a string.
ScriptClip() is also unnecessary unless the other variable involves some run-time function.