예제 #1
0
def combining_transforms():

    X = util.test_object(1)

    #------------------------------------------------------------------#
    # TODO: Experiment with combining transformation matrices.

    X_t = reg.reflect(-1, 1).dot(reg.rotate(np.pi / 2)).dot(X)
    X_u = reg.shear(2, 1).dot(reg.reflect(1, -1)).dot(X)
    X_v = reg.reflect(1, -1).dot(reg.shear(2, 1)).dot(X)
    X_w = reg.rotate(np.pi / 2).dot(reg.shear(2, 1)).dot(X)

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

    util.plot_object(ax1, X_t)
    util.plot_object(ax2, X_u)
    util.plot_object(ax3, X_v)
    util.plot_object(ax4, X_w)

    ax1.set_title('reflect, rotate')
    ax2.set_title('shear, reflect')
    ax3.set_title('reflect, shear')
    ax4.set_title('rotate, shear')

    ax1.grid()
    ax2.grid()
    ax3.grid()
    ax4.grid()
예제 #2
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()
예제 #3
0
def combining_transforms():

    X = util.test_object(1)

    X_1 = X
    X_2 = reg.rotate(3 * np.pi / 4).dot(X)
    X_3 = reg.reflect(-1, 1).dot(reg.rotate(3 * np.pi / 4).dot(X))
    X_4 = reg.shear(0.1, 0.2).dot(
        reg.reflect(-1, 1).dot(reg.rotate(3 * np.pi / 4).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_1)
    util.plot_object(ax2, X_2)
    util.plot_object(ax3, X_3)
    util.plot_object(ax4, X_4)

    ax1.set_title('Original')
    ax2.set_title('Then rotate')
    ax3.set_title('Now reflect over x')
    ax4.set_title('Lastly, shear')

    for ax_obj in [ax1, ax2, ax3, ax4]:
        ax_obj.grid()
예제 #4
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()
예제 #5
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()
예제 #6
0
def combining_transforms():

    X = util.test_object(1)

    X_rot = reg.rotate(3 * np.pi / 7).dot(X)
    X_shear = reg.shear(0.3, 0.22).dot(X)

    X_rot_shear = reg.shear(0.1, 0.3).dot(X_rot)
    X_shear_reflect = reg.reflect(-1, 1).dot(X_shear)
    X_multicom = reg.rotate(np.pi / 3).dot(X_rot_shear)

    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_shear)
    util.plot_object(ax3, X_shear_reflect)
    util.plot_object(ax4, X_multicom)

    ax1.set_title('Original')
    ax2.set_title('Combination 1')
    ax3.set_title('Combination 2')
    ax4.set_title('Combination 3')

    ax1.grid()
    ax2.grid()
    ax3.grid()
    ax4.grid()
def combining_transforms():

    X = util.test_object(1)

    #------------------------------------------------------------------#
    # TODO: Experiment with combining transformation matrices.
    X_t = reg.rotate(np.pi/2).dot(X)*reg.reflect(-1,1).dot(X)
    return X_t
예제 #8
0
def combining_transforms():

    X = util.test_object(1)
    T = reg.reflect(-1, 1).dot(reg.rotate(np.pi / 2))
    X_t = T.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_t)
예제 #9
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()
예제 #10
0
def mutual_information_test():
    I = plt.imread('../data/cameraman.tif')
    I_mirror, _ = reg.image_transform(I, util.t2h(reg.reflect(-1, 1)))
    error_msg = "Mutual Information function is incorrectly implemented"

    # mutual information of an image with itself
    p1 = reg.joint_histogram(I, I)
    p2 = reg.joint_histogram(I, I_mirror)
    MI1 = reg.mutual_information(p1)
    MI2 = reg.mutual_information(p2)

    assert 1 - MI1 < 10e-10, error_msg + " (self MI should be 1)"
    assert MI2 < 0.8, error_msg + " (mirrored image gives MI above 0.8 (strange))"

    print('MI test successful!')
예제 #11
0
def combining_transforms():

    X = util.test_object(1)

    #------------------------------------------------------------------#
    X_t = reg.reflect(-1,1).dot(reg.rotate(2)).dot(X)