示例#1
0
def filter_3d_1d(mat_3D, lam1):
    for i in range(mat_3D.shape[0]):
        for j in range(mat_3D.shape[1]):
            line = mat_3D[i, j]
            line = ptv.tv2_1d(line, lam1)
            mat_3D[i, j] = line
    return mat_3D
示例#2
0
def test_tv2_1d():
    methods = ('ms', 'pg', 'mspg')
    for _ in range(20):
        dimension = np.random.randint(1e1, 3e1)
        x = 100 * np.random.randn(dimension)
        w = 20 * np.random.rand()
        solutions = [tv2_1d(x, w, method=method) for method in methods]
        for i in range(len(solutions) - 1):
            assert np.allclose(solutions[i], solutions[i + 1], atol=1e-3)
示例#3
0
def test_tv2_1d():
    methods = ('ms', 'pg', 'mspg')
    for _ in range(20):
        dimension = np.random.randint(1e1, 3e1)
        x = 100*np.random.randn(dimension)
        w = 20*np.random.rand()
        solutions = [tv2_1d(x, w, method=method) for method in methods]
        for i in range(len(solutions)-1):
            assert np.allclose(solutions[i], solutions[i+1], atol=1e-3)
plt.show()

### TV-L2 filtering

# Generate sinusoidal signal
N = 1000
s = sin(np.arange(1, N + 1) / 10.0) + sin(np.arange(1, N + 1) / 100.0)

# Introduce noise
n = s + 0.5 * randn(*shape(s))

# Filter using TV-L2
lam = 100
print('Filtering signal with TV-L2...')
start = time.time()
f = ptv.tv2_1d(n, lam)
end = time.time()
print('Elapsed time ' + str(end - start))

# Plot results
plt.subplot(3, 1, 1)
plt.title('TVL2 filtering')
plt.plot(s)
plt.ylabel('Original')
grid(True)

plt.subplot(3, 1, 2)
plt.plot(n)
plt.ylabel('Noisy')
grid(True)
示例#5
0
plt.show()

### TV-L2 filtering

# Generate sinusoidal signal
N = 1000
s = np.sin(np.arange(1,N+1)/10.0) + np.sin(np.arange(1,N+1)/100.0)

# Introduce noise
n = s + 0.5*np.random.randn(*np.shape(s))

# Filter using TV-L2
lam=100;
print('Filtering signal with TV-L2...')
start = time.time()
f = ptv.tv2_1d(n,lam);
end = time.time()
print('Elapsed time ' + str(end-start))

# Plot results
plt.subplot(3, 1, 1)
plt.title('TVL2 filtering')
plt.plot(s)
plt.ylabel('Original')
plt.grid(True)

plt.subplot(3, 1, 2)
plt.plot(n)
plt.ylabel('Noisy')
plt.grid(True)