コード例 #1
0
def test_bilinear():
    H = np.array([[1 / 2., 0, 0], [0, 1 / 2., 0], [0, 0, 1]])
    A = bilinear(HR.shape[0], HR.shape[1], [H, H], HR.shape[0] / 2,
                 HR.shape[1] / 2)

    p = np.prod(HR.shape)
    assert_equal(A.shape, (2 * p / 4, np.prod(HR.shape)))

    HR_small = (A[p / 4:, :] * HR.flat).reshape(np.array(HR.shape) / 2)
    err_norm = np.linalg.norm(ndi.zoom(HR, 0.5) - HR_small)
    err_norm /= np.prod(HR_small.shape)

    assert err_norm < 2
コード例 #2
0
ファイル: test_operators.py プロジェクト: Germanc/supreme
def test_bilinear():
    H = np.array([[1/2., 0,    0],
                  [0,    1/2., 0],
                  [0,    0,    1]])
    A = bilinear(HR.shape[0], HR.shape[1],
                 [H, H],
                 HR.shape[0] / 2, HR.shape[1]/2)

    p = np.prod(HR.shape)
    assert_equal(A.shape, (2 * p/4, np.prod(HR.shape)))

    HR_small = (A[p/4:, :] * HR.flat).reshape(np.array(HR.shape) / 2)
    err_norm = np.linalg.norm(ndi.zoom(HR, 0.5) - HR_small)
    err_norm /= np.prod(HR_small.shape)

    assert err_norm < 2
コード例 #3
0
    X = np.array([[1, 2, 3], [4, 5, 6]])
    Y = scipy.linalg.block_diag(X, X, X)
    bd = block_diag(X.shape[0], X.shape[1], X.shape[0] * 3, X.shape[1] * 3)
    assert_array_equal((bd * X.flat).reshape(np.array(X.shape) * 3), Y)


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)
コード例 #4
0
ファイル: test_operators.py プロジェクト: Germanc/supreme
    Y = scipy.linalg.block_diag(X, X, X)
    bd = block_diag(X.shape[0], X.shape[1],
                    X.shape[0] * 3, X.shape[1] * 3)
    assert_array_equal((bd * X.flat).reshape(np.array(X.shape) * 3), Y)

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')