.. DO NOT EDIT. .. THIS FILE WAS AUTOMATICALLY GENERATED BY SPHINX-GALLERY. .. TO MAKE CHANGES, EDIT THE SOURCE PYTHON FILE: .. "demos\03_geometry\d26_ShortScanWangWeights.py" .. LINE NUMBERS ARE GIVEN BELOW. .. only:: html .. note:: :class: sphx-glr-download-link-note :ref:`Go to the end ` to download the full example code. .. rst-class:: sphx-glr-example-title .. _sphx_glr_demos_03_geometry_d26_ShortScanWangWeights.py: Shifted detector on a short scan ================================ Why Wang weights are skipped on short scans, shown on a uniform cylinder. Source: `Python/demos/d26_ShortScanWangWeights.py `__ ยท `MATLAB/Demos/d26_ShortScanWangWeights.m `__ .. dropdown:: MATLAB version of this demo :icon: code .. literalinclude:: /../MATLAB/Demos/d26_ShortScanWangWeights.m :language: matlab .. GENERATED FROM PYTHON SOURCE LINES 15-70 .. image-sg:: /demos/03_geometry/images/sphx_glr_d26_ShortScanWangWeights_001.png :alt: 200-degree scan of a uniform cylinder - Wang detector-offset weights need a full circle, centred detector (reference) left/right interior ratio 1.00, 0.1 mm offset, Wang weights applied (before) left/right interior ratio 1.17, 0.1 mm offset, Wang skipped on the short scan (after) left/right interior ratio 1.00 :srcset: /demos/03_geometry/images/sphx_glr_d26_ShortScanWangWeights_001.png :class: sphx-glr-single-img .. rst-class:: sphx-glr-script-out .. code-block:: none centred detector (reference): left 0.02000 right 0.02000 ratio 1.000 0.1 mm offset, Wang weights applied (before): left 0.02156 right 0.01840 ratio 1.171 0.1 mm offset, Wang skipped on the short scan (after): left 0.02000 right 0.02000 ratio 1.000 | .. code-block:: Python import numpy as np import tigre import tigre.algorithms as algs import matplotlib.pyplot as plt geo = tigre.geometry_default(high_resolution=False) geo.nVoxel = np.array([64, 64, 64]) geo.sVoxel = np.array([64.0, 64.0, 64.0]) geo.dVoxel = geo.sVoxel / geo.nVoxel zz, yy, xx = np.mgrid[:64, :64, :64] mu = 0.02 phantom = (((yy - 31.5) ** 2 + (xx - 31.5) ** 2 <= 20 ** 2) * mu).astype(np.float32) core = (yy - 31.5) ** 2 + (xx - 31.5) ** 2 <= 14 ** 2 angles = np.linspace(0, np.deg2rad(200), 200) # short scan proj = tigre.Ax(phantom, geo, angles) def lr(vol): left = float(vol[16:48, :, :32][core[16:48, :, :32]].mean()) right = float(vol[16:48, :, 32:][core[16:48, :, 32:]].mean()) return left, right vol_ref = algs.fdk(proj, geo, angles) # centred detector geo_off = tigre.geometry_default(high_resolution=False) geo_off.nVoxel, geo_off.sVoxel, geo_off.dVoxel = geo.nVoxel, geo.sVoxel, geo.dVoxel geo_off.offDetector = np.array([0.0, 0.1]) # 0.1 mm: a fraction of a pixel # The old behaviour: Wang weights applied because offDetector != 0. Reproduce # it by calling the Wang path directly on a full-circle-shaped call. from tigre.algorithms import single_pass_algorithms as spa _orig = spa.is_short_scan spa.is_short_scan = lambda a: False # force the pre-fix path vol_wang = algs.fdk(proj, geo_off, angles) spa.is_short_scan = _orig vol_gated = algs.fdk(proj, geo_off, angles) # new default: skipped fig, axes = plt.subplots(1, 3, figsize=(13, 4.4)) for ax, vol, title in zip( axes, (vol_ref, vol_wang, vol_gated), ("centred detector (reference)", "0.1 mm offset, Wang weights applied (before)", "0.1 mm offset, Wang skipped on the short scan (after)")): l, r = lr(vol) ax.imshow(vol[32], cmap="gray", vmin=0, vmax=1.5 * mu) ax.set_title(f"{title}\nleft/right interior ratio {l / r:.2f}", fontsize=9) ax.axis("off") print(f"{title}: left {l:.5f} right {r:.5f} ratio {l / r:.3f}") fig.suptitle("200-degree scan of a uniform cylinder - Wang detector-offset weights need a full circle", fontsize=10) plt.tight_layout() plt.savefig("d26_short_scan_wang.png", dpi=120) plt.show() .. rst-class:: sphx-glr-timing **Total running time of the script:** (0 minutes 0.497 seconds) .. _sphx_glr_download_demos_03_geometry_d26_ShortScanWangWeights.py: .. only:: html .. container:: sphx-glr-footer sphx-glr-footer-example .. container:: sphx-glr-download sphx-glr-download-jupyter :download:`Download Jupyter notebook: d26_ShortScanWangWeights.ipynb ` .. container:: sphx-glr-download sphx-glr-download-python :download:`Download Python source code: d26_ShortScanWangWeights.py ` .. container:: sphx-glr-download sphx-glr-download-zip :download:`Download zipped: d26_ShortScanWangWeights.zip ` .. only:: html .. rst-class:: sphx-glr-signature `Gallery generated by Sphinx-Gallery `_