示例#1
0
    def test_projector(self):

        data = ctdata.sets['parallel']
        data.load()
        print ' Data detector width:', data.detector_width_mm
        print ' Data projections shape:', data.projections.shape

        geom = self.geom_class(data, 2*(100,), 2*(100,))
        print ' Detector pixel width:', geom.det_col_spacing, geom.det_row_spacing

        projector = self.projector_class(geom)

        # Adjoint <Ax,y>=<x,Ad y> with x[:]=1 and y[:]=1
        rn_vol0 = Rn(geom.vol_size).element(1)
        rn_proj0 = Rn(geom.proj_size).element(1)
        rn_proj = projector.forward(rn_vol0)
        rn_vol = projector.backward(rn_proj0)
        l = rn_proj.inner(rn_proj0)
        r = rn_vol0.inner(rn_vol)
        print(' Adjoint with x[:]=1 and y[:]=1:')
        print('  <Ax,y> = <x,Ad y> : {0} = {1}'.format(l, r))
        print('  |<Ax,y> - <x,Ad y>| = {0}'.format(np.abs(l - r)))
        print('  <Ax,y> / <x,Ad y>  -1 = {0}'.format(l / r -1))

        # Back-project phantom data
        rn_proj = Rn(geom.proj_size).element(data.projections.ravel())
        rn_bp = projector.backward(rn_proj)

        # FBP
        rn_fbp = projector.fbp(rn_proj)
        rec = np.reshape(rn_fbp.data, geom.vol_shape)

        # import scipy.io as sio
        # sio.savemat(self.matfile, {'parallel_fbp': rec})
        # plt.imshow(rec, cmap=plt.cm.Greys)
        # plt.show()

        projector.clear_astra_memory()