Exemplo n.º 1
0
def test_convolve():
    w = np.array([[0, 1, 0], [1, 2, 1], [0, 1, 0]]) / 6.
    A = convolve(40, 40, w)

    p = np.prod(HR.shape)
    c1 = (A * HR.flat).reshape(HR.shape)
    c2 = ndi.convolve(HR, w)

    assert np.linalg.norm(c1 - c2) / np.prod(HR.shape) < 0.5
Exemplo n.º 2
0
def test_convolve():
    w = np.array([[0, 1, 0],
                  [1, 2, 1],
                  [0, 1, 0]]) / 6.
    A = convolve(40, 40, w)

    p = np.prod(HR.shape)
    c1 = (A * HR.flat).reshape(HR.shape)
    c2 = ndi.convolve(HR, w)

    assert np.linalg.norm(c1 - c2) / np.prod(HR.shape) < 0.5
Exemplo n.º 3
0

if __name__ == "__main__":
    scale = 3

    theta = 5 / 180. * np.pi
    C = np.cos(theta)
    S = np.sin(theta)
    tx, ty = 0, 0

    A = bilinear(
        HR.shape[0], HR.shape[1],
        [np.array([[C / scale, -S, tx], [S, C / scale, ty], [0, 0, 1.]])],
        HR.shape[0] / scale, HR.shape[1] / scale)

    C = convolve(HR.shape[0], HR.shape[1], gauss(5, std=1))

    import matplotlib.pyplot as plt
    plt.spy((A * C).todense())

    plt.figure()
    fwd = (A * C * HR.flat)
    rev = C.T * A.T * fwd

    plt.subplot(1, 3, 1)
    plt.imshow(HR, cmap=plt.cm.gray, interpolation='nearest')

    plt.subplot(1, 3, 2)
    plt.imshow(fwd.reshape(np.array(HR.shape) / scale),
               interpolation='nearest',
               cmap=plt.cm.gray)
Exemplo n.º 4
0
if __name__ == "__main__":
    scale = 3

    theta = 5 / 180. * np.pi
    C = np.cos(theta)
    S = np.sin(theta)
    tx, ty = 0, 0

    A = bilinear(HR.shape[0], HR.shape[1],
                 [np.array([[C/scale, -S,        tx],
                            [S,        C/scale,  ty],
                            [0,        0,        1.]])],
                  HR.shape[0] / scale, HR.shape[1] / scale)


    C = convolve(HR.shape[0], HR.shape[1], gauss(5, std=1))

    import matplotlib.pyplot as plt
    plt.spy((A * C).todense())

    plt.figure()
    fwd = (A * C * HR.flat)
    rev = C.T * A.T * fwd

    plt.subplot(1, 3, 1)
    plt.imshow(HR, cmap=plt.cm.gray, interpolation='nearest')

    plt.subplot(1, 3, 2)
    plt.imshow(fwd.reshape(np.array(HR.shape) / scale),
               interpolation='nearest', cmap=plt.cm.gray)
    plt.subplot(1, 3, 3)