Tomography/Laminography Reconstruction

This notebook demonstrates a simulated tomography/laminography reconstruction using tike. Since laminography is just a specific case of tomography, one example should be sufficient.

[1]:
import logging
import lzma
import pickle

import matplotlib.pyplot as plt
import numpy as np

import tike.lamino
import tike.view
[2]:
for module in [tike, np]:
    print("{} is version {}".format(module.__name__, module.__version__))
tike is version 0.15.2.dev39+g7ca618d.d20210126
numpy is version 1.19.5

Create test data

Define the object

[3]:
with lzma.open('../../../tests/data/nalm256.pickle.lzma', 'rb') as file:
    original = pickle.load(file)[::2, ::2, ::2].astype('complex64')
original.shape
[3]:
(128, 128, 128)
[4]:
# Mark object to make it asymmetric
original[20:25, 60:64, 20:25] = 0.001
[5]:
plt.figure()
tike.view.plot_complex(np.sum(original, axis=0))
plt.show()
../_images/examples_tomo_6_0.png
[6]:
plt.figure()
tike.view.plot_complex(np.sum(original, axis=1))
plt.show()
../_images/examples_tomo_7_0.png
[7]:
plt.figure()
tike.view.plot_complex(np.sum(original, axis=2))
plt.show()
../_images/examples_tomo_8_0.png

Define trajectory

[8]:
theta = np.linspace(0, np.pi, 128, endpoint=False, dtype='float32')
theta.shape
[8]:
(128,)

Simulate data acquisition

[9]:
tilt=np.pi/2
data = tike.lamino.simulate(obj=original, theta=theta, tilt=tilt)
[10]:
plt.figure()
tike.view.plot_complex(data[0])
plt.show()
../_images/examples_tomo_13_0.png

Reconstruct the data

[11]:
logging.basicConfig(level=logging.INFO)
result = {
    'obj': np.zeros(original.shape, dtype='complex64')
}
[12]:
for i in range(5):
    result = tike.lamino.reconstruct(
        **result,
        theta=theta,
        data=data,
        algorithm='cgrad',
        num_iter=4,
        tilt=tilt,
    )
    plt.figure()
    tike.view.plot_complex(result['obj'][64])
    plt.show()
    plt.figure()
    tike.view.plot_complex(result['obj'][:, 64])
    plt.show()
    plt.figure()
    tike.view.plot_complex(result['obj'][:, :, 64])
    plt.show()
INFO:tike.lamino.lamino:cgrad on 128 by 128 by 128 volume for 4 iterations.
INFO:tike.lamino.solvers.cgrad:Estimate step length from forward adjoint operations.
INFO:tike.opt:line_search: 0 backtracks; 1.000e+00 -> 1.000e+00; cost 1.591542e+00
INFO:tike.opt:line_search: 0 backtracks; 1.000e+00 -> 1.000e+00; cost 5.836657e-01
INFO:tike.opt:line_search: 0 backtracks; 1.000e+00 -> 1.000e+00; cost 5.836524e-01
INFO:tike.opt:line_search: 0 backtracks; 1.000e+00 -> 1.000e+00; cost 1.908309e-01
INFO:tike.lamino.solvers.cgrad:    object cost is +1.90831e-01
INFO:tike.lamino.solvers.cgrad:Estimate step length from forward adjoint operations.
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.566347e-01
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 9.627850e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 7.772186e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.909871e-02
INFO:tike.lamino.solvers.cgrad:    object cost is +5.90987e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.775804e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.262215e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.586865e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.953092e-02
INFO:tike.lamino.solvers.cgrad:    object cost is +2.95309e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.622433e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.186004e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.988655e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.745226e-02
INFO:tike.lamino.solvers.cgrad:    object cost is +1.74523e-02
../_images/examples_tomo_16_1.png
../_images/examples_tomo_16_2.png
../_images/examples_tomo_16_3.png
INFO:tike.lamino.lamino:cgrad on 128 by 128 by 128 volume for 4 iterations.
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.546917e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.427541e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.284465e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.125180e-02
INFO:tike.lamino.solvers.cgrad:    object cost is +1.12518e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.028463e-02
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 8.848310e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 8.371785e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 6.706986e-03
INFO:tike.lamino.solvers.cgrad:    object cost is +6.70699e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.498258e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.201392e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.760564e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.412584e-03
INFO:tike.lamino.solvers.cgrad:    object cost is +4.41258e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.184069e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.801845e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.567511e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.226189e-03
INFO:tike.lamino.solvers.cgrad:    object cost is +3.22619e-03
../_images/examples_tomo_16_5.png
../_images/examples_tomo_16_6.png
../_images/examples_tomo_16_7.png
INFO:tike.lamino.lamino:cgrad on 128 by 128 by 128 volume for 4 iterations.
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.935811e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.771729e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.600668e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.432635e-03
INFO:tike.lamino.solvers.cgrad:    object cost is +2.43264e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.317104e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.096016e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.013589e-03
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 9.717180e-04
INFO:tike.lamino.solvers.cgrad:    object cost is +9.71718e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 6.740721e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.917902e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.352943e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.183609e-04
INFO:tike.lamino.solvers.cgrad:    object cost is +5.18361e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.086251e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.379081e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.973193e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.986875e-04
INFO:tike.lamino.solvers.cgrad:    object cost is +2.98688e-04
../_images/examples_tomo_16_9.png
../_images/examples_tomo_16_10.png
../_images/examples_tomo_16_11.png
INFO:tike.lamino.lamino:cgrad on 128 by 128 by 128 volume for 4 iterations.
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.318308e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.201903e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.079567e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 2.023986e-04
INFO:tike.lamino.solvers.cgrad:    object cost is +2.02399e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.985125e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.827621e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.741439e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.393378e-04
INFO:tike.lamino.solvers.cgrad:    object cost is +1.39338e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.124756e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.079692e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.027424e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 1.000923e-04
INFO:tike.lamino.solvers.cgrad:    object cost is +1.00092e-04
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 9.819519e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 9.169694e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 8.798604e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 7.626788e-05
INFO:tike.lamino.solvers.cgrad:    object cost is +7.62679e-05
../_images/examples_tomo_16_13.png
../_images/examples_tomo_16_14.png
../_images/examples_tomo_16_15.png
INFO:tike.lamino.lamino:cgrad on 128 by 128 by 128 volume for 4 iterations.
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 6.627871e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 6.390986e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 6.122344e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.957991e-05
INFO:tike.lamino.solvers.cgrad:    object cost is +5.95799e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.842850e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.495198e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 5.301681e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.691230e-05
INFO:tike.lamino.solvers.cgrad:    object cost is +4.69123e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.158177e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 4.022623e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.864486e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.760109e-05
INFO:tike.lamino.solvers.cgrad:    object cost is +3.76011e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.687003e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.484281e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.370501e-05
INFO:tike.opt:line_search: 0 backtracks; 1.610e+04 -> 1.610e+04; cost 3.046333e-05
INFO:tike.lamino.solvers.cgrad:    object cost is +3.04633e-05
../_images/examples_tomo_16_17.png
../_images/examples_tomo_16_18.png
../_images/examples_tomo_16_19.png