Beispiel #1
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    if len(argv) != 5:
        print "Usage: python %s <CheckerboardImage> <OutlierFraction> <CorruptedImage> <LowRankImage>" % sys.argv[0]
        sys.exit(1)

    # outlier fraction
    p = float(sys.argv[2])

    # read image
    I = sitk.ReadImage(argv[1])
    # data for processing
    X = sitk.GetArrayFromImage(I)
    # number of pixel
    N = np.prod(X.shape)

    eps = np.round(np.random.uniform(-10, 10, 100))
    idx = np.random.random_integers(0, N-1, np.round(N*p))
    X.ravel()[idx] = np.array(200+eps, dtype=np.uint8)

    # write outlier image
    J = sitk.GetImageFromArray(X)
    sitk.WriteImage(J, sys.argv[3])

    # decompose X into L+S
    L, S, _ = ialm.recover(X)

    C = sitk.GetImageFromArray(np.asarray(L, dtype=np.uint8))
    sitk.WriteImage(C, sys.argv[4])

    # compute mean-square error and Frobenius norm
    print "MSE: %.4g" % np.sqrt(np.asmatrix((L-sitk.GetArrayFromImage(I))**2).sum())
    print "Frobenius-Norm: %.4g" % np.linalg.norm(L-sitk.GetArrayFromImage(I),ord='fro')
Beispiel #2
0
 def test_recover(self):
     """Test recovery from outliers.
     """
     # run recovery
     lr, sp, _ = ialm.recover(self._data, None)
     # load baseline (no outliers)
     baseline = np.genfromtxt("im_baseline.dat")
     # Frobenius norm between recovered mat. and baseline
     d = np.linalg.norm(np.round(lr)-baseline, ord='fro')
     self.assertTrue(np.allclose(d,0.0))
Beispiel #3
0
def rpca(Y,lamda):
    t_begin = time.clock()

    gamma = lamda* np.sqrt(float(Y.shape[1])/Y.shape[0])
    low_rank, sparse, n_iter,rank, sparsity, sumSparse= ialm.recover(Y,gamma)
    gc.collect()

    t_end = time.clock()
    t_elapsed = t_end- t_begin
    print 'RPCA takes:%f seconds'%t_elapsed

    return (low_rank, sparse, n_iter,rank, sparsity, sumSparse)
Beispiel #4
0
def rpca(Y, lamda):
    t_begin = time.clock()

    gamma = lamda * np.sqrt(float(Y.shape[1]) / Y.shape[0])
    low_rank, sparse, n_iter, rank, sparsity, sumSparse = ialm.recover(
        Y, gamma)
    gc.collect()

    t_end = time.clock()
    t_elapsed = t_end - t_begin
    print 'RPCA takes:%f seconds' % t_elapsed

    return (low_rank, sparse, n_iter, rank, sparsity, sumSparse)
Beispiel #5
0
def main(argv=None):
    if argv is None:
        argv = sys.argv

    if len(argv) != 5:
        print "Usage: python %s <CheckerboardImage> <OutlierFraction> <CorruptedImage> <LowRankImage>" % sys.argv[
            0]
        sys.exit(1)

    # outlier fraction
    p = float(sys.argv[2])

    # read image
    I = sitk.ReadImage(argv[1])
    # data for processing
    X = sitk.GetArrayFromImage(I)
    # number of pixel
    N = np.prod(X.shape)

    eps = np.round(np.random.uniform(-10, 10, 100))
    idx = np.random.random_integers(0, N - 1, np.round(N * p))
    X.ravel()[idx] = np.array(200 + eps, dtype=np.uint8)

    # write outlier image
    J = sitk.GetImageFromArray(X)
    sitk.WriteImage(J, sys.argv[3])

    # decompose X into L+S
    L, S, _ = ialm.recover(X)

    C = sitk.GetImageFromArray(np.asarray(L, dtype=np.uint8))
    sitk.WriteImage(C, sys.argv[4])

    # compute mean-square error and Frobenius norm
    print "MSE: %.4g" % np.sqrt(
        np.asmatrix((L - sitk.GetArrayFromImage(I))**2).sum())
    print "Frobenius-Norm: %.4g" % np.linalg.norm(
        L - sitk.GetArrayFromImage(I), ord='fro')