Ejemplo n.º 1
0
 def test_tv(self):
     geom = Geometry(2)
     proj_vec = Rn(geom.proj_size).element(1)
     cp = ODLChambollePock(geom, proj_vec)
     cp.least_squares(3, L=131.0, non_negativiy_constraint=False,
                      tv_norm=1,
                      verbose=False)
Ejemplo n.º 2
0
    def test_adjoint_scaling_factor(self):
        """Test if back-projector A^* is adjoint of forward projector A:

            <A x, y>_D = <x,A^* y>_I .

        Define scaling factor as A^* = s B where is the implemented
        back-projector. Thus,

            s = <A x, y>_D / <x,B y>_I ,

        or using y = A x

            s = <A x, A x>_D / <x,B A x>_I .
        """
        geom = Geometry(2)

        # x = ones() and y = A x
        vol_rn = Rn(geom.vol_size)
        vol_rn_ones = vol_rn.element(1)
        proj_rn = Rn(geom.proj_size)
        projector = ODLProjector(geom, vol_rn, proj_rn)

        proj = projector.forward(vol_rn_ones)
        vol = projector.backward(proj)

        s0 = proj.norm() ** 2 / vol_rn._inner(vol, vol_rn_ones)

        # x = ones(), y = ones()
        vol_rn = Rn(geom.vol_size)
        vol_rn_ones = vol_rn.element(1)
        proj_rn = Rn(geom.proj_size)
        proj_rn_ones = proj_rn.element(1)

        projector = ODLProjector(geom, vol_rn, proj_rn)

        proj = projector.forward(vol_rn_ones)
        vol = projector.backward(proj_rn_ones)

        s1 = proj.inner(proj_rn_ones) / vol_rn_ones.inner(vol)

        # implemented function
        proj_vec = Rn(geom.proj_size).element(1)
        cp = ODLChambollePock(geom, proj_vec)
        cp.adjoint_scaling_factor()
        s2 = cp.adj_scal_fac
        self.assertEqual(s1, s2)

        print('Scaling factors:', s0, s1, s2)

        projector.clear_astra_memory()
Ejemplo n.º 3
0
    def test_creation_of_vector_in_rn(self):

        geom = Geometry(2)

        rn = Rn(geom.proj_size)
        self.assertEqual(type(rn).__name__, 'Rn')
        rn_vec = rn.element(np.zeros(geom.proj_size))
        self.assertEqual(type(rn_vec).__name__, 'Vector')
        self.assertEqual(rn.dtype, 'float')
        self.assertEqual(rn.field, odl.RealNumbers())

        ODLChambollePock(geom)
Ejemplo n.º 4
0
 def test_least_squares_method(self):
     geom = Geometry(2)
     proj_vec = Rn(geom.proj_size).element(1)
     cp = ODLChambollePock(geom, proj_vec)
     num_iter = 3
     cp.least_squares(num_iter, verbose=False)
Ejemplo n.º 5
0
    def test_matrix_norm(self):
        """Compute matrix norm of forward/backward projector using power
        norm. """

        geom = Geometry(2)
        proj_vec = Rn(geom.proj_size).element(1)

        # Compute norm for simple least squares
        cp = ODLChambollePock(geom, proj_vec)
        self.assertEqual(cp.adj_scal_fac, 1)
        mat_norm0 = cp.matrix_norm(iterations=4,
                                   vol_init=1,
                                   intermediate_results=True)
        self.assertTrue(mat_norm0[-1] > 0)

        # Resume computation
        mat_norm1, vol = cp.matrix_norm(iterations=3,
                                        vol_init=1, intermediate_results=True,
                                        return_volume=True)
        mat_norm2 = cp.matrix_norm(iterations=4, vol_init=vol,
                                   intermediate_results=True)
        self.assertNotEqual(mat_norm0[0], mat_norm2[0])

        self.assertEqual(mat_norm0[3], mat_norm2[0])

        # Compute norm for TV
        mat_norm3 = cp.matrix_norm(iterations=4, vol_init=1, tv_norm=True,
                                   intermediate_results=True)

        self.assertFalse(np.array_equal(mat_norm2, mat_norm3))
        print('LS unit init volume:', mat_norm2)
        print('TV unit init volume:', mat_norm3)

        # Use non-homogeneous initial volume
        v0 = np.random.rand(geom.vol_size)
        mat_norm4 = cp.matrix_norm(iterations=4, vol_init=v0, tv_norm=False,
                                   intermediate_results=True)
        mat_norm5 = cp.matrix_norm(iterations=4, vol_init=v0, tv_norm=True,
                                   intermediate_results=True)
        print('LS random init volume:', mat_norm4)
        print('TV random init volume:', mat_norm5)

        # test with adjoint scaling factor for backprojector
        self.assertEqual(cp.adj_scal_fac, 1)
        cp.adjoint_scaling_factor()
        self.assertFalse(cp.adj_scal_fac == 1)
        print('adjoint scaling factor:', cp.adj_scal_fac)

        mat_norm6 = cp.matrix_norm(iterations=4, vol_init=1, tv_norm=False,
                                   intermediate_results=True)
        mat_norm7 = cp.matrix_norm(iterations=4, vol_init=1, tv_norm=True,
                                   intermediate_results=True)

        print('LS init volume, adjoint rescaled:', mat_norm6)
        print('TV init volume, adjoint rescaled:', mat_norm7)