Skip to content

Commit

Permalink
work on documentation update complete
Browse files Browse the repository at this point in the history
  • Loading branch information
dkazanc committed Jan 6, 2025
1 parent e90f236 commit 7651843
Show file tree
Hide file tree
Showing 36 changed files with 1,587 additions and 2,251 deletions.
6 changes: 6 additions & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# ChangeLog

## v3.0.1 (2024.12)

* Documentation has been updated in January 2025 with a lot of additional information, API links, tutorials, etc.
* Docstrings of the modules were updated with the references to documentation.


## v3.0 (2023.12)
* Project reorganised into two parts: a library that is build as a shared object using Cmake and Ctypes bindings and pure Python part that can be
installed separately.
Expand Down
199 changes: 100 additions & 99 deletions Demos/2D/Model.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@

model = 4 # select a model number from the library file (Phantom2DLibrary)
N_size = 512 # set the desired dimension of the phantom
# one can specify an exact path to the parameters file
path = os.path.dirname(tomophantom.__file__)
path_library2D = os.path.join(path, "phantomlib", "Phantom2DLibrary.dat")

Expand All @@ -29,6 +28,7 @@
plt.imshow(phantom_2D, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("{}" "{}".format("2D Phantom using model no.", model))
plt.show()

# %%
# Parameters to generate a sinogram
Expand All @@ -51,110 +51,111 @@
plt.imshow(sino_an, vmin=0, vmax=300, cmap="BuPu")
plt.colorbar(ticks=[0, 150, 300], orientation="vertical")
plt.title("{}" "{}".format("Analytical sinogram of model no.", model))
# %%
# generate numerical sinogram
angles_num = int(0.5 * np.pi * N_size)
# angles number
angles = np.linspace(0.0, 179.9, angles_num, dtype="float32")
P = int(np.sqrt(2) * N_size) # detectors

tic = timeit.default_timer()
sino_num = TomoP2D.SinoNum(phantom_2D, P, angles)
toc = timeit.default_timer()
Run_time = toc - tic
print("Numerical sinogram has been generated in {} seconds".format(Run_time))

plt.figure()
plt.rcParams.update({"font.size": 21})
plt.imshow(sino_num, vmin=0, vmax=300, cmap="BuPu")
plt.colorbar(ticks=[0, 150, 300], orientation="vertical")
plt.title("{}" "{}".format("Numerical sinogram of model no.", model))
plt.show()
# # %%
# # generate numerical sinogram
# angles_num = int(0.5 * np.pi * N_size)
# # angles number
# angles = np.linspace(0.0, 179.9, angles_num, dtype="float32")
# P = int(np.sqrt(2) * N_size) # detectors

# tic = timeit.default_timer()
# sino_num = TomoP2D.SinoNum(phantom_2D, P, angles)
# toc = timeit.default_timer()
# Run_time = toc - tic
# print("Numerical sinogram has been generated in {} seconds".format(Run_time))

# plt.figure()
# plt.imshow(abs(sino_an-sino_num), vmin=0, vmax=0.001, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.02, 0.05], orientation='vertical')
# plt.title('Analytical vs Numerical singograms')
# %%


###################################################################
from tomobar.methodsDIR import RecToolsDIR

angles_rad = angles * (np.pi / 180.0)

# get numerical sinogram (ASTRA-toolbox)
Rectools = RecToolsDIR(
DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal)
DetectorsDimV=None, # DetectorsDimV # detector dimension (vertical) for 3D case only
CenterRotOffset=0.0, # Center of Rotation (CoR) scalar (for 3D case only)
AnglesVec=angles_rad, # array of angles in radians
ObjSize=N_size, # a scalar to define reconstructed object dimensions
device_projector="cpu",
)

tic = timeit.default_timer()
sino_num_ASTRA = Rectools.FORWPROJ(phantom_2D) # generate numerical sino (Ax)
toc = timeit.default_timer()
Run_time = toc - tic
print("Numerical (ASTRA) sinogram has been generated in {} seconds".format(Run_time))

plt.figure()
plt.rcParams.update({"font.size": 21})
plt.imshow(sino_num_ASTRA, vmin=0, vmax=150, cmap="BuPu")
plt.colorbar(ticks=[0, 150, 250], orientation="vertical")
plt.title("{}" "{}".format("Numerical sinogram (ASTRA) of model no.", model))
# %%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing analytical sinogram using Fourier Slice method")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# plt.rcParams.update({"font.size": 21})
# plt.imshow(sino_num, vmin=0, vmax=300, cmap="BuPu")
# plt.colorbar(ticks=[0, 150, 300], orientation="vertical")
# plt.title("{}" "{}".format("Numerical sinogram of model no.", model))

# # plt.figure()
# # plt.imshow(abs(sino_an-sino_num), vmin=0, vmax=0.001, cmap="BuPu")
# # plt.colorbar(ticks=[0, 0.02, 0.05], orientation='vertical')
# # plt.title('Analytical vs Numerical singograms')
# # %%


# ###################################################################
# from tomobar.methodsDIR import RecToolsDIR

# angles_rad = angles * (np.pi / 180.0)

# # get numerical sinogram (ASTRA-toolbox)
# Rectools = RecToolsDIR(
# DetectorsDimH=P, # DetectorsDimH # detector dimension (horizontal)
# DetectorsDimV=None, # DetectorsDimV # detector dimension (vertical) for 3D case only
# CenterRotOffset=0.0, # Center of Rotation (CoR) scalar (for 3D case only)
# AnglesVec=angles_rad, # array of angles in radians
# ObjSize=N_size, # a scalar to define reconstructed object dimensions
# device_projector="cpu",
# )

# tic = timeit.default_timer()
# sino_num_ASTRA = Rectools.FORWPROJ(phantom_2D) # generate numerical sino (Ax)
# toc = timeit.default_timer()
# Run_time = toc - tic
# print("Numerical (ASTRA) sinogram has been generated in {} seconds".format(Run_time))

RecFourier = Rectools.FOURIER(sino_an, "linear")
# plt.figure()
# plt.rcParams.update({"font.size": 21})
# plt.imshow(sino_num_ASTRA, vmin=0, vmax=150, cmap="BuPu")
# plt.colorbar(ticks=[0, 150, 250], orientation="vertical")
# plt.title("{}" "{}".format("Numerical sinogram (ASTRA) of model no.", model))
# # %%
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# print("Reconstructing analytical sinogram using Fourier Slice method")
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")

plt.figure()
plt.imshow(RecFourier, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("Fourier slice reconstruction")
# %%
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
print("Reconstructing analytical sinogram using FBP (tomobar)...")
print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# x = Atools.backproj(sino_an) # generate backprojection (A'b)
# RecFourier = Rectools.FOURIER(sino_an, "linear")

plt.figure()
plt.subplot(121)
plt.imshow(sino_an, cmap="BuPu")
plt.title("Analytical sinogram")
plt.subplot(122)
plt.imshow(sino_num_ASTRA, cmap="BuPu")
plt.title("Numerical sinogram")
plt.show()
# calculate norm
# rmse1 = np.linalg.norm(sino_an - sino_num_ASTRA)/np.linalg.norm(sino_num_ASTRA)
# plt.figure()
# plt.imshow(RecFourier, vmin=0, vmax=1, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
# plt.title("Fourier slice reconstruction")
# # %%
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# print("Reconstructing analytical sinogram using FBP (tomobar)...")
# print("%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%")
# # x = Atools.backproj(sino_an) # generate backprojection (A'b)

print("Reconstructing analytical sinogram using FBP (astra TB)...")
FBPrec1 = Rectools.FBP(sino_an)
plt.figure()
plt.imshow(FBPrec1, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("FBP Reconstructed Phantom (analyt)")
# plt.figure()
# plt.subplot(121)
# plt.imshow(sino_an, cmap="BuPu")
# plt.title("Analytical sinogram")
# plt.subplot(122)
# plt.imshow(sino_num_ASTRA, cmap="BuPu")
# plt.title("Numerical sinogram")
# plt.show()
# # calculate norm
# # rmse1 = np.linalg.norm(sino_an - sino_num_ASTRA)/np.linalg.norm(sino_num_ASTRA)

# print("Reconstructing analytical sinogram using FBP (astra TB)...")
# FBPrec1 = Rectools.FBP(sino_an)
# plt.figure()
# plt.imshow(FBPrec1, vmin=0, vmax=1, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
# plt.title("FBP Reconstructed Phantom (analyt)")

print("Reconstructing numerical sinogram using FBP (astra TB)...")
FBPrec2 = Rectools.FBP(sino_num_ASTRA)
# print("Reconstructing numerical sinogram using FBP (astra TB)...")
# FBPrec2 = Rectools.FBP(sino_num_ASTRA)

plt.figure()
plt.imshow(FBPrec2, vmin=0, vmax=1, cmap="BuPu")
plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
plt.title("FBP Reconstructed Phantom (numeric)")
# plt.figure()
# plt.imshow(FBPrec2, vmin=0, vmax=1, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.5, 1], orientation="vertical")
# plt.title("FBP Reconstructed Phantom (numeric)")

plt.figure()
plt.imshow(abs(FBPrec1 - FBPrec2), vmin=0, vmax=0.05, cmap="BuPu")
plt.colorbar(ticks=[0, 0.02, 0.05], orientation="vertical")
plt.title("FBP rec differences")
# rmse2 = np.linalg.norm(FBPrec1 - FBPrec2)/np.linalg.norm(FBPrec2)

Qtools = QualityTools(phantom_2D, FBPrec1)
RMSE_FBP1 = Qtools.rmse()
Qtools = QualityTools(phantom_2D, FBPrec2)
RMSE_FBP2 = Qtools.rmse()
print("RMSE for FBP (analyt) {}".format(RMSE_FBP1))
print("RMSE for FBP (numeric) {}".format(RMSE_FBP2))
# plt.figure()
# plt.imshow(abs(FBPrec1 - FBPrec2), vmin=0, vmax=0.05, cmap="BuPu")
# plt.colorbar(ticks=[0, 0.02, 0.05], orientation="vertical")
# plt.title("FBP rec differences")
# # rmse2 = np.linalg.norm(FBPrec1 - FBPrec2)/np.linalg.norm(FBPrec2)

# Qtools = QualityTools(phantom_2D, FBPrec1)
# RMSE_FBP1 = Qtools.rmse()
# Qtools = QualityTools(phantom_2D, FBPrec2)
# RMSE_FBP2 = Qtools.rmse()
# print("RMSE for FBP (analyt) {}".format(RMSE_FBP1))
# print("RMSE for FBP (numeric) {}".format(RMSE_FBP2))
5 changes: 0 additions & 5 deletions Demos/2D/Object2D.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,6 @@
Script to generate 2D/3D analytical objects and their sinograms
Recursively adding objects and sinos one can build a required model
>>>>> Optional dependencies (reconstruction mainly): <<<<<
1. ASTRA toolbox: conda install -c astra-toolbox astra-toolbox
2. tomobar: conda install -c dkazanc tomobar
or install from https://github.com/dkazanc/ToMoBAR
@author: Daniil Kazantsev
"""
import numpy as np
Expand Down

This file was deleted.

264 changes: 0 additions & 264 deletions Demos/jupyter-notebooks/.ipynb_checkpoints/model2D-checkpoint.ipynb

This file was deleted.

325 changes: 0 additions & 325 deletions Demos/jupyter-notebooks/.ipynb_checkpoints/model3D-checkpoint.ipynb

This file was deleted.

401 changes: 0 additions & 401 deletions Demos/jupyter-notebooks/Random2Dphantom_artifacts.ipynb

This file was deleted.

257 changes: 0 additions & 257 deletions Demos/jupyter-notebooks/model2D.ipynb

This file was deleted.

325 changes: 0 additions & 325 deletions Demos/jupyter-notebooks/model3D.ipynb

This file was deleted.

7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,9 @@

****************

### NEW! VERSION 3.0
TomoPhantom has been refactored, please see [changes](CHANGES.md). Everyone is welcome to <a href="https://dkazanc.github.io/TomoPhantom/index.html">Documentation</a> page.
### NEW!
Please see [changes](CHANGES.md). <a href="https://dkazanc.github.io/TomoPhantom/index.html">Documentation</a> has been updated in January 2025 with
a lot of additional information, API links, tutorials, etc.

<div class="post-content">
<h3 class="post-title">About TomoPhantom </h3>
Expand All @@ -34,7 +35,7 @@ TomoPhantom has been refactored, please see [changes](CHANGES.md). Everyone is w
* Model a variety of tomographic data artefacts (noise models, zingers, rings, shifts, partial volume effect and others).

### Installation:
Tomophantom is distributed as a Python conda package for Linux/Windows/Mac OS's:
TomoPhantom is distributed as a conda package in Python for Linux & Windows:
```
conda install -c httomo tomophantom
```
Expand Down
10 changes: 6 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,19 @@ for parallel-beam scanning geometry.

Documentation
-------------
Please check the full `documentation <https://dkazanc.github.io/Tomophantom/>`_.

`Documentation <https://dkazanc.github.io/Tomophantom/>`_ is a good place to start.

Install TomoPhantom
--------------------------------------------------------
Tomophantom is distributed as a Python conda package for Linux/Windows/Mac OS's:
-------------------

TomoPhantom is distributed as a conda package in Python for Linux & Windows:

.. code-block:: console
$ conda install -c httomo tomophantom
See the detailed page on :ref:`ref_installation`.
See the detailed installation page on :ref:`ref_installation`.

.. [SX2018] D. Kazantsev et al. 2018, TomoPhantom, a software package to
generate 2D-4D analytical phantoms for CT image reconstruction
Expand Down
2 changes: 2 additions & 0 deletions conda-recipe_library/conda_build_config.yaml
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
python:
- 3.10
- 3.11
- 3.12
numpy:
- 1.23
- 1.26
- 1.26
zip_keys:
- python
- numpy
Expand Down
Binary file added docs/source/_static/tutorials/model4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/tutorials/model_sino4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/tutorials/object2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added docs/source/_static/tutorials/object_sino2d.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 6 additions & 0 deletions docs/source/api/tomophantom.generator.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
:mod:`tomophantom.generator`
============================================
.. automodule:: tomophantom.generator
:members:
:show-inheritance:
:undoc-members:
4 changes: 2 additions & 2 deletions docs/source/howto/build_phantoms.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ Build Phantoms

This sections explains how to build phantoms by presenting two main ways of doing that.

* 1. The easiest and the quickest way to build a phantom is to use provided library files, see more in :ref:`howto_libraries`. This is the most suitable way to start for someone who is new to TomoPhantom. We recommend to try building already pre-existing models by following this guide on :ref:`tutorial_model`.
* 1. The easiest and the quickest way to build a phantom is to use provided library files, see more in :ref:`howto_libraries`. This is the most suitable way to start for someone who is new to TomoPhantom. We recommend to try building already pre-existing models by following this guide on how to generate :ref:`tutorial_model`.

* 2. For more advanced approach in building bespoke phantoms consisting of multiple objects, we recommend to use :ref:`ref_object_api`. This is how one can build a phantom directly, i.e., without the use of the library file. One can specify parameters in Python as a dictionary and pass into a function that works with the objects. We recommend to have a look at this tutorial :ref:`tutorial_object`.
* 2. For more advanced approach in building bespoke phantoms consisting of multiple objects, we recommend to follow the guidelines of :ref:`ref_object_api`. This is how one can build a phantom directly, i.e., without the use of the library file. One can specify parameters as a dictionary in Python and pass into a function that works with the objects. This can be more versatile way of building phantoms when one need to update or manipulate with parameters of objects. We recommend to have a look at the tutorial how to generate :ref:`tutorial_object`.
Loading

0 comments on commit 7651843

Please sign in to comment.