<jupyter_start><jupyter_text>Reconstruct 3D Shepp Logan phantom.This file demonstrates the generation of a 3D Shepp-Logan phantom followed by sinogram projection and reconstruction using MBIR. The phantom, sinogram, and reconstruction are then displayed.<jupyter_code>import numpy as np
import matplotlib.pyplot as plt
import matplotlib as mpl
import svmbir
def plot_image(img, title=None, vmin=None, vmax=None):
    """
    Function to display and save a 2D array as an image.
    :param img: 2D numpy array to display
    :param title: Title to display
    :param vmin: Value mapped to black
    :param vmax: Value mapped to white
    """

    fig = plt.figure()
    imgplot = plt.imshow(img, vmin=vmin, vmax=vmax)
    plt.title(label=title)
    imgplot.set_cmap('gray')
    plt.colorbar()
    plt.show()
    plt.close()<jupyter_output><empty_output><jupyter_text>Set Parameters<jupyter_code># Simulated image parameters
num_rows_cols = 256 # Assumes a square image
center_slice = 16
num_slices = 2*center_slice+1
display_slice = 12
# Simulated sinogram parameters
num_views = 144

# Reconstruction parameters
T = 0.1
p = 1.1
sharpness = 4.0
snr_db = 40.0

# Generate array of view angles form -180 to 180 degs
angles = np.linspace(-np.pi/2.0, np.pi/2.0, num_views, endpoint=False)<jupyter_output><empty_output><jupyter_text>Generate phantom<jupyter_code>phantom = svmbir.phantom.gen_shepp_logan_3d(num_rows_cols, num_rows_cols, num_slices)
mpl.rcParams['figure.dpi'] = 100
plot_image(phantom[display_slice], title='A phantom at z = -0.25',vmin=1., vmax=1.1)
mpl.rcParams['figure.dpi'] = 300

fig, axs = plt.subplots(4, 4)
plt.set_cmap('gray')
plt.subplots_adjust(hspace=0.5)
for i in range(0,16):
    im=axs[i//4, i%4].imshow(phantom[i*2,:, :], vmin=1.0, vmax=1.1)

fig.colorbar(im,ax=axs)
fig.suptitle('Slices of 3D Shepp Logan Phantom')
plt.show()
plt.close()<jupyter_output><empty_output><jupyter_text>Generate sinogram<jupyter_code>mpl.rcParams['figure.dpi'] = 100
sino = svmbir.project(angles, phantom, num_rows_cols)
plot_image(sino[:,display_slice,:], title='A Sinogram at z = -0.25')<jupyter_output>Found system matrix: /Users/damonli/.cache/svmbir/parbeam/sysmatrix/abd33f36e770cb3ed8e9.2Dsvmatrix<jupyter_text>MBIR reconstruction<jupyter_code># Determine resulting number of views, slices, and channels
(num_views, num_slices, num_channels) = sino.shape

# Perform MBIR reconstruction
recon = svmbir.recon(sino, angles, T=T, p=p, sharpness=sharpness, snr_db=snr_db)

# Compute Normalized Root Mean Squared Error
nrmse = svmbir.phantom.nrmse(recon, phantom)

# display reconstruction
mpl.rcParams['figure.dpi'] = 100
title = f'3D Recon at z = -0.25 with NRMSE={nrmse:.3f}.'
plot_image(recon[display_slice], title=title, vmin=1.0, vmax=1.1)
mpl.rcParams['figure.dpi'] = 300

fig, axs = plt.subplots(4, 4)
plt.set_cmap('gray')
plt.subplots_adjust(hspace=0.5)
for i in range(0,16):
    im=axs[i//4, i%4].imshow(recon[i*2,:, :], vmin=1.0, vmax=1.1)

fig.colorbar(im,ax=axs)
title = f'Slices of 3D Recon with NRMSE={nrmse:.3f}.'
fig.suptitle(title)
plt.show()
plt.close()<jupyter_output><empty_output>
{'fraction_non_alphanumeric': 0.13095238095238096, 'fraction_numerical': 0.03571428571428571, 'mean_word_length': 5.559071729957806, 'pattern_counts': {'":': 0, '<': 20, '<?xml version=': 0, '>': 20, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'chain_length': '5', 'dir': 'jupyter-structured-clean-dedup', 'id': '384449', 'license': 'BSD-3-Clause', 'n_tokens_mistral': 1309, 'n_tokens_neox': 1212, 'n_words': 268, 'path': 'docs/source/ipynb/demo_3D_shepp_logan.ipynb', 'repo_name': 'DamonLee5/svmbir', 'size': '3108'}