<?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/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Chanijean</id>
		<title>Avisynth wiki - User contributions [en]</title>
		<link rel="self" type="application/atom+xml" href="http://avisynth.nl/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=Chanijean"/>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php/Special:Contributions/Chanijean"/>
		<updated>2026-06-05T05:59:34Z</updated>
		<subtitle>User contributions</subtitle>
		<generator>MediaWiki 1.19.24</generator>

	<entry>
		<id>http://avisynth.nl/index.php/GeneralConvolution</id>
		<title>GeneralConvolution</title>
		<link rel="alternate" type="text/html" href="http://avisynth.nl/index.php/GeneralConvolution"/>
				<updated>2018-10-06T20:02:15Z</updated>
		
		<summary type="html">&lt;p&gt;Chanijean: /* External Links */ link is back up :^)&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;Performs a matrix convolution on an [[RGB32]] clip.&lt;br /&gt;
&lt;br /&gt;
== Syntax and Parameters ==&lt;br /&gt;
&amp;lt;div style=&amp;quot;max-width:68em&amp;quot; &amp;gt;&lt;br /&gt;
{{Template:FuncDef&lt;br /&gt;
|GeneralConvolution (clip ''clip'', [ int ''bias'', string ''matrix'', float ''divisor'', bool ''auto'' ] )&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
:{{Par2|clip|clip|}}&lt;br /&gt;
::Source clip. Must be [[RGB32]].&lt;br /&gt;
&lt;br /&gt;
:{{Par2|bias|int|0}}&lt;br /&gt;
::Additive bias to adjust the total output intensity.&lt;br /&gt;
&lt;br /&gt;
:{{Par2|matrix|string|&amp;quot;0 0 0 0 1 0 0 0 0&amp;quot;}}&lt;br /&gt;
::A 3×3 or 5×5 matrix with 3&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (9) or 5&amp;lt;sup&amp;gt;2&amp;lt;/sup&amp;gt; (25) integer values.&lt;br /&gt;
&lt;br /&gt;
:{{Par2|divisor|float|1.0}}&lt;br /&gt;
::Divides the output of the convolution before adding {{FuncArg|bias}}.&lt;br /&gt;
&lt;br /&gt;
:{{Par2|auto|bool|true}}&lt;br /&gt;
::Enables ''auto scaling''. Auto scaling divides the output of the convolution by the sum of the elements of the matrix. The value of {{FuncArg|divisor}} is applied in addition to this auto scaling factor. If the sum of elements is zero, auto scaling is disabled.&lt;br /&gt;
&lt;br /&gt;
The {{FuncArg|divisor}} is usually the sum of the elements of the matrix. But when the sum is zero, you can leave {{FuncArg|divisor}}=1 and use the {{FuncArg|bias}} setting to correct the pixel values. The {{FuncArg|bias}} could be useful if the pixel values are negative due to the convolution. After adding {{FuncArg|bias}}, the pixels are clipped to the range 0-255.&lt;br /&gt;
&lt;br /&gt;
Around the borders the edge pixels are simply repeated to service the matrix.&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Examples ==  &lt;br /&gt;
* Blur:&lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(0, &amp;quot;&lt;br /&gt;
    10 10 10 10 10&lt;br /&gt;
    10 10 10 10 10 &lt;br /&gt;
    10 10 16 10 10 &lt;br /&gt;
    10 10 10 10 10 &lt;br /&gt;
    10 10 10 10 10 &amp;quot;, 256, false)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Horizontal (Sobel) edge detection: &lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(0, &amp;quot;&lt;br /&gt;
     1  2  1 &lt;br /&gt;
     0  0  0 &lt;br /&gt;
    -1 -2 -1 &amp;quot;, 8)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Vertical (Sobel) Edge Detection: &lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(0, &amp;quot;&lt;br /&gt;
    1  0 -1 &lt;br /&gt;
    2  0 -2 &lt;br /&gt;
    1  0 -1 &amp;quot;, 8)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Displacement (simply move the position of the &amp;quot;1&amp;quot; for left, right, up, down)&lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(0, &amp;quot;&lt;br /&gt;
    0 1 0 &lt;br /&gt;
    0 0 0 &lt;br /&gt;
    0 0 0 &amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Displacement by half pixel up (auto scaling):&lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(0, &amp;quot;&lt;br /&gt;
    0   1   0 &lt;br /&gt;
    0   1   0 &lt;br /&gt;
    0   0   0 &amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Displacement by half pixel to the right (manual scaling):&lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(0, &amp;quot;&lt;br /&gt;
    0   0   0&lt;br /&gt;
    0 128 128&lt;br /&gt;
    0   0   0 &amp;quot;, 256, false)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Sharpness filter:&lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(0, &amp;quot;&lt;br /&gt;
    0   -1   0 &lt;br /&gt;
   -1    5  -1 &lt;br /&gt;
    0   -1   0 &amp;quot;, 0, true)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
:In this case, the new pixel values &amp;lt;span style=&amp;quot;font-family:times,georgia,serif;&amp;quot;&amp;gt;y(m,n)&amp;lt;/span&amp;gt; are given by&lt;br /&gt;
:&amp;lt;span style=&amp;quot;font-family:times,georgia,serif;&amp;quot;&amp;gt;y(m,n) = ( -1*x(m-1,n) - 1*x(m,n-1) + 5*x(m,n) - 1*x(m,n+1) - 1*x(m+1,n) )/1.0 + 0&amp;lt;/span&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Slight blur filter with black level clipping and 25% brightening:&lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(-16, &amp;quot;&lt;br /&gt;
    0   12   0&lt;br /&gt;
   12  256  12&lt;br /&gt;
    0   12   0 &amp;quot;, 0.75 ,true)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
:In this case, the new pixel values &amp;lt;span style=&amp;quot;font-family:times,georgia,serif;&amp;quot;&amp;gt;y(m,n)&amp;lt;/span&amp;gt; are given by&lt;br /&gt;
:&amp;lt;span style=&amp;quot;font-family:times,georgia,serif;&amp;quot;&amp;gt;y(m,n) = ( 12*x(m-1,n) + 12*x(m,n-1) + 256*x(m,n) + 12*x(m,n+1) + 12*x(m+1,n) )/(12+12+256+12+12)/0.75 - 16&amp;lt;/span&amp;gt;&lt;br /&gt;
{{HalfBreak}}&lt;br /&gt;
* Emboss filter (3D relief effect)&lt;br /&gt;
&amp;lt;div {{BoxWidthIndent|28|2}} &amp;gt;&lt;br /&gt;
 GeneralConvolution(128, &amp;quot;&lt;br /&gt;
 -1 0 0&lt;br /&gt;
  0 0 0&lt;br /&gt;
  0 0 1&amp;quot;)&lt;br /&gt;
&amp;lt;/div&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== External Links ==&lt;br /&gt;
* [https://jeanbruenn.info/2011/03/13/avisynths-convolution-stuff-explained/ ''AviSynth’s GeneralConvolution explained'']&lt;br /&gt;
* Some other examples can be found [http://web.archive.org/web/20100105183639/http://www.gamedev.net/reference/programming/features/imageproc/page2.asp here].&lt;br /&gt;
&lt;br /&gt;
== Changelog ==&lt;br /&gt;
{| border=&amp;quot;1&amp;quot;&lt;br /&gt;
|- &lt;br /&gt;
| v2.55&lt;br /&gt;
| Added divisor, auto.&lt;br /&gt;
|- &lt;br /&gt;
| v2&lt;br /&gt;
| Initial Release&lt;br /&gt;
|}&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
[[Category:Internal filters]]&lt;br /&gt;
[[Category:Blurring]]&lt;br /&gt;
[[Category:Sharpeners]]&lt;/div&gt;</summary>
		<author><name>Chanijean</name></author>	</entry>

	</feed>