Exemple #1
0
def test_image_shape():
    obj = tomograpy.centered_cubic_map(3, cube_shape0)
    # projection
    pj_times = np.empty(len(image_shapes) + 1)
    pj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d),
                                        s,
                                        n_images=n_images)
        tomograpy.projector(data, obj)
        pj_times[i + 1] = time.time()
    pj_times = pj_times[1:] - pj_times[:-1]
    # backprojection
    bpj_times = np.empty(len(image_shapes) + 1)
    bpj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d),
                                        s,
                                        n_images=n_images)
        tomograpy.backprojector(data, obj)
        bpj_times[i + 1] = time.time()
    bpj_times = bpj_times[1:] - bpj_times[:-1]
    # pretty print
    text = ''
    text += 'Image shape'
    text += ''.join(
        [' & ' + str(s) + " $\\times$ " + str(s) for s in image_shapes])
    text += ' \\\\ \n' + 'Projection (s)'
    text += ''.join([' & %2.2f' % pjt for pjt in pj_times])
    text += ' \\\\ \n' + 'Backprojection (s)'
    text += ''.join([' & %2.2f' % bpjt for bpjt in bpj_times])
    text += ' \\\\ \n'
    print text
def test_image_shape():
    obj = tomograpy.centered_cubic_map(3, cube_shape0)
    # projection
    pj_times = np.empty(len(image_shapes) + 1)
    pj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d), s, n_images=n_images)
        tomograpy.projector(data, obj)
        pj_times[i + 1] = time.time()
    pj_times = pj_times[1:] - pj_times[:-1]
    # backprojection
    bpj_times = np.empty(len(image_shapes) + 1)
    bpj_times[0] = time.time()
    for i, s in enumerate(image_shapes):
        data = tomograpy.centered_stack(tomograpy.fov(obj, d), s, n_images=n_images)
        tomograpy.backprojector(data, obj)
        bpj_times[i + 1] = time.time()
    bpj_times = bpj_times[1:] - bpj_times[:-1]
    # pretty print
    text = ''
    text += 'Image shape'
    text += ''.join([' & ' + str(s) + " $\\times$ " + str(s)  for s in image_shapes])
    text += ' \\\\ \n' + 'Projection (s)'
    text += ''.join([' & %2.2f' % pjt for pjt in pj_times])
    text += ' \\\\ \n' + 'Backprojection (s)'
    text += ''.join([' & %2.2f' % bpjt for bpjt in bpj_times])
    text += ' \\\\ \n'
    print text
Exemple #3
0
def test_cores():
    obj = tomograpy.centered_cubic_map(3, cube_shape0)
    data = tomograpy.centered_stack(tomograpy.fov(obj, d),
                                    data_shape0,
                                    n_images=n_images)
    # projection
    pj_times = np.empty(nthread_max + 1)
    pj_times[0] = time.time()
    for nt in xrange(nthread_max):
        tomograpy.projector(data, obj, nthread=nt + 1)
        pj_times[nt + 1] = time.time()
    pj_times = pj_times[1:] - pj_times[:-1]
    # backprojection
    bpj_times = np.empty(nthread_max + 1)
    bpj_times[0] = time.time()
    for nt in xrange(nthread_max):
        tomograpy.backprojector(data, obj, nthread=nt + 1)
        bpj_times[nt + 1] = time.time()
    bpj_times = bpj_times[1:] - bpj_times[:-1]
    # pretty print
    text = ''
    text += 'Cores'
    text += ''.join([' & ' + str(i + 1) for i in xrange(nthread_max)])
    text += ' \\\\ \n' + 'Projection (s)'
    text += ''.join([' & %2.2f' % pjt for pjt in pj_times])
    text += ' \\\\ \n' + 'Backprojection (s)'
    text += ''.join([' & %2.2f' % bpjt for bpjt in bpj_times])
    text += ' \\\\ \n'
    print text
def test_cores():
    obj = tomograpy.centered_cubic_map(3, cube_shape0)
    data = tomograpy.centered_stack(tomograpy.fov(obj, d), data_shape0, n_images=n_images)
    # projection
    pj_times = np.empty(nthread_max + 1)
    pj_times[0] = time.time()
    for nt in xrange(nthread_max):
        tomograpy.projector(data, obj, nthread=nt + 1)
        pj_times[nt + 1] = time.time()
    pj_times = pj_times[1:] - pj_times[:-1]
    # backprojection
    bpj_times = np.empty(nthread_max + 1)
    bpj_times[0] = time.time()
    for nt in xrange(nthread_max):
        tomograpy.backprojector(data, obj, nthread=nt + 1)
        bpj_times[nt + 1] = time.time()
    bpj_times = bpj_times[1:] - bpj_times[:-1]
    # pretty print
    text = ''
    text += 'Cores'
    text += ''.join([' & ' + str(i + 1)  for i in xrange(nthread_max)])
    text += ' \\\\ \n' + 'Projection (s)'
    text += ''.join([' & %2.2f' % pjt for pjt in pj_times])
    text += ' \\\\ \n' + 'Backprojection (s)'
    text += ''.join([' & %2.2f' % bpjt for bpjt in bpj_times])
    text += ' \\\\ \n'
    print text
Exemple #5
0
#!/usr/bin/env python
import time
import numpy as np
import tomograpy
import lo
# object
obj = tomograpy.centered_cubic_map(3, 32)
obj[:] = tomograpy.phantom.shepp_logan(obj.shape)
# data
radius = 200.
a = tomograpy.fov(obj.header, radius)
data = tomograpy.centered_stack(a,
                                128,
                                n_images=60,
                                radius=radius,
                                max_lon=np.pi)
# projector
P = tomograpy.lo(data.header, obj.header)
# projection
t = time.time()
data = tomograpy.projector(data, obj)
print("projection time : " + str(time.time() - t))
# data
y = data.flatten()
# backprojection
t = time.time()
x0 = P.T * y
bpj = x0.reshape(obj.shape)
print("projection time : " + str(time.time() - t))
# priors
Ds = [lo.diff(obj.shape, axis=i) for i in xrange(3)]
#!/usr/bin/env python
import time
import numpy as np
import tomograpy
import lo
# object
obj = tomograpy.centered_cubic_map(10, 64)
obj[:] = tomograpy.phantom.shepp_logan(obj.shape)
# data 
radius = 200
a = tomograpy.fov(obj, radius)
data = tomograpy.centered_stack(a, 128, n_images=60, radius=radius, max_lon=np.pi)
# model
kwargs = {"pb":"pb", "obj_rmin":1.5, "data_rmin":1.5}
P, D, obj_mask, data_mask = tomograpy.models.thomson(data, obj, u=.5, **kwargs)
# projection
t = time.time()
data[:] = (P * obj.ravel()).reshape(data.shape)
print("projection time : " + str(time.time() - t))
# data
# backprojection
t = time.time()
x0 = P.T * data.ravel()
bpj = x0.reshape(obj.shape)
print("backprojection time : " + str(time.time() - t))
# inversion using scipy.sparse.linalg
t = time.time()
sol = lo.acg(P, data.ravel(), D, 1e-3 * np.ones(3),  maxiter=100, tol=1e-8)
sol = sol.reshape(obj.shape)
print("inversion time : " + str(time.time() - t))
#!/usr/bin/env python
import time
import numpy as np
import tomograpy
# object
obj = tomograpy.centered_cubic_map(3, 128, fill=1.)
# data
radius = 200.
a = tomograpy.fov(obj.header, radius)
data = tomograpy.centered_stack(a, 128, n_images=17, radius=200., max_lon=np.pi)
# projection
t = time.time()
data = tomograpy.projector(data, obj, obstacle="sun")
print("projection time : " + str(time.time() - t))
# backprojection
obj0 = tomograpy.centered_cubic_map(3, 128, fill=0.)
t = time.time()
obj0 = tomograpy.backprojector(data, obj0, obstacle="sun")
print("backprojection time : " + str(time.time() - t))
#!/usr/bin/env python
import time
import numpy as np
import tomograpy
import lo
# object
obj = tomograpy.centered_cubic_map(10, 64)
obj[:] = tomograpy.phantom.shepp_logan(obj.shape)
# data
radius = 200
a = tomograpy.fov(obj, radius)
data = tomograpy.centered_stack(a,
                                128,
                                n_images=60,
                                radius=radius,
                                max_lon=np.pi)
# model
kwargs = {"pb": "pb", "obj_rmin": 1.5, "data_rmin": 1.5}
P, D, obj_mask, data_mask = tomograpy.models.thomson(data, obj, u=.5, **kwargs)
# projection
t = time.time()
data[:] = (P * obj.ravel()).reshape(data.shape)
print("projection time : " + str(time.time() - t))
# data
# backprojection
t = time.time()
x0 = P.T * data.ravel()
bpj = x0.reshape(obj.shape)
print("backprojection time : " + str(time.time() - t))
# inversion using scipy.sparse.linalg
t = time.time()
Exemple #9
0
#!/usr/bin/env python
import time
import numpy as np
import tomograpy
# object
object_header = tomograpy.centered_cubic_map_header(3, 128)
obj = tomograpy.simu.object_from_header(object_header, fill=1.)
# data
radius = 200.
a = tomograpy.fov(object_header, radius)
data = tomograpy.centered_stack(a, 128, n_images=60, radius=200., max_lon=np.pi)
# projection
t = time.time()
data = tomograpy.projector(data, obj)
print("projection time : " + str(time.time() - t))
# backprojection
t = time.time()
data[:] = 1.
obj0 = tomograpy.simu.object_from_header(object_header, fill=0.)
obj0 = tomograpy.backprojector(data, obj0)
print("backprojection time : " + str(time.time() - t))

obj1 = tomograpy.simu.object_from_header(object_header, fill=0.)
obj1 = tomograpy.backprojector(data, obj1)