def test_01(self): N = 64 L = 20 x = np.cos(np.linspace(0, np.pi, N))[np.newaxis, :] y = np.cos(np.linspace(0, np.pi, N))[:, np.newaxis] U = x * y V = np.random.randn(N, N) t = np.sort(np.abs(V).ravel())[V.size - L] V[np.abs(V) < t] = 0 D = U + V lmbda = 0.1 opt = spline.SplineL1.Options({ 'Verbose': False, 'gEvalY': False, 'MaxMainIter': 250, 'RelStopTol': 5e-4, 'DFidWeight': V == 0, 'AutoRho': { 'Enabled': True } }) b = spline.SplineL1(D, lmbda, opt) X = b.solve() assert (np.abs(b.itstat[-1].ObjFun - 0.333606246) < 1e-6) assert (sm.mse(U, X) < 1e-6)
def test_02(self): N = 8 D = np.random.randn(N, N) lmbda = 0.1 try: b = spline.SplineL1(D, lmbda) b.solve() except Exception as e: print(e) assert (0)
def test_03(self): N = 8 D = np.random.randn(N, N) lmbda = 0.1 dt = np.float64 opt = spline.SplineL1.Options({ 'Verbose': False, 'MaxMainIter': 20, 'AutoRho': { 'Enabled': True }, 'DataType': dt }) b = spline.SplineL1(D, lmbda, opt=opt) b.solve() assert (b.X.dtype == dt) assert (b.Y.dtype == dt) assert (b.U.dtype == dt)
imgn = util.spnoise(img, 0.2) """ Set regularization parameter and options for ℓ1-spline solver. The regularization parameter used here has been manually selected for good performance. """ lmbda = 5.0 opt = spline.SplineL1.Options({'Verbose': True, 'gEvalY': False}) """ Create solver object and solve, returning the the denoised image ``imgr``. """ b = spline.SplineL1(imgn, lmbda, opt) imgr = b.solve() """ Display solve time and denoising performance. """ print("SplineL1 solve time: %5.2f s" % b.timer.elapsed('solve')) print("Noisy image PSNR: %5.2f dB" % metric.psnr(img, imgn)) print("Denoised image PSNR: %5.2f dB" % metric.psnr(img, imgr)) """ Display reference, corrupted, and denoised images. """