<?xml version="1.0"?>
<?xml-stylesheet type="text/css" href="http://avisynth.nl/skins/common/feed.css?303"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
		<id>http://avisynth.nl/index.php?action=history&amp;feed=atom&amp;title=MaskTools2%2Fmt_lut</id>
		<title>MaskTools2/mt lut - Revision history</title>
		<link rel="self" type="application/atom+xml" href="http://avisynth.nl/index.php?action=history&amp;feed=atom&amp;title=MaskTools2%2Fmt_lut"/>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=MaskTools2/mt_lut&amp;action=history"/>
		<updated>2026-04-07T14:40:36Z</updated>
		<subtitle>Revision history for this page on the wiki</subtitle>
		<generator>MediaWiki 1.19.24</generator>

	<entry>
		<id>http://avisynth.nl/index.php?title=MaskTools2/mt_lut&amp;diff=12055&amp;oldid=prev</id>
		<title>Reel.Deal: add documentation (v2.2.24)</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php?title=MaskTools2/mt_lut&amp;diff=12055&amp;oldid=prev"/>
				<updated>2020-07-27T20:23:34Z</updated>
		
		<summary type="html">&lt;p&gt;add documentation (v2.2.24)&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;{{FilterCat4|External_filters|Plugin_functions|Other_filters|Support_filters}}&lt;br /&gt;
== Description ==&lt;br /&gt;
mt_lut applies an expression to all the pixels of a mask / video.&lt;br /&gt;
&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== [[Script variables|Syntax and Parameters]] ==&lt;br /&gt;
&amp;lt;div style=&amp;quot;max-width:70em&amp;quot; &amp;gt;&lt;br /&gt;
:{{Template:FuncDef|mt_lut (clip, string &amp;quot;expr&amp;quot;, string &amp;quot;yExpr&amp;quot;, string &amp;quot;uExpr&amp;quot;, string &amp;quot;vExpr&amp;quot;, float &amp;quot;Y &amp;quot;, float &amp;quot;U&amp;quot;, float &amp;quot;V&amp;quot;, string &amp;quot;chroma&amp;quot;, int &amp;quot;offX&amp;quot;, int &amp;quot;offY&amp;quot;, int &amp;quot;w&amp;quot;, int &amp;quot;h&amp;quot;, bool &amp;quot;sse2&amp;quot;, bool &amp;quot;sse3&amp;quot;, bool &amp;quot;ssse3&amp;quot;, bool &amp;quot;sse4&amp;quot;, bool &amp;quot;avx&amp;quot;, bool &amp;quot;avx2&amp;quot;, float &amp;quot;A&amp;quot;, string &amp;quot;alpha&amp;quot;, string &amp;quot;paramscale&amp;quot;, bool &amp;quot;stacked&amp;quot;, bool &amp;quot;realtime&amp;quot;, string &amp;quot;aExpr&amp;quot;, string &amp;quot;scale_inputs&amp;quot;, bool &amp;quot;clamp_float&amp;quot;, int &amp;quot;use_expr&amp;quot;, bool &amp;quot;clamp_float_UV&amp;quot;)&lt;br /&gt;
}}&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2| |clip| }}&lt;br /&gt;
:::Input clip one.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|expr|string|&amp;quot;x&amp;quot;}}&lt;br /&gt;
::{{Par2|yExpr|string|&amp;quot;x&amp;quot;}}&lt;br /&gt;
::{{Par2|uExpr|string|&amp;quot;x&amp;quot;}}&lt;br /&gt;
::{{Par2|vExpr|string|&amp;quot;x&amp;quot;}}&lt;br /&gt;
:::Expression written is reverse polish notation.&lt;br /&gt;
:::If yexpr, uexpr or vexpr is noy defined, expr is used instead.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|Y|float|3}}&lt;br /&gt;
::{{Par2|U|float|2}}&lt;br /&gt;
::{{Par2|V|float|2}}&lt;br /&gt;
:::These values describe the actual processing mode that is to be used on each plane / channel. Here is how the modes are coded :&lt;br /&gt;
::::*x = -255...0 : all the pixels of the plane will be set to -x. (-255..0 range can of course differ when non-8 bit video formats are used) &lt;br /&gt;
::::*x = 1 : the plane will not be processed. That means the content of the plane after the filter is pure garbage.&lt;br /&gt;
::::*x = 2 : the plane of the first input clip will be copied.&lt;br /&gt;
::::*x = 3 : the plane will be processed with the processing the filter is designed to do.&lt;br /&gt;
:::U, V and A are defaulted to 2 (that way, the resulting clip contains the chroma (alpha) of clip1, and looks right).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|chroma|string|&amp;quot;&amp;quot;}}&lt;br /&gt;
:::When defined, the value contained in this string will overwrite the u &amp;amp; v processing modes.&lt;br /&gt;
:::This is a nice addition proposed by mg262 that makes the filter more user friendly. Allowed values for chroma are:&lt;br /&gt;
::::*&amp;quot;process&amp;quot; : set u = v = 3.&lt;br /&gt;
::::*&amp;quot;copy&amp;quot; or &amp;quot;copy first&amp;quot; : set u = v = 2.&lt;br /&gt;
::::*&amp;quot;xxx&amp;quot;, where xxx is a number : set u = v = -xxx.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|offX|int|0}}&lt;br /&gt;
::{{Par2|offY|int|0}}&lt;br /&gt;
:::{{Template:FuncDef3|offX}} and {{Template:FuncDef3|offY}} are the top left coordinates of the box where the actual processing shall occur. Everything outside that box will be garbage.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|w|int|-1}}&lt;br /&gt;
::{{Par2|h|int|-1}}&lt;br /&gt;
:::{{Template:FuncDef3|w}} and {{Template:FuncDef3|h}} are the width and height of the processed box. -1 means that the box extends to the lower right corner of the video. That also means that default settings are meant to process the whole picture.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|sse2|bool|true}}&lt;br /&gt;
::{{Par2|ssse3|bool|true}}&lt;br /&gt;
::{{Par2|sse4|bool|true}}&lt;br /&gt;
::{{Par2|avx|bool|true}}&lt;br /&gt;
::{{Par2|avx2|bool|true}}&lt;br /&gt;
:::CPU optimizations; for debugging only.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|Y|float|1}}&lt;br /&gt;
:::Same as the Y,U,V parameters but for the alpha channel, if applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|alpha|string|&amp;quot;&amp;quot;}}&lt;br /&gt;
:::Same as the chroma parameter but for the alpha channel, if applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|paramscale|string|&amp;quot;i8&amp;quot;}}&lt;br /&gt;
:::Same as the chroma parameter but for the alpha channel, if applicable.&lt;br /&gt;
:::Parameter &amp;quot;paramscale&amp;quot; for filters working with threshold-like parameters (v2.2.5-)&lt;br /&gt;
:::Filters: mt_binarize, mt_edge, mt_inpand, mt_expand, mt_inflate, mt_deflate, mt_motion, mt_logic, mt_clamp&lt;br /&gt;
:::paramscale can be &amp;quot;i8&amp;quot; (default), &amp;quot;i10&amp;quot;, &amp;quot;i10&amp;quot;, &amp;quot;i12&amp;quot;, &amp;quot;i14&amp;quot;, &amp;quot;i16&amp;quot;, &amp;quot;f32&amp;quot; or &amp;quot;none&amp;quot; or &amp;quot;&amp;quot;&lt;br /&gt;
:::Using &amp;quot;paramscale&amp;quot; tells the filter that parameters are given at what bit depth range.&lt;br /&gt;
:::By default paramscale is &amp;quot;i8&amp;quot;, so existing scripts with parameters in the 0..255 range are working at any bit depths&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|stacked|bool|false}}&lt;br /&gt;
:::[[Stack16]] format; not recommended, MaskTools2 supports native high bit-depth with AviSynth+.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|realtime|bool|false}}&lt;br /&gt;
:::Parameter &amp;quot;realtime&amp;quot; for lut-type filters to override default behaviour.&lt;br /&gt;
:::Slower but at least works on those bit depths where LUT tables would occupy too much memory.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|aExpr|string|&amp;quot;x&amp;quot;}}&lt;br /&gt;
:::Same as the expr, yExpr, uExpr, vExpr parameters but for the alpha channel, if applicable.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|scale_inputs|string|&amp;quot;none&amp;quot;}}&lt;br /&gt;
:::Autoscale any input (x,y,z,a) bit depths to 8-16 bit for internal expression use, the conversion method is either full range or limited YUV range. (Replaces clamp_f_i8, clamp_f_i10, clamp_f_i12, clamp_f_i14 or clamp_f_i16, clamp_f_f32 or clamp_f keywords)&lt;br /&gt;
&lt;br /&gt;
:::The primary reason of this feature is the &amp;quot;easy&amp;quot; usage of formerly written expressions optimized for 8 bits.&lt;br /&gt;
&lt;br /&gt;
:::Use:&lt;br /&gt;
&lt;br /&gt;
:::*&amp;lt;code&amp;gt;&amp;quot;int&amp;quot;&amp;lt;/code&amp;gt; : scales limited range videos, only integer formats (8-16bits) to 8 (or bit depth specified by 'i8'..'i16')&lt;br /&gt;
:::*&amp;lt;code&amp;gt;&amp;quot;intf&amp;quot;&amp;lt;/code&amp;gt; : scales full range videos, only integer formats (8-16bits) to 8 (or bit depth specified by 'i8'..'i16')&lt;br /&gt;
:::*&amp;lt;code&amp;gt;&amp;quot;float&amp;quot;&amp;lt;/code&amp;gt; or &amp;lt;code&amp;gt;&amp;quot;floatf&amp;quot;&amp;lt;/code&amp;gt; : only scales 32 bit float format to 8 bit range (or bit depth specified by 'i8'..'i16')&lt;br /&gt;
:::*&amp;lt;code&amp;gt;&amp;quot;floatUV&amp;quot;&amp;lt;/code&amp;gt; : affects the chroma plane expressions of 32 bit float formats. Shifts the input up by 0.5 before processing it in the expression, thus values from -0.5..0.5 (zero centered) range are converted to the 0..1 (0.5 centered) one. Since the expression result internally has 0..1.0 range, this then is shifted back to the original -0.5..0.5 range. (since 2.2.20) Note: predefined constants such as cmin, cmax, range_min, range_max and range_half will be shifted as well, e.g. the expression will see range_half = 0.5&lt;br /&gt;
:::*&amp;lt;code&amp;gt;&amp;quot;all&amp;quot;&amp;lt;/code&amp;gt; : scales videos to 8 (or bit depth specified by 'i8'..'i16') - conversion uses limited_range logic (mul/div by two's power)&lt;br /&gt;
:::*&amp;lt;code&amp;gt;&amp;quot;allf&amp;quot;&amp;lt;/code&amp;gt; : scales videos to 8 (or bit depth specified by 'i8'..'i16') - conversion uses full scale logic (stretch)&lt;br /&gt;
:::*&amp;lt;code&amp;gt;&amp;quot;none&amp;quot;&amp;lt;/code&amp;gt; : no magic&lt;br /&gt;
&lt;br /&gt;
:::Usually limited range is for normal YUV videos, full scale is for RGB or known-to-be-fullscale YUV.&lt;br /&gt;
&lt;br /&gt;
:::By default the internal conversion target is 8 bits, so old expressions written for 8 bit videos will probably work. This internal working bit-depth can be overwritten by the i8, i10, i12, i14, i16 specifiers.&lt;br /&gt;
&lt;br /&gt;
:::When using autoscale mode, scaleb, scalef, yscaleb and yscalef keywords are meaningless for 8-16 bits, because there is nothing to scale. 32 bit (float) values will be scaled however when &amp;quot;float&amp;quot;, &amp;quot;floatUV&amp;quot;, &amp;quot;all&amp;quot;, &amp;quot;allf&amp;quot; is specified.&lt;br /&gt;
&lt;br /&gt;
:::How it works:&lt;br /&gt;
&lt;br /&gt;
:::*This option scales (x,y,z,a) 8-32 bit inputs to a common bit depth value, which bit depth is 8 by default and can be set to 10, 12, 14 and 16 bits by the 'i10'..'i16' keywords For example: scale_inputs=&amp;quot;all&amp;quot; converts any inputs to 8 bit range. No truncation occurs however (no precision loss), because even a 16 bit data is converted to 8 bit in floating point precision, using division by 256.0 (2^16/2^8). So the conversion is not a simple shift-right-8 in the integer domain, which would lose precision.&lt;br /&gt;
&lt;br /&gt;
:::*Calculates expression&lt;br /&gt;
    &lt;br /&gt;
:::*Scales the result back to the output video bit depth. Clamping (clipping to valid range) and converting to integer occurs here.&lt;br /&gt;
&lt;br /&gt;
:::The predefined constants such as 'range_max', etc. will behave according to the internal working bit depth.&lt;br /&gt;
&lt;br /&gt;
:::Warning#1 This feature was created for easy porting earlier 8-bit-video-only expressions. You have to understand how it works internally.&lt;br /&gt;
&lt;br /&gt;
:::Let's see a 16bit input in &amp;quot;all&amp;quot; and &amp;quot;allf&amp;quot; mode (target is the default 8 bits)&lt;br /&gt;
&lt;br /&gt;
:::Limited range 16-&amp;gt;8 bits conversion has a factor of 1/256.0 (Instead of shift right 8 in integer domain, float-division is used or else it would lose presision) Full range 16-&amp;gt;8 bits conversion has a factor of 255.0/65535&lt;br /&gt;
&lt;br /&gt;
:::Using bit shifts (really it's division and multiplication by 2^8=256.0): result = calculate_lut_value(input / 256.0) * 256.0 Full scale 16-8-16 bit mode ('intf', 'allf') result = calculate_lut_value(input / 65535.0 * 255.0 ) / 255.0 * 65535.0&lt;br /&gt;
&lt;br /&gt;
:::Use scale_inputs = &amp;quot;all&amp;quot; (&amp;quot;int&amp;quot;, &amp;quot;float&amp;quot;) for YUV videos with 'limited' range e.g. in 8 bits: Y=16..235, UV=16..240). Use scale_inputs = &amp;quot;allf&amp;quot; (intf, floatf) for RGB or YUV videos with 'full' range e.g. in 8 bits: channels 0..255.&lt;br /&gt;
&lt;br /&gt;
:::When input is 32bit float, the 0..1.0 (luma) and -0.5..0.5 (chroma) channel is scaled to 0..255 (8 bits), 0..1023 (i10 mode), 0..4095 (i12 mode), 0..16383(i14 mode), 0..65535(i16 mode) then back.&lt;br /&gt;
&lt;br /&gt;
:::Warning#2 One cannot specify different conversion methods for converting before and after the expression. Neither can you specify different methods for different input clips (e.g. x is full, y is limited is not supported).&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|clamp_float|bool|false}}&lt;br /&gt;
:::32 bit float video is always a bit different, as usually no clamping is applied to valid ranges &lt;br /&gt;
:::This parameter along with clamp_float_UV changes this behaviour.&lt;br /&gt;
    &lt;br /&gt;
:::*&amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; : no clamp&lt;br /&gt;
:::*&amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; : standard clamp which is 0..1 for Luma or for RGB color space and -0.5..0.5 for YUV chroma UV chroma clamping can be set to 0..1 by using clamp_float_UV.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|use_expr|int|0}}&lt;br /&gt;
::: Use it when realtime calculation (interpreted pixel-by-pixel expression calculation) is slow and an appropriate AviSynth+ version (&amp;gt;r2712) is available.&lt;br /&gt;
&lt;br /&gt;
:::By sending the expression to the [[Expr]] filter in AviSynth+, lut filters can utilize a realtime JIT-compiled fast expression calculation.&lt;br /&gt;
&lt;br /&gt;
:::Possible values:&lt;br /&gt;
:::*0 : Uses lut and internal realtime calculation&lt;br /&gt;
:::*1 : Expr, when bit depth&amp;gt;=10 or lutxyza&lt;br /&gt;
:::*2 : When masktools would use realtime calc, passes the expressions and parameters to the &amp;quot;Expr&amp;quot; filter in AviSynth+&lt;br /&gt;
:::*3 : Expr, always passed (from 2.2.17)&lt;br /&gt;
&lt;br /&gt;
:::For modes 1, 2 and 3: Passes the expressions, &amp;quot;scale_inputs&amp;quot;, &amp;quot;clamp_float&amp;quot; and &amp;quot;clamp_float_UV&amp;quot; parameter to the &amp;quot;Expr&amp;quot; filter in AviSynth+&lt;br /&gt;
:::Note: clamp_float_UV is valid parameter only from AviSynth+ 3.5, and for compatibility reasons is passed only when it's true, so when it differs from the default value.&lt;br /&gt;
&lt;br /&gt;
:::Note #1: AviSynth+ internal precision is 32bit float, masktools2 is double (usually no difference can be seen)&lt;br /&gt;
:::Note #2: Some keywords (e.g. bit shift) are not available on AviSynth+&lt;br /&gt;
:::Note #3: Since &amp;quot;Expr&amp;quot; can work only on full sized clips, offX, offY, w and h parameters are ignored.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
::{{Par2|clamp_float_UV|bool|false}}&lt;br /&gt;
:::*&amp;lt;code&amp;gt;false&amp;lt;/code&amp;gt; : standard clamp which is 0..1 for Luma or for RGB color space and -0.5..0.5 for YUV chroma UV&lt;br /&gt;
:::*&amp;lt;code&amp;gt;true&amp;lt;/code&amp;gt; : chroma UV clamp same as luma 0..1, used in conjunction with expressions written for integer (positive only) U/V values in mind.&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
== Examples ==&lt;br /&gt;
Very similar to [[Histogram]](&amp;quot;Luma&amp;quot;)[https://forum.doom9.org/showthread.php?t=181511]:&lt;br /&gt;
 mt_lut(expr=&amp;quot;x 16 &amp;amp;u 17 x 15 &amp;amp;u - 1 x 15 &amp;amp;u + ? 14 *&amp;quot;, u=-128, v=-128) &lt;br /&gt;
&lt;br /&gt;
or for high bit depth:&lt;br /&gt;
 mt_lut (expr=&amp;quot;x 16 &amp;amp;u 17 x 15 &amp;amp;u - 1 x 15 &amp;amp;u + ? 14 *&amp;quot;, u=-128, v=-128, scale_inputs=&amp;quot;allf&amp;quot;) &lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
&amp;lt;br&amp;gt;&lt;br /&gt;
-----------------------------------------------&lt;br /&gt;
'''Back to [[MaskTools2#Filters|MaskTools2]] &amp;amp;larr;'''&lt;br /&gt;
-----------------------------------------------&lt;/div&gt;</summary>
		<author><name>Reel.Deal</name></author>	</entry>

	</feed>