Exemplo n.º 1
0
def transforms_test():

    X = util.test_object(1)
    X_rot = reg.rotate(3 * np.pi / 4).dot(X)
    X_shear = reg.shear(0.1, 0.2).dot(X)
    X_reflect = reg.reflect(-1, -1).dot(X)

    fig = plt.figure(figsize=(12, 5))
    ax1 = fig.add_subplot(141, xlim=(-4, 4), ylim=(-4, 4))
    ax2 = fig.add_subplot(142, xlim=(-4, 4), ylim=(-4, 4))
    ax3 = fig.add_subplot(143, xlim=(-4, 4), ylim=(-4, 4))
    ax4 = fig.add_subplot(144, xlim=(-4, 4), ylim=(-4, 4))

    util.plot_object(ax1, X)
    util.plot_object(ax2, X_rot)
    util.plot_object(ax3, X_shear)
    util.plot_object(ax4, X_reflect)

    ax1.set_title('Original')
    ax2.set_title('Rotation')
    ax3.set_title('Shear')
    ax4.set_title('Reflection')

    ax1.grid()
    ax2.grid()
    ax3.grid()
    ax4.grid()
Exemplo n.º 2
0
def combining_transforms():
    X = util.test_object(1)

    X_shear_reflect = reg.reflect(-1, 1).dot(reg.shear(0.5, 0.2).dot(X))
    X_reflect_shear = reg.shear(0.5, 0.2).dot(reg.reflect(-1, 1).dot(X))

    fig = plt.figure(figsize=(12, 5))
    ax1 = fig.add_subplot(141, xlim=(-4, 4), ylim=(-4, 4))
    ax2 = fig.add_subplot(142, xlim=(-4, 4), ylim=(-4, 4))
    ax3 = fig.add_subplot(143, xlim=(-4, 4), ylim=(-4, 4))
    ax4 = fig.add_subplot(144, xlim=(-4, 4), ylim=(-4, 4))

    util.plot_object(ax1, X)
    util.plot_object(ax2, X_shear_reflect)
    util.plot_object(ax3, X_reflect_shear)
    util.plot_object(ax4, X)

    ax1.set_title('Original')
    ax2.set_title('shear_reflect')
    ax3.set_title('reflect_shear')
    ax4.set_title('Original')

    ax1.grid()
    ax2.grid()
    ax3.grid()
    ax4.grid()

    fig.show()
Exemplo n.º 3
0
def arbitrary_rotation():

    X = util.test_object(1)
    Xh = util.c2h(X)

    #------------------------------------------------------------------#
    # TODO: Perform rotation of the test shape around the first vertex
    #------------------------------------------------------------------#

    X_rot = T.dot(Xh)

    fig = plt.figure(figsize=(5,5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_rot)
    ax1.set_xlim(ax1.get_ylim())
    ax1.grid()
Exemplo n.º 4
0
def t2h_test():
    X = util.test_object(1)
    Xh = util.c2h(X)

    # translation vector
    t = np.array([10, 20])

    # rotation matrix
    T_rot = reg.rotate(np.pi / 4)

    Th = util.t2h(T_rot, t)

    X_rot_tran = Th.dot(Xh)

    fig = plt.figure(figsize=(5, 5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_rot_tran)
    ax1.grid()
Exemplo n.º 5
0
def arbitrary_rotation():

    X = util.test_object(1)
    Xh = util.c2h(X)

    #------------------------------------------------------------------#
    Xt= X[:0]
    T_trans = util.t2h(reg.identity(), Xt)
    T_rot = reg.rotate(0.25*np.pi)
    T_trans_inv = np.linalg.inv(T_trans)
    T = T_trans_inv.dot(T_rot.dot(T_trans))
    #------------------------------------------------------------------#

    X_rot = T.dot(Xh)

    fig = plt.figure(figsize=(5,5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_rot)
    ax1.set_xlim(ax1.get_ylim())
    ax1.grid()
Exemplo n.º 6
0
def arbitrary_rotation():
    X = util.test_object(1)
    Xh = util.c2h(X)

    p_rot = X[:, 0]
    T_to_zero = util.t2h(reg.identity(), -p_rot)
    T_return = util.t2h(reg.identity(), p_rot)
    T_rot = util.t2h(reg.rotate(45))

    T = T_return.dot(T_rot.dot(T_to_zero))

    X_rot = T.dot(Xh)

    fig = plt.figure(figsize=(5, 5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_rot)
    ax1.set_xlim(ax1.get_ylim())
    ax1.grid()

    fig.show()
Exemplo n.º 7
0
def combining_transforms():

    X = util.test_object(1)

    #------------------------------------------------------------------#
    # TODO: Experiment with combining transformation matrices.
    Example_1_temp = reg.rotate(5 * np.pi / 3).dot(X)
    Example_1_result = reg.reflect(-1, 1).dot(Example_1_temp)

    Example2 = reg.reflect(-1, 1).dot(X)
    Example2_result = reg.rotate(np.pi / 2).dot(Example2)

    Example2_reversed = reg.rotate(np.pi / 2).dot(X)
    Example2_reversed_result = reg.rotate(5 * np.pi / 3).dot(X)

    #plotting
    fig = plt.figure(figsize=(12, 5))
    ax1 = fig.add_subplot(141, xlim=(-4, 4), ylim=(-4, 4))
    ax2 = fig.add_subplot(142, xlim=(-4, 4), ylim=(-4, 4))
    ax3 = fig.add_subplot(143, xlim=(-4, 4), ylim=(-4, 4))

    util.plot_object(ax1, X)
    util.plot_object(ax2, Example2_result)
    util.plot_object(ax3, Example2_reversed_result)

    ax1.set_title('Original')
    ax2.set_title('Reflection, rotation')
    ax3.set_title('Reversed')

    ax1.grid()
    ax2.grid()
    ax3.grid()
Exemplo n.º 8
0
def ls_affine_test():

    X = util.test_object(1)
    # convert to homogeneous coordinates
    Xh = util.c2h(X)

    T_rot = reg.rotate(np.pi / 4)
    T_scale = reg.scale(1.2, 0.9)
    T_shear = reg.shear(0.2, 0.1)

    T = util.t2h(T_rot.dot(T_scale).dot(T_shear), [10, 20])

    Xm = T.dot(Xh)

    Te = reg.ls_affine(Xh, Xm)

    Xmt = Te.dot(Xm)

    fig = plt.figure(figsize=(12, 5))

    ax1 = fig.add_subplot(131)
    ax2 = fig.add_subplot(132)
    ax3 = fig.add_subplot(133)

    util.plot_object(ax1, Xh)
    util.plot_object(ax2, Xm)
    util.plot_object(ax3, Xmt)

    ax1.set_title('Test shape')
    ax2.set_title('Arbitrary transformation')
    ax3.set_title('Retrieved test shape')

    ax1.grid()
    ax2.grid()
    ax3.grid()
Exemplo n.º 9
0
def arbitrary_rotation():
    X = util.test_object(1)
    Xh = util.c2h(X)

    # ------------------------------------------------------------------#
    Tlat = util.t2h(reg.identity(), np.array(X[:, 0]))
    Tlat_down = util.t2h(reg.identity(), -np.array(X[:, 0]))
    T_rot = reg.rotate(np.pi / 4)

    T_rot_hom = util.t2h(T_rot, np.array([0, 0]))

    T_tot = Tlat.dot(T_rot_hom).dot(Tlat_down)
    X_fin = T_tot.dot(Xh)

    # ------------------------------------------------------------------#

    fig = plt.figure(figsize=(5, 5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_fin)
    ax1.set_xlim(ax1.get_ylim())
    ax1.grid()
Exemplo n.º 10
0
def arbitrary_rotation():

    X = util.test_object(1)
    Xh = util.c2h(X)

    #------------------------------------------------------------------#
    # TODO: Perform rotation of the test shape around the first vertex

    Xt = X[:, 0]

    T = util.t2h(reg.rotate(np.pi / 4), Xt).dot(util.t2h(reg.identity(), -Xt))

    #------------------------------------------------------------------#

    X_rot = T.dot(Xh)

    fig = plt.figure(figsize=(5, 5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_rot)
    ax1.set_xlim(ax1.get_ylim())
    ax1.grid()
Exemplo n.º 11
0
def arbitrary_rotation():

    X = util.test_object(1)
    Xh = util.c2h(X)

    #------------------------------------------------------------------#
    # TODO: TODO: Perform rotation of the test shape around the first vertex
    a_point = X[:,0]
    ax = a_point[0]
    ay = a_point[1]

    trans1 = np.array([[1,0,ax],[0,1,ay],[0,0,1]])              #translatiematrix 1 (zie slides)
    trans2 = np.array([[1, 0, -ax], [0, 1, -ay], [0, 0, 1]])    #translatiematrix 2

    phi = (np.pi/4)
    c = np.cos(phi)
    s = np.sin(phi)
    extra = ([[0,0]])
    extra_vertical = np.transpose(extra)
    extra_horizontal = ([[0,0,1]])
    r = np.array([[c, -s], [s, c]])
    rot1 = np.concatenate((r, extra_vertical), 1)
    rot2 = np.concatenate((rot1, extra_horizontal), 0)          #rotatiematrix

    Transformation = trans1.dot(rot2.dot(trans2))
    X_rot = Transformation.dot(Xh)

    #------------------------------------------------------------------#

    #X_rot = T.dot(Xh)

    fig = plt.figure(figsize=(5,5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_rot)
    ax1.set_xlim(ax1.get_ylim())
    ax1.grid()
Exemplo n.º 12
0
def arbitrary_rotation():

    X = util.test_object(1)
    Xh = util.c2h(X)

    #------------------------------------------------------------------#
    # TODO: TODO: Perform rotation of the test shape around the first vertex
    #------------------------------------------------------------------#
    tdown = X[:, 0] * -1
    tup = X[:, 0]
    tdown = util.t2h(reg.identity(), tdown)
    tup = util.t2h(reg.identity(), tup)
    r = util.t2h(reg.rotate(45), [0, 0])
    T = tup.dot(r.dot(tdown))

    X_rot = T.dot(Xh)

    fig = plt.figure(figsize=(5, 5))
    ax1 = fig.add_subplot(111)
    util.plot_object(ax1, X)
    util.plot_object(ax1, X_rot)
    ax1.set_xlim(ax1.get_ylim())
    ax1.grid()
    plt.show()
Exemplo n.º 13
0
def combining_transforms():

    X = util.test_object(1)

    #------------------------------------------------------------------#
    # Experiment with combining transformation matrices.
    X1_1 = reg.rotate(np.pi / 4).dot(reg.reflect(-1, 1).dot(X))
    X1_2 = reg.reflect(-1, 1).dot(reg.rotate(np.pi / 4).dot(X))
    X2_1 = reg.shear(0.6, 0.3).dot(reg.reflect(-1, -1).dot(X))
    X2_2 = reg.shear(0.6, 0.3).dot(reg.reflect(-1, 1).dot(X))
    X3_1 = reg.reflect(-1, 1).dot(reg.shear(0.6, 0.3).dot(X))
    X3_2 = reg.shear(0.6, 0.3).dot(reg.reflect(-1, 1).dot(X))

    fig = plt.figure(figsize=(12, 5))
    ax1 = fig.add_subplot(141, xlim=(-4, 4), ylim=(-4, 4))
    ax2 = fig.add_subplot(142, xlim=(-4, 4), ylim=(-4, 4))
    ax3 = fig.add_subplot(143, xlim=(-4, 4), ylim=(-4, 4))
    ax4 = fig.add_subplot(144, xlim=(-4, 4), ylim=(-4, 4))

    util.plot_object(ax1, X)
    util.plot_object(ax2, X1_1)
    util.plot_object(ax2, X1_2)
    util.plot_object(ax3, X2_1)
    util.plot_object(ax3, X2_2)
    util.plot_object(ax4, X3_1)
    util.plot_object(ax4, X3_2)

    ax1.grid()
    ax2.grid()
    ax3.grid()
    ax4.grid()
Exemplo n.º 14
0
# -*- coding: utf-8 -*-
"""
Created on Tue Sep 10 15:36:11 2019

@author: 20161879
"""

import sys
sys.path.append("../code")
import numpy as np
import matplotlib.pyplot as plt
import registration as reg
import registration_util as util

X = util.test_object(1)
X_scaled = reg.scale(2, 3).dot(X)

fig = plt.figure(figsize=(5, 5))
ax1 = fig.add_subplot(111)
ax1.grid()
util.plot_object(ax1, X)
util.plot_object(ax1, X_scaled)