Reformer

From Avisynth wiki
(Difference between revisions)
Jump to: navigation, search
(Syntax and Parameters)
(Reformer: update documentation to match Reformer)
 
(3 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+ r2347 or later
+
* [x86]: [[AviSynth+]] or [https://sourceforge.net/projects/avisynth2/ AviSynth 2.6]
 +
* Supported color formats: [[RGB24]], [[RGB32]], [[YUY2]], [[Y8]], [[YV12]], [[YV16]], [[YV24]]
  
 +
<br>
 
== [[Script variables|Syntax and Parameters]] ==
 
== [[Script variables|Syntax and Parameters]] ==
:{{Template:FuncDef| Reform (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", bool "qr", bool "norm")}}
+
:{{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| }}
::: Clip to be skewed into quadrilateral or deskewed into rectangle
+
:::Input clip to be skewed into quadrilateral or deskewed into rectangle.
 
<br>
 
<br>
 
::{{Par2| |clip| }}
 
::{{Par2| |clip| }}
::: Clip to be used as background
+
:::Clip to be used as background.     
 
<br>
 
<br>
::{{Par2|resize|string|"cubic"}}
+
::{{Par2|resize|string|"lanczos"}}
::: Radius of grid to use
+
:::Resize interpolation to use: <code>"lanczos" | "cubic" | "line" | "point"</code>
:::* "lanczos"
+
:::* "cubic"
+
:::* "line"
+
:::* "point"
+
 
<br>
 
<br>
 
::{{Par2|ltopx|float|0}}
 
::{{Par2|ltopx|float|0}}
::: Q left top x coordinate
 
<br>
 
 
::{{Par2|ltopy|float|0}}
 
::{{Par2|ltopy|float|0}}
::: Q left top y coordinate
+
:::Quadrilateral left top x and y coordinates.
 
<br>
 
<br>
 
::{{Par2|lbotx|float|0}}
 
::{{Par2|lbotx|float|0}}
::: Q left bottom x coordinate
+
::{{Par2|lboty|float|height-1}}
<br>
+
:::Quadrilateral left bottom x and y coordinates.
::{{Par2|lboty|float|frame height - 1}}
+
::: Q left bottom y coordinate
+
<br>
+
::{{Par2|rtopx|float|frame width - 1}}
+
::: Q right top x coordinate
+
 
<br>
 
<br>
 +
::{{Par2|rtopx|float|width-1}}
 
::{{Par2|rtopy|float|0}}
 
::{{Par2|rtopy|float|0}}
::: Q right top y coordinate
+
:::Quadrilateral right top x and y coordinates.
 
<br>
 
<br>
::{{Par2|rbotx|float|frame width - 1}}
+
::{{Par2|rbotx|float|width-1}}
::: Q right bottom x coordinate
+
::{{Par2|rboty|float|height-1}}
<br>
+
:::Quadrilateral right bottom x and y coordinates.
::{{Par2|rboty|float|frame height - 1}}
+
::: Q right bottom y coordinate
+
 
<br>
 
<br>
 
::{{Par2|leftx|float|0}}
 
::{{Par2|leftx|float|0}}
::: R left x coordinate
+
::{{Par2|rightx|float| width-1}}
<br>
+
:::Rectangle coordinates: left x and right x.
::{{Par2|rightx|float|frame width - 1}}
+
::: R right x coordinate
+
 
<br>
 
<br>
 
::{{Par2|ytop|float|0}}
 
::{{Par2|ytop|float|0}}
::: R top y coordinate
+
::{{Par2|ybot|float|height-1}}
 +
:::Rectangle coordinates: top y and bottom y.
 
<br>
 
<br>
::{{Par2|ybot|float|frame height - 1}}
+
::{{Par2|eltopx|float|ltopx}}
::: R bottom y coordinate
+
::{{Par2|eltopy|float|ltopy}}
 +
:::End frame, Quadrilateral left top x and y coordinates.
 
<br>
 
<br>
::{{Par2|qr|bool|true}}
+
::{{Par2|elbotx|float|lbotx}}
::: R bottom y coordinate
+
::{{Par2|elboty|float|lboty}}
:::* true = q to r
+
:::End frame, Quadrilateral left bottom x and y coordinates.
:::* false = r to q
+
 
<br>
 
<br>
::{{Par2|norm|bool|false}}
+
::{{Par2|ertopx|float|rtopx}}
::: Whether normalised coordinates are specified?
+
::{{Par2|ertopy|float|rtopy}}
:::* true = normalized
+
:::End frame, Quadrilateral right top x and y coordinates.
:::* false = real
+
<br>
 +
::{{Par2|erbotx|float|rbotx}}
 +
::{{Par2|erboty|float|rboty}}
 +
:::End frame, Quadrilateral right bottom x and y coordinates.
 +
<br>
 +
::{{Par2|eleftx|float|leftx}}
 +
::{{Par2|erightx|float|rightx}}
 +
:::End frame Rectanlge coordinates: left x and right x.
 +
<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)
 
ScriptClip("""
 
  
 +
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.
 +
<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