コード例 #1
0
RECORD = 'multi_aniso_atoms_2D'
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
コード例 #2
0
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
from GaussDictCode.regularisation import Joubert, null

RECORD = 'multi_aniso_atoms_2D'
RECORD = None

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 = 5  # 5
コード例 #3
0
                abs(nP - n - e * c.sum(c.mul(grad, da)))), log10(e)))
#             print(nP, n, abs(grad).max(), abs(Rp.asarray()).max())
#             print((nP - n) / e, c.asarray(c.sum(c.mul(grad, da))))
#             print(abs(nP - n - e * c.sum(c.mul(e, da))), log10(e))
        print()
    print('Finished after time: ', time() - tic)


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)')
コード例 #4
0
        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)
        else:
            X = [x[j] - a.x[i, j] for j in range(3)]
コード例 #5
0
vol = odl.uniform_discr_frompartition(vol, dtype='float32')
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
        f.read_header()
        data = f.read_data().transpose((2, 1, 0))
    for i in range(0, len(angles)):
        plt.gca().clear()
        plt.imshow(log10(data[i].T))
        plt.title(str(i))
        plt.show(block=False)
        plt.pause(.1)
    plt.show()
    exit()
    raise Exception('Weird dataset... Background subtraction?')
    # First dimension is angle, second is width, third is slice
    data = asarray(data)
    # Space settings:
    dim = 3
    ASpace = AtomSpace(dim, isotropic=False)
    vol = odl.uniform_partition([-1] * 3, [1] * 3,
                                (data.shape[1], data.shape[1], data.shape[2]))
    data = ascontiguousarray(data[:, ::4, ::4], dtype='float32')
    #     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]