Ejemplo n.º 1
0
def reconstruct():
    # reconstruct a simple image

    R = np.zeros((30,30))
    for i in xrange(13):
        R[27-2*i, 2+i] = 1.
        R[27-2*i, -2-i] = 1.
    R[16,9:22] = 1.
    ncols, nrows = R.shape
    n = ncols * nrows
    m = n / 4
    # generate DCT measurement matrix
    D1 = math.sqrt(1./8) * fftpack.dct(np.eye(n), axis=0)[np.random.permutation(n)[:m]]

    # create measurements
    b = D1.dot(R.flatten())

    rec_sig = l1Min(D1, b).reshape((nrows, ncols))
    rec_sig2 = l2Min(D1, b).reshape((nrows, ncols))
    plt.subplot(1,3,1)
    plt.imshow(R, cmap=plt.cm.Greys_r, interpolation='nearest')
    plt.xticks([])
    plt.yticks([])
    plt.subplot(1,3,2)
    plt.imshow(rec_sig, cmap=plt.cm.Greys_r, interpolation='nearest')
    plt.xticks([])
    plt.yticks([])

    plt.subplot(1,3,3)
    plt.imshow(rec_sig2, cmap=plt.cm.Greys_r, interpolation='nearest')
    plt.xticks([])
    plt.yticks([])

    plt.savefig('reconstruct.pdf')
    plt.clf()
def get_coefs(samples):
    """Compute coefficients of the Chebyshev interpolant
    using the discrete cosine transform."""
    cfs = ft.dct(samples, type=1)
    cfs /= (samples.size - 1)
    cfs[::cfs.size-1] /= 2
    cfs[1::2] *= -1
    return cfs
Ejemplo n.º 3
0
def get_coefs(samples):
    """Compute coefficients of the Chebyshev interpolant
    using the discrete cosine transform."""
    cfs = ft.dct(samples, type=1)
    cfs /= (samples.size - 1)
    cfs[::cfs.size - 1] /= 2
    cfs[1::2] *= -1
    return cfs
Ejemplo n.º 4
0
def reconstruct():
    # reconstruct a simple image

    R = np.zeros((30, 30))
    for i in xrange(13):
        R[27 - 2 * i, 2 + i] = 1.
        R[27 - 2 * i, -2 - i] = 1.
    R[16, 9:22] = 1.
    ncols, nrows = R.shape
    n = ncols * nrows
    m = n / 4
    # generate DCT measurement matrix
    D1 = math.sqrt(1. / 8) * fftpack.dct(np.eye(n),
                                         axis=0)[np.random.permutation(n)[:m]]

    # create measurements
    b = D1.dot(R.flatten())

    rec_sig = l1Min(D1, b).reshape((nrows, ncols))
    rec_sig2 = l2Min(D1, b).reshape((nrows, ncols))
    plt.subplot(1, 3, 1)
    plt.imshow(R, cmap=plt.cm.Greys_r, interpolation='nearest')
    plt.xticks([])
    plt.yticks([])
    plt.subplot(1, 3, 2)
    plt.imshow(rec_sig, cmap=plt.cm.Greys_r, interpolation='nearest')
    plt.xticks([])
    plt.yticks([])

    plt.subplot(1, 3, 3)
    plt.imshow(rec_sig2, cmap=plt.cm.Greys_r, interpolation='nearest')
    plt.xticks([])
    plt.yticks([])

    plt.savefig('reconstruct.pdf')
    plt.clf()