Reform


Author V. C. Mohan
1 Oct 2020
Reform uses matrix algebra for transformations .

This function accepts RGB, Planar and YUY2 formats for all bit depths supported by avisynth+. It is thread safe. MT_NICE_FILTER

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. Coordinates can be specified in floating point real or in normalized form.

While there are no limits for specifying coordinate values, it has to be ensured thatthey do not result in twist or fold the Quadrlateral.The accuracy of transform deteriorates with higher deviation of quad from rectangle. In the table of parameters R stands for Rectangle and Q stands for Quadrilateral.The quadrilateral coordinates need to be specified in clockwise order starting from the corner the top left corner of rectangle transforms to.


Function Grid can help specifying coordinates correctly.

Description of parameters. Q stands for Quadrilateral and R for rectangle.
Parameter Parameter name Variable type Limits of values Default value
clip to be skewed into quadrilateral or deskewed into rectangle clip none
clip to be used as background clip none
interpolation method to be used resize string "lanczos" "cubic" "line" "point" "cubic"
Q left top x coordinate qx float none 0
Q left top y coordinate qy float none 0
Q right top x coordinate qx1 float none frame wwidth - 1
Q right top y coordinate qy1 float none 0
Q right bottom x coordinate qx2 float none frame width-1
Q right bottom y coordinate qy2 float none height - 1
Q left bottom x coordinate qx3 float none 0
Q left bottom y coordinate qy3 float none frame height-1
R left x coordinate lx float none 0
R right x coordinate rx float none frame width-1
R top y coordinate ty float none 0
R bottom y coordinate by float none frame height-1
Whether quadrilateral to rectangle conversion qr boolean true for q to r, false for r to q true
Whether normalised coordinates are specified? norm boolean true for normalized, false for real false

Script examples:-
ColorBars(). converttorgb32()
bg = blankclip(last)
Reform(last,bg,qr = false,norm = false, qx = 80, qy = 270, qx1 = 320, qy1 = 50, qx2 = 650, qy2 = 320,qx3 = 100, qy3 = 400)
Reform(last,last,qr = true,norm = false, qx = 80, qy = 270, qx1 = 320, qy1 = 50, qx2 = 650, qy2 = 320,qx3 = 100, qy3 = 400)
Below is a suitably modified interesting script due to Martin53 ( sept 2012)in the quad plugin thread). By commenting either call or 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 having qr = true or qr = false or have both running to see the effect
	Reform(c, bg,lx=t1x,rx=t2x,ty=t1y,by=t3y,qx=c1x,qy=c1y, qx1=c2x,qy1=c2y,  qx2=c3x,qy2=c3y,qx3=c4x,qy3=c4y, resize = "point", qr = false)

#Reform(c,bg,lx=t1x,rx=t2x,ty=t1y,by=t3y,qx=c1x,qy=c1y, 		      qx1=c2x,qy1=c2y,  qx2=c3x,qy2=c3y,qx3=c4x,qy3=c4y,          resize="point", qr = true)

 """)

 

To my index page down loadmanyPlus plugin To Avisynth