예제 #1
0
    def __init__(self, space):
        '''
        space must be either an AtomSpace, VolSpace or ProjSpace instance.
        AtomSpace: Fourier transform is purely analytic and maps gaussians to
            gaussians
        VolSpace: Forward map evaluates the FT on this regular grid given by to.grid
            fromSpace is ignored. Either atoms or VolSpace elements can be mapped with 
            the resulting operator and the back projection will map to VolSpace
        ProjSpace: Forward map evaluates the FT using the Fourier slice theorem. 
            Inputs must either be atoms or ProjSpace elements.

        '''

        if isinstance(space, AtomSpace):
            self.inGrid = None
            self.outGrid = None
            toSpace = space
            dim = space.dim
        elif isinstance(space, VolSpace):
            self.inGrid = space.grid
            self.outGrid = GaussFT.getGrid(space.grid)
            toSpace = VolSpace(self.outGrid)
            dim = len(space.grid)
        elif isinstance(space, ProjSpace):
            self.inGrid = tuple(space.detector) + tuple(space.ortho)
            self.outGrid = tuple(GaussFT.getGrid(space.detector))
            toSpace = ProjSpace(detector=self.outGrid, orientations=space.orientations,
                                ortho=space.ortho)
            self.outGrid += tuple(space.ortho)
            dim = len(space.detector) + 1
        else:
            raise ValueError

        Dictionary.__init__(self, space, toSpace,
                            isLinear=True, isInvertible=True, inverse=self.__inverse)

        if self.inGrid is not None:
            if dim == 2:
                from GaussDictCode.bin import FTGaussian2D
                self.__evalFT = FTGaussian2D.evaluate
                self.__derivsFT = FTGaussian2D.derivs
            else:
                from GaussDictCode.bin import FTGaussian3D
                self.__evalFT = FTGaussian3D.evaluate
                self.__derivsFT = FTGaussian3D.derivs

        self.dim = dim
예제 #2
0
RECORD = None
import odl
from GaussDictCode.dictionary_def import VolSpace, ProjSpace, AtomSpace, AtomElement
from GaussDictCode.atomFuncs import GaussTomo
from numpy import sqrt, pi, zeros, random, arange, log10
from matplotlib import pyplot as plt, animation as mv
from GaussDictCode.bin.manager import myManager
from GaussDictCode.regularisation import Joubert, null

with myManager(device='cpu', order='C', fType='float32',
               cType='complex64') as c:
    # Space settings:
    dim = 2
    device = 'GPU'  # CPU or GPU
    ASpace = AtomSpace(dim, isotropic=True)
    vol = VolSpace(odl.uniform_discr([-1] * 2, [1] * 2, [128] * 2))

    # Projection settings:
    PSpace = ProjSpace(
        odl.uniform_discr(0, pi, 30),
        odl.uniform_discr(-1.5 * sqrt(dim), 1.5 * sqrt(dim), 128))

    # Initiate Data:
    #####
    # #   These lines initiate the 2 atom demo
    gt = AtomElement(ASpace, x=[[-.5, 0], [.5, 0]], r=[.30, .10], I=1)
    #     recon = AtomElement(ASpace, [[.2, .5], [-.2, -.5]], [.18, .18], 1)
    recon = ASpace.random(10, seed=1)
    # #   These lines generate random atoms
    #     nAtoms = 1  # 5
    #     gt = ASpace.random(nAtoms, seed=2)  # 6, 10
예제 #3
0

if __name__ == '__main__':
    from numpy import pi
    import odl
    from GaussDictCode.dictionary_def import VolSpace, ProjSpace, AtomSpace, ProjElement
    from matplotlib import pyplot as plt

#     # 2D comparison
    ASpace = AtomSpace(2, isotropic=False)
    atoms = ASpace.random(2, seed=1)
    angles = odl.uniform_partition(0, 2 * pi, 360, nodes_on_bdry=True)
    detector = odl.uniform_partition(-1, 1, 256)
    vol = odl.uniform_partition([-1] * 2, [1] * 2, [128] * 2)
    myPSpace = ProjSpace(angles, detector)
    myTomo = GaussTomo(ASpace, VolSpace(vol), myPSpace, device='GPU')
    mySino = myTomo(atoms)
    odlPSpace = odl.tomo.Parallel2dGeometry(angles, detector)
    odlTomo = odl.tomo.RayTransform(
        odl.uniform_discr_frompartition(vol), odlPSpace)
    odlSino = odlTomo(myTomo.discretise(atoms).asarray())
    odlSino = ProjElement(myPSpace, odlSino.asarray())

    mySino.plot(plt.subplot('211'), aspect='auto')
    plt.title('2D Atomic Sinogram (top) and volume-sinogram (bottom)')
    odlSino.plot(plt.subplot('212'), aspect='auto')

#     # 2.5D comparison
    ASpace = AtomSpace(3, isotropic=False)
    atoms = ASpace.random(3, seed=2)
    atoms.I[:] = 1
예제 #4
0
        sz = [1] * d
        sz[i] = -1
        k[i] = v[i].reshape(sz)
    return k


if __name__ == '__main__':
    import numpy as np
    from matplotlib import pyplot as plt
    sz = [256] * 3
    x = _tomesh([10 * np.linspace(-.3, 1, s).astype('f4') for s in sz])
#     x = _tomesh([10 * np.linspace(-.3, 1, sz[0]).astype('f4'),
#                  10 * np.linspace(-.3, 1, sz[1]).astype('f4'),
#                  10 * np.linspace(-.3, 1, sz[2]).astype('f4')])
    k = _tomesh(GaussFT.getGrid(x))
    vSpace = VolSpace(x)
    fSpace = VolSpace(k)
    aSpace = AtomSpace(dim=len(sz), isotropic=False)

    a = aSpace.random(2, seed=2)
    a.r[:, :3] = (3 + a.r[:, :3]) / (3 + 1)
    a.r[:, 3:] = (0 + a.r[:, 3:]) / (3 + 1)
    a.x[:] = (a.x + 1) * 2 + 4

    # Ie^{-|R(x-m)|^2/2}
    volRep = 0
    for i in range(len(a)):
        if len(sz) == 2:
            X = [x[j] - a.x[i, j] for j in range(2)]
            Rx = [a.r[i, 0] * X[0] + a.r[i, 2] * X[1], a.r[i, 1] * X[1]]
            volRep += a.I[i] * exp(-(Rx[0] ** 2 + Rx[1] ** 2) / 2)
gt = ascontiguousarray(gt, dtype='float32')

PSpace = (angles, odl.uniform_partition([-1] * 2, [1] * 2, [64] * 2))
PSpace = odl.tomo.Parallel3dEulerGeometry(*PSpace)

# Operators
Radon = odl.tomo.RayTransform(vol, PSpace)
data = Radon(gt)

with myManager(device='cpu', order='C', fType='float32',
               cType='complex64') as c:
    # Space settings:
    dim = 3
    device = 'GPU'
    ASpace = AtomSpace(dim, isotropic=False)
    vol = VolSpace(odl.uniform_discr([-1] * 3, [1] * 3, gt.shape))

    # Projection settings:
    PSpace = ProjSpace(angles, odl.uniform_discr([-1] * 2, [1] * 2, [64] * 2))

    nAtoms = 50
    recon = ASpace.random(nAtoms, seed=1)
    c.set(recon.x[:], c.mul(recon.x, 1 / 3))
    c.set(recon.r, 10, (slice(None), slice(None, 3)))
    c.set(recon.r, 0, (slice(None), slice(3, None)))
    nAtoms = recon.I.shape[0]
    Radon = GaussTomo(ASpace, vol, PSpace, device=device)
    gt = VolElement(vol, gt)
    R = Radon(recon)
    data = ProjElement(PSpace, data.asarray().reshape(PSpace.shape))
예제 #6
0
    matplotlib.use('Agg')
import odl
from GaussDictCode.dictionary_def import VolSpace, ProjSpace, AtomSpace, AtomElement
from GaussDictCode.atomFuncs import GaussTomo
from numpy import sqrt, pi
from GaussDictCode.bin.manager import myManager

raise Exception('FT code has not been updated in a long time')

with myManager(device='cpu', order='C', fType='float32',
               cType='complex64') as c:
    # Space settings:
    dim = 3
    device = 'GPU'
    ASpace = AtomSpace(dim, isotropic=False)
    vol = VolSpace(odl.uniform_discr([-1] * 3, [1] * 3, [64] * 3))

    # Projection settings:
    #     PSpace = ProjSpace(odl.uniform_discr([0, -pi / 2], [pi, pi / 2], [50, 1]),
    #                        odl.uniform_discr([-sqrt(dim)] * 2,
    #                                          [sqrt(dim)] * 2, [64] * 2))
    PSpace = ProjSpace(
        odl.uniform_discr([0], [pi], [50]),
        odl.uniform_discr([-sqrt(dim)] * 2, [sqrt(dim)] * 2, [64] * 2))

    # Initiate Data:
    #####
    # # These lines initiate the 2 atom demo, seed=200 is a good one
    #     gt = AtomElement(ASpace, x=[[0.64, 0.78, -0.34],
    #                                 [0.29, -0.82, -0.78]], r=[[10, 10, 10, 0, 0, 0], [10, 7, 5, 0, 0, 0]], I=[2, 1])
    gt = AtomElement(ASpace, x=[[0, 0, 0]], r=[[10, 10, 10, 0, 0, 0]], I=[1])
예제 #7
0
    #     angles = angles[2:-1]
    vol = vol[::4, ::4, ::4]
    #     for i in range(0, len(angles)):
    #         plt.gca().clear()
    #         plt.imshow(data[i].T)
    #         plt.title(str(i))
    #         plt.show(block=False)
    #         plt.pause(.3)
    #     plt.show()
    #     exit()

    box = [vol.min_pt, vol.max_pt]
    PSpace = ProjSpace(
        angles,
        odl.uniform_partition(vol.min_pt[1:], vol.max_pt[1:], data.shape[1:]))
    vol = VolSpace(odl.uniform_discr_frompartition(vol, dtype='float32'))

    # Initiate Recon:
    #####
    def newAtoms(n, seed=None):
        tmp = ASpace.random(n, seed=seed)
        c.set(tmp.r, 2, (slice(None), slice(None, 3)))
        c.set(tmp.r, 0, (slice(None), slice(3, None)))
        c.set(tmp.I[:], .1)
        return tmp

    nAtoms = 50
    recon = newAtoms(nAtoms, 1)
    #####
    Radon = GaussTomo(ASpace, vol, PSpace, device='GPU')
    data = ProjElement(PSpace, data / data.max())