Reformer

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Reformer: update documentation to match Reformer)
 
(5 intermediate revisions by one user not shown)
Line 1: Line 1:
 
+
{{FilterCat4|External_filters|Plugins|Adjustment_filters|Transformation}}
{{FilterCat4|External_filters|Plugins|<!-- category -->TODO|<!-- category -->TODO}}
+
 
+
 
{{Filter3
 
{{Filter3
|1=<!-- author --> [http://www.avisynth.nl/users/vcmohan/ V.C.Mohan]
+
|1={{Author/vcmohan}}
|2=<!-- version --> 9 Apr 2018
+
|2=14 Oct 2015
|3=<!-- URL --> [http://www.avisynth.nl/users/vcmohan/movePlus/movePlus.7z movePlus.7z]
+
|3=[http://www.avisynth.nl/users/vcmohan/Reformer/Reformer_2_6.zip Reformer_2_6.zip]
|4=<!-- category --> External filters
+
|4=Transformation
|5=<!-- license --> [https://www.gnu.org/licenses/gpl-2.0.txt GPLv2]
+
|5=[https://www.gnu.org/licenses/gpl-2.0.txt GPLv2]
|6=<!-- discussion URL -->[https://forum.doom9.org/showthread.php?t=166716&highlight=Reformer Reformer plugin]}}
+
|6=[https://forum.doom9.org/showthread.php?t=166716 Doom9 Forum]}}
 
+
 
<br>
 
<br>
 
== Description ==
 
== Description ==
<!-- a one-sentence description -->
+
[[Reformer]] can be used to correct skewed images or vice versa. Useful if video is recorded with incorrectly located camera or for transitions or effects.
Reform uses matrix algebra for transformations. Reform has two modes viz: rectangle to quadrilateral and quadrilateral to rectangle. Lanczos or cubic or linear or nearest point interpolation methods can be opted. [http://www.avisynth.nl/users/vcmohan/movePlus/Reform.html Full Description]
+
 
 +
This plugin probably is better suited than the [[Reform]] plugin as it performs much better even if the rectangle is rotated by 90 degrees. Reform fails in such a situation. This Reformer uses matrix algebra for transformations unlike Reform which does a geometric transform.
 +
 
 +
[[Reformer]] has two functions:  
 +
 
 +
*<code>r2q</code> transforms a rectangle to a quadrilateral.
 +
 
 +
*<code>q2r</code> transforms a quadrilateral to a rectangle.  
 +
 
 +
Lanczos, cubic, linear or nearest point interpolation methods can be opted. The parameters are identical to both functions (and to the Reform plugin), and the coordinates can be specified as floating point or (since AviSynth accepts integers as floating point) in integer format.
 +
 
 +
While there are no limits for specifying parameters, it has to be ensured that the specified parameters do not twist or fold the Quadrlateral. In the parameter description R stands for Rectangle and Q stands for Quadrilateral.
 +
 
 +
Most of the parameters can be linearly varied over the length of the clip, and so it can be used to distort or correct distorted faces or objects progressively. Also can be used by proper scripting as transition. For reading coordinates correctly, the plugin [[Grid]] can be used.
 +
 
  
 +
* See official documentation: http://www.avisynth.nl/users/vcmohan/Reformer/Reformer.html
 +
* For AviSynth+ see [[movePlus]], includes high bit depth colorspace support and 64-bit.
 
<br>
 
<br>
 
== Requirements ==
 
== Requirements ==
* <!-- Avisynth version -->AviSynth 2.5.8 or [http://sourceforge.net/projects/avisynth2/ 2.6.0] or greater
+
* [x86]: [[AviSynth+]] or [https://sourceforge.net/projects/avisynth2/ AviSynth 2.6]
* <!-- source video: progressive
+
* Supported color formats: [[RGB24]], [[RGB32]], [[YUY2]], [[Y8]], [[YV12]], [[YV16]], [[YV24]]
* <!-- color formats -->Supported color formats: [[RGB32]], [[RGB24]], [[YUY2]], [[YV12]], <span style="color:red">*</span>[[YV16]], <span style="color:red">*</span>[[YV24]], <span style="color:red">*</span>[[YV411]], <span style="color:red">*</span>[[Y8]]
+
: <span style="color:red">*</span> Not available in AviSynth 2.5.8.
+
* <!-- CPU/GPU -->
+
* <!-- binaries -->
+
* <!-- dependent plugins -->
+
<br>
+
"cc[resize]s[ltopx]f[ltopy]f[lbotx]f[lboty]f[rtopx]f[rtopy]f[rbotx]f[rboty]f"
+
"[leftx]f[rightx]f[ytop]f[ybot]f"
+
"[eltopx]f[eltopy]f[elbotx]f[elboty]f[ertopx]f[ertopy]f[erbotx]f[erboty]f"
+
"[eleftx]f[erightx]f[eytop]f[eybot]f"
+
  
 +
<br>
 
== [[Script variables|Syntax and Parameters]] ==
 
== [[Script variables|Syntax and Parameters]] ==
:{{Template:FuncDef|<!-- function name -->q2r or r2q(''clip'', ''<!-- par 1 type -->clip'' "<!-- par 1 name -->", ''<!-- par 2 type -->string'' "<!-- par 2 name -->resize", ''<!-- par 3 type -->float'' "<!-- par 3 name -->ltopx ",''<!-- par 4 type -->float'' <!-- par 4 name -->ltopy",''<!-- par 5 type -->float'' <!-- par 5 name -->lbotx",''<!-- par 6 type -->float'' <!-- par 6 name -->lboty",''<!-- par 7 type -->float'' <!-- par 7 name -->rtopx",''<!-- par 8 type -->float'' <!-- par 8 name -->rtopy",''<!-- par 9 type -->float'' <!-- par 9 name -->rbotx"''<!-- par 10 type -->float'' <!-- par 10 name -->rboty",''<!-- par 11 type -->float'' <!-- par 11 name -->leftx",''<!-- par 12 type -->float'' <!-- par 12 name -->rightx",''<!-- par 13 type -->float'' <!-- par 13 name -->ytop",''<!-- par 14 type -->float'' <!-- par 14 name -->ybot")}}
+
:{{Template:FuncDef|r2q (clip, clip, string "resize", float "ltopx", float "ltopy", float "lbotx", float "lboty", float "rtopx", float "rtopy", float "rbotx", float "rboty", float "leftx", float "rightx", float "ytop", float "ybot", float "eltopx", float "eltopy", float "elbotx", float "elboty", float "ertopx", float "ertopy", float "erbotx", float "erboty", float "eleftx", float "erightx", float "eytop", float "eybot")}}
 +
 
 +
:{{Template:FuncDef|q2r (clip, clip, string "resize", float "ltopx", float "ltopy", float "lbotx", float "lboty", float "rtopx", float "rtopy", float "rbotx", float "rboty", float "leftx", float "rightx", float "ytop", float "ybot", float "eltopx", float "eltopy", float "elbotx", float "elboty", float "ertopx", float "ertopy", float "erbotx", float "erboty", float "eleftx", float "erightx", float "eytop", float "eybot")}}
 
<br>
 
<br>
 
::{{Par2| |clip| }}
 
::{{Par2| |clip| }}
:::Input clip.  
+
:::Input clip to be skewed into quadrilateral or deskewed into rectangle.
 
<br>
 
<br>
 
::{{Par2| |clip| }}
 
::{{Par2| |clip| }}
:::background clip.       
+
:::Clip to be used as background.       
 
<br>
 
<br>
::{{Par2|<!-- par 2 type -->string|<!-- par 2 name -->resize|<!-- par 1 default value -->"lanczos"}}
+
::{{Par2|resize|string|"lanczos"}}
:::<!-- par 1 description -->type of interpolation to be used for resizing. lanczos, bicubic, bilinear, nearest point .
+
:::Resize interpolation to use: <code>"lanczos" | "cubic" | "line" | "point"</code>
 
+
 
<br>
 
<br>
::{{Par2|<!-- par 3 type -->float|<!-- par 3 name -->ltopx|<!-- par 3 default value -->0}}
+
::{{Par2|ltopx|float|0}}
:::<!-- par 3 description -->quadrilateral left top x.
+
::{{Par2|ltopy|float|0}}
 +
:::Quadrilateral left top x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 4 type -->float|<!-- par 4 name -->ltopy|<!-- par 4 default value -->0}}
+
::{{Par2|lbotx|float|0}}
:::<!-- par 4 description -->quadrilateral left top y .
+
::{{Par2|lboty|float|height-1}}
 +
:::Quadrilateral left bottom x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 5 type -->float|<!-- par 5 name -->lbotx|<!-- par 5 default value -->0}}
+
::{{Par2|rtopx|float|width-1}}
:::<!-- par 5 description -->quadrilateral left bottom x .
+
::{{Par2|rtopy|float|0}}
 +
:::Quadrilateral right top x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 6 type -->float|<!-- par 6 name -->lboty|<!-- par 6 default value -->height - 1}}
+
::{{Par2|rbotx|float|width-1}}
:::<!-- par 6 description -->quadrilateral left bottom y .
+
::{{Par2|rboty|float|height-1}}
 +
:::Quadrilateral right bottom x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 7 type -->float|<!-- par 7 name -->rtopx|<!-- par 7 default value -->frame width -1}}
+
::{{Par2|leftx|float|0}}
:::<!-- par 7 description -->quadrilateral right top x .
+
::{{Par2|rightx|float| width-1}}
 
+
:::Rectangle coordinates: left x and right x.
 
<br>
 
<br>
::{{Par2|<!-- par 8 type -->float|<!-- par 8 name -->rtopy|<!-- par 8 default value -->0}}
+
::{{Par2|ytop|float|0}}
:::<!-- par 8 description -->quadrilateral right top y .
+
::{{Par2|ybot|float|height-1}}
 +
:::Rectangle coordinates: top y and bottom y.
 
<br>
 
<br>
::{{Par2|<!-- par 9 type -->float|<!-- par 9 name -->rbotx|<!-- par 9 default value -->width- 1}}
+
::{{Par2|eltopx|float|ltopx}}
:::<!-- par 9 description -->quadrilateral right bottom x .
+
::{{Par2|eltopy|float|ltopy}}
 +
:::End frame, Quadrilateral left top x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 10 type -->float|<!-- par 10 name -->rboty|<!-- par 10 default value -->height- 1}}
+
::{{Par2|elbotx|float|lbotx}}
:::<!-- par 10 description -->quadrilateral right bottom y .
+
::{{Par2|elboty|float|lboty}}
 +
:::End frame, Quadrilateral left bottom x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 11 type -->float|<!-- par 11 name -->leftx|<!-- par 11 default value -->0}}
+
::{{Par2|ertopx|float|rtopx}}
:::<!-- par 11 description -->Rectangle left x
+
::{{Par2|ertopy|float|rtopy}}
 +
:::End frame, Quadrilateral right top x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 12 type -->float|<!-- par 12 name -->rightx|<!-- par 12 default value -->width - 1}}
+
::{{Par2|erbotx|float|rbotx}}
:::<!-- par 12 description -->Rectangle right x
+
::{{Par2|erboty|float|rboty}}
 +
:::End frame, Quadrilateral right bottom x and y coordinates.
 
<br>
 
<br>
::{{Par2|<!-- par 13 type -->float|<!-- par 13 name -->ytop|<!-- par 13 default value -->0}}
+
::{{Par2|eleftx|float|leftx}}
:::<!-- par 13 description -->Rectangle top y
+
::{{Par2|erightx|float|rightx}}
::{{Par2|<!-- par 14 type -->float|<!-- par 14 name -->rbotx|<!-- par 14 default value -->width- 1}}
+
:::End frame Rectanlge coordinates: left x and right x.
:::<!-- par 14 description -->Rectangle bottom y .
+
 
<br>
 
<br>
 +
::{{Par2|eytop|float|ytop}}
 +
::{{Par2|eybot|float|ybot}}
 +
:::End frame Rectanlge coordinates: top y and bottom y.
 
<br>
 
<br>
 
  
 
== Examples ==
 
== Examples ==
<!-- example code block: 1st char in each line = space -->
+
Script examples:
  ## This is some example code to blur  an image.
+
  ColorBars().ConvertToRGB32()
imagereader("C:\..........jpg", end = 10)
+
  bg = blankclip(last)
a = avisource("C;\..........avi").converttoYUY2()
+
  r2q(bg, leftx=100, rightx=400, ytop=200, ybot=480, ltopx=200, ltopy=150, rbotx=500, rboty=400, resize="lanczos")
  converttoyv16()
+
 
# Rectangle to quadrilateral
+
  r2q(last,last,leftx = 100,rightx = 400, ytop = 200, ybot = 480,ltopx=200,ltopy=150, rbotx = 500, rboty = 400, resize= "lanczos")
+
# quad to rectangle excercise
+
c= last
+
  
# bg = blankclip(last,color = 0)
+
Below is a suitably modified interesting script originally by Martin53 (Sept. 2012) in the [https://forum.doom9.org/showthread.php?p=1592937#post1592937 quad plugin thread.] By commenting either r2q call or q2r call or none the power of the plugin can be viewed.
ScriptClip("""
+
<pre>
 +
ColorBars().ConvertToYV12()
 +
bg = BlankClip(last)
 +
Subtitle("Flying Colorbars()",text_color=$d0c000,align=5,size=40)
 +
ScriptClip("""
 +
c= last
  
 +
bg = blankclip(last)
 
h = height(bg)-1
 
h = height(bg)-1
 
w = width(bg)-1
 
w = width(bg)-1
Line 117: Line 134:
 
     c4x = (0.5+a*sin(t)) * w
 
     c4x = (0.5+a*sin(t)) * w
 
     c4y = (0.5-a*cos(t)) * h
 
     c4y = (0.5-a*cos(t)) * h
+
# comment out call to r2q or to q2r or leave as it is
# r2q(c, c,leftx=t1x,rightx=t2x,ytop=t1y,ybot=t3y,ltopx=c1x,ltopy=c1y, rtopx=c2x,rtopy=c2y,  rbotx=c3x,rboty=c3y,lbotx=c4x,lboty=c4y, resize = "line")
+
r2q(c, bg,leftx=t1x,rightx=t2x,ytop=t1y,ybot=t3y,ltopx=c1x,ltopy=c1y, rtopx=c2x,rtopy=c2y,  rbotx=c3x,rboty=c3y,lbotx=c4x,lboty=c4y, resize = "point")
  
 
q2r( bg,leftx=t1x,rightx=t2x,ytop=t1y,ybot=t3y,ltopx=c1x,ltopy=c1y, rtopx=c2x,rtopy=c2y,  rbotx=c3x,rboty=c3y,lbotx=c4x,lboty=c4y, resize = "point" )
 
q2r( bg,leftx=t1x,rightx=t2x,ytop=t1y,ybot=t3y,ltopx=c1x,ltopy=c1y, rtopx=c2x,rtopy=c2y,  rbotx=c3x,rboty=c3y,lbotx=c4x,lboty=c4y, resize = "point" )
 +
 +
""")
 +
</pre>
 +
<br>
 
<br>
 
<br>
 
-----------------------------------------------
 
-----------------------------------------------
'''Back to [[External_filters|External Filters]] &larr;'''
+
'''Back to [[External_filters#Rotation.2FShear.2FSkew.2FPerspective|External Filters]] &larr;'''

Latest revision as of 07:08, 9 June 2020

Abstract
Author V. C. Mohan
Version 14 Oct 2015
Download Reformer_2_6.zip
Category Transformation
License GPLv2
Discussion Doom9 Forum


Contents

[edit] Description

Reformer can be used to correct skewed images or vice versa. Useful if video is recorded with incorrectly located camera or for transitions or effects.

This plugin probably is better suited than the Reform plugin as it performs much better even if the rectangle is rotated by 90 degrees. Reform fails in such a situation. This Reformer uses matrix algebra for transformations unlike Reform which does a geometric transform.

Reformer has two functions:

  • r2q transforms a rectangle to a quadrilateral.
  • q2r transforms a quadrilateral to a rectangle.

Lanczos, cubic, linear or nearest point interpolation methods can be opted. The parameters are identical to both functions (and to the Reform plugin), and the coordinates can be specified as floating point or (since AviSynth accepts integers as floating point) in integer format.

While there are no limits for specifying parameters, it has to be ensured that the specified parameters do not twist or fold the Quadrlateral. In the parameter description R stands for Rectangle and Q stands for Quadrilateral.

Most of the parameters can be linearly varied over the length of the clip, and so it can be used to distort or correct distorted faces or objects progressively. Also can be used by proper scripting as transition. For reading coordinates correctly, the plugin Grid can be used.



[edit] Requirements


[edit] Syntax and Parameters

r2q (clip, clip, string "resize", float "ltopx", float "ltopy", float "lbotx", float "lboty", float "rtopx", float "rtopy", float "rbotx", float "rboty", float "leftx", float "rightx", float "ytop", float "ybot", float "eltopx", float "eltopy", float "elbotx", float "elboty", float "ertopx", float "ertopy", float "erbotx", float "erboty", float "eleftx", float "erightx", float "eytop", float "eybot")
q2r (clip, clip, string "resize", float "ltopx", float "ltopy", float "lbotx", float "lboty", float "rtopx", float "rtopy", float "rbotx", float "rboty", float "leftx", float "rightx", float "ytop", float "ybot", float "eltopx", float "eltopy", float "elbotx", float "elboty", float "ertopx", float "ertopy", float "erbotx", float "erboty", float "eleftx", float "erightx", float "eytop", float "eybot")


clip   =
Input clip to be skewed into quadrilateral or deskewed into rectangle.


clip   =
Clip to be used as background.


string  resize = "lanczos"
Resize interpolation to use: "lanczos" | "cubic" | "line" | "point"


float  ltopx = 0
float  ltopy = 0
Quadrilateral left top x and y coordinates.


float  lbotx = 0
float  lboty = height-1
Quadrilateral left bottom x and y coordinates.


float  rtopx = width-1
float  rtopy = 0
Quadrilateral right top x and y coordinates.


float  rbotx = width-1
float  rboty = height-1
Quadrilateral right bottom x and y coordinates.


float  leftx = 0
float  rightx = width-1
Rectangle coordinates: left x and right x.


float  ytop = 0
float  ybot = height-1
Rectangle coordinates: top y and bottom y.


float  eltopx = ltopx
float  eltopy = ltopy
End frame, Quadrilateral left top x and y coordinates.


float  elbotx = lbotx
float  elboty = lboty
End frame, Quadrilateral left bottom x and y coordinates.


float  ertopx = rtopx
float  ertopy = rtopy
End frame, Quadrilateral right top x and y coordinates.


float  erbotx = rbotx
float  erboty = rboty
End frame, Quadrilateral right bottom x and y coordinates.


float  eleftx = leftx
float  erightx = rightx
End frame Rectanlge coordinates: left x and right x.


float  eytop = ytop
float  eybot = ybot
End frame Rectanlge coordinates: top y and bottom y.


[edit] Examples

Script examples:

ColorBars().ConvertToRGB32()
bg = blankclip(last)
r2q(bg, leftx=100, rightx=400, ytop=200, ybot=480, ltopx=200, ltopy=150, rbotx=500, rboty=400, resize="lanczos")


Below is a suitably modified interesting script originally by Martin53 (Sept. 2012) in the quad plugin thread. By commenting either r2q call or q2r call or none the power of the plugin can be viewed.

ColorBars().ConvertToYV12()
bg = BlankClip(last)
Subtitle("Flying Colorbars()",text_color=$d0c000,align=5,size=40)
ScriptClip("""
c= last

	bg = blankclip(last)
	h = height(bg)-1
	w = width(bg)-1	
    t = 0.061 *(current_frame)
    t2 = 0.127 *( current_frame)
    a = 0.501 + 0.5 * sin(t/pi)
    t1x = (-0.2*cos(t2)) * w
    t1y = (0.5-0.5*cos(t2)) * h
    t2x = (1.0+0.2*cos(t2)) * w
    t2y = (0.5-0.5*cos(t2)) * h
    t3x = (1.0+0.2*cos(t2)) * w
    t3y = (0.5+0.5*cos(t2)) * h
    t4x = (-0.2*cos(t2)) * w
    t4y = (0.5+0.5*cos(t2)) * h
    c1x = (0.5+a*cos(t)) * w
    c1y = (0.5+a*sin(t)) * h
    c2x = (0.5-a*sin(t)) * w
    c2y = (0.5+a*cos(t)) * h
    c3x = (0.5-a*cos(t)) * w
    c3y = (0.5-a*sin(t)) * h
    c4x = (0.5+a*sin(t)) * w
    c4y = (0.5-a*cos(t)) * h
	# comment out call to r2q or to q2r or leave as it is
	r2q(c, bg,leftx=t1x,rightx=t2x,ytop=t1y,ybot=t3y,ltopx=c1x,ltopy=c1y, rtopx=c2x,rtopy=c2y,  rbotx=c3x,rboty=c3y,lbotx=c4x,lboty=c4y, resize = "point")

	q2r( bg,leftx=t1x,rightx=t2x,ytop=t1y,ybot=t3y,ltopx=c1x,ltopy=c1y, rtopx=c2x,rtopy=c2y,  rbotx=c3x,rboty=c3y,lbotx=c4x,lboty=c4y, resize = "point" )

 """)
 




Back to External Filters

Personal tools