toupy.tomo package¶
Submodules¶
toupy.tomo.iradon module¶
Filtered Back-Projection and SART reconstruction.
GPU path : CuPy + a custom CUDA kernel CPU path : pure NumPy/SciPy, identical to the original mod_iradon.
- The public API is unchanged:
compute_angle_weights, compute_filter, mod_iradon, mod_iradon_cuda, backprojector, reconsSART
- toupy.tomo.iradon.backprojector(sinogram, theta, **params)[source]¶
Wrapper that dispatches to the GPU or CPU FBP implementation.
- Parameters:
sinogram (ndarray shape (nbins, nangles))
theta (ndarray)
params (dict) –
params["opencl"]— repurposed asparams["cuda"]: set True to use the CUDA path. The keyopenclis still accepted as an alias for backwards compatibility. All other keys are forwarded to the chosen implementation.
- Returns:
recons
- Return type:
ndarray shape (output_size, output_size)
- toupy.tomo.iradon.compute_angle_weights(theta)[source]¶
Compute per-angle weights for non-equally-spaced angular distributions.
- Parameters:
theta (ndarray) – Angles in degrees.
- Returns:
weights – Weight for each angle, proportional to the angular distance to its neighbours. Forked from odtbrain.util.compute_angle_weights_1d.
- Return type:
ndarray
- toupy.tomo.iradon.compute_filter(nbins, filter_type='ram-lak', derivatives=False, freqcutoff=1)[source]¶
Compute the frequency-domain filter for FBP reconstruction.
- Parameters:
nbins (int) – Number of detector bins (sinogram rows).
filter_type (str, optional) – One of
ram-lak,shepp-logan,cosine,hamming,hann. Default isram-lak.derivatives (bool, optional) – Use a Hilbert filter suited for derivative projections. Default False.
freqcutoff (float, optional) – Normalised frequency cutoff in [0, 1]. Default 1 (no cutoff).
- Returns:
fourier_filter
- Return type:
ndarray shape (projection_size_padded, 1) complex64
- toupy.tomo.iradon.mod_iradon(radon_image, theta=None, output_size=None, filter_type='ram-lak', derivatives=False, interpolation='linear', circle=False, freqcutoff=1)[source]¶
Inverse Radon transform — CPU path (pure NumPy/SciPy).
Reconstruct an image from its Radon transform using filtered back-projection.
- Parameters:
radon_image (ndarray shape (nbins, nangles)) – Sinogram. Each column corresponds to one projection angle.
theta (ndarray, optional) – Projection angles in degrees. Defaults to
nanglesevenly-spaced values in [0, 180).output_size (int, optional) – Side length of the square output image.
filter_type (str, optional) – See
compute_filter().derivatives (bool, optional) – Set True if the sinogram contains projection derivatives.
interpolation (str, optional) –
linear(default),nearest, orcubic.circle (bool, optional) – Zero pixels outside the inscribed circle.
freqcutoff (float, optional) – Normalised frequency cutoff.
- Returns:
reconstructed
- Return type:
ndarray shape (output_size, output_size)
- toupy.tomo.iradon.mod_iradon_cuda(radon_image, theta=None, output_size=None, filter_type='ram-lak', derivatives=False, circle=False, freqcutoff=1)[source]¶
Inverse Radon transform — CUDA/GPU path.
Falls back to
mod_iradon()automatically if CuPy is unavailable.- Parameters:
radon_image (ndarray shape (nbins, nangles)) – Sinogram on CPU. Converted to float32 internally.
theta (ndarray, optional) – Projection angles in degrees.
output_size (int, optional) – Side length of the square output image.
filter_type (str, optional) – See
compute_filter().derivatives (bool, optional) – Set True if the sinogram contains projection derivatives.
circle (bool, optional) – Zero pixels outside the inscribed circle.
freqcutoff (float, optional) – Normalised frequency cutoff.
- Returns:
reconstructed
- Return type:
ndarray shape (output_size, output_size) float32
toupy.tomo.radon module¶
Forward Radon transform (projection).
GPU path : CuPy + the CUDA kernel defined in iradon.py CPU path : skimage.transform.radon (unchanged fallback).
Public API is unchanged: projector()
- toupy.tomo.radon.projector(recons, theta, **params)[source]¶
Wrapper to choose between CUDA and CPU forward Radon transform.
- Parameters:
recons (ndarray shape (N, N)) – Tomographic slice to project.
theta (ndarray) – Projection angles in degrees.
params (dict) –
params["cuda"]— True → use GPU path.params["opencl"]— accepted as alias for backwards compatibility.
- Returns:
sinogram
- Return type:
ndarray shape (N, nangles)
- toupy.tomo.radon.radon_cuda(recons, theta)[source]¶
Forward Radon transform — CUDA/GPU path.
Falls back to
skimage.transform.radonautomatically if CuPy is unavailable.- Parameters:
recons (ndarray shape (N, N)) – The tomographic slice to project. Converted to float32 internally.
theta (ndarray) – Projection angles in degrees.
- Returns:
sinogram – The computed sinogram, in the same layout as skimage’s radon output (each column = one projection).
- Return type:
ndarray shape (N, nangles)
toupy.tomo.tomorecons module¶
- toupy.tomo.tomorecons.fdk_tomo_recons(projections, geometry: ConeBeamGeometry, **params)[source]¶
High-level FDK cone-beam reconstruction wrapper.
Mirrors
tomo_recons()for cone-beam geometry. Validates the geometry, applies optional pre-processing, calls the three-step FDK pipeline, and optionally displays the central reconstructed slice.- Parameters:
projections (ndarray, shape (n_angles, n_v, n_u)) – Flat-field-corrected, Beer-Lambert log-normalised cone-beam projections.
geometry (ConeBeamGeometry) – Validated acquisition geometry.
**params –
Algorithm parameters. Recognised keys:
- filtertypestr
Ramp-filter window (forwarded to
fdk_filter()). Default'ram-lak'.- freqcutofffloat
Normalised frequency cutoff in
(0, 1]. Default1.- output_sizeint or None
Transaxial reconstruction grid side length.
Noneusesgeometry.n_u.- cudabool
Use CuPy GPU path. Default
False.- circlebool
Multiply the reconstructed volume by a cylindrical mask to suppress border artefacts. Default
False.- showreconsbool
Display the central axial slice after reconstruction. Default
False.- colormapstr
Colormap for display. Default
'bone'.- vmin_plotfloat or None
Display window minimum.
- vmax_plotfloat or None
Display window maximum.
- autosavebool
Save the volume to disk without prompting. Default
False.
- Returns:
volume – Reconstructed 3-D volume.
- Return type:
ndarray, shape (n_v, N, N)
- Raises:
ValueError – If
projections.ndim != 3or shape is inconsistent withgeometry.
See also
tomo_reconsParallel-beam (2-D) slice reconstruction wrapper.
full_tomo_reconsSlice-by-slice parallel-beam full reconstruction.
toupy.tomo.fdk.fdk_reconstructBare FDK pipeline (no display/save).
- toupy.tomo.tomorecons.full_tomo_recons(input_stack, theta, **params)[source]¶
Full tomographic reconstruction
- Parameters:
input_stack (ndarray) – A 3-dimensional array containing the stack of projections. The order should be
[projection_num, row, column]theta (ndarray) – A 1-dimensional array of thetas
params (dict) – Dictionary containing additional parameters
params["algorithm"] (str) – Choice of algorithm. Two algorithm implemented: “FBP” and “SART”
params["slicenum"] (int) – Slice number
params["filtertype"] (str) – Filter to use for FBP
params["freqcutoff"] (float) – Frequency cutoff (between 0 and 1)
params["circle"] (bool) – Multiply the reconstructed slice by a circle to remove borders
params["derivatives"] (bool) – If the projections are derivatives. Only for FBP.
params["calc_derivatives"] (bool) – Calculate derivatives of the sinogram if not done yet.
params["opencl"] (bool) – Implement the tomographic reconstruction in CUDA
params["autosave"] (bool) – Save the data at the end without asking
params["vmin_plot"] (float) – Minimum value for the gray level at each display
params["vmax_plot"] (float) – Maximum value for the gray level at each display
params["colormap"] (str) – Colormap
params["showrecons"] (bool) – If to show the reconstructed slices
- Returns:
tomogram – A 3-dimensional array containing the full reconstructed tomogram.
- Return type:
ndarray
- toupy.tomo.tomorecons.tomo_recons(sinogram, theta, **params)[source]¶
Wrapper to select tomographic algorithm
- sinogramndarray
A 2-dimensional array containing the sinogram
- thetandarray
A 1-dimensional array of thetas
- paramsdict
Dictionary containing additional parameters
- params[“algorithm”]str
Choice of algorithm. Two algorithm implemented: “FBP” and “SART”
- params[“slicenum”]int
Slice number
- params[“filtertype”]str
Name of the filter to be applied in frequency domain filtering. The options are: ram-lak, shepp-logan, cosine, hamming, hann. Assign None to use no filter.
- params[“freqcutoff”]float
Frequency cutoff (between 0 and 1)
- params[“circle”]bool
Multiply the reconstructed slice by a circle to remove borders
- params[“weight_angles”]bool
If True, weights each projection with a factor proportional to the angular distance between the neighboring projections.
\[\Delta \phi_0 \longmapsto \Delta \phi_j =\]
rac{phi_{j+1} - phi_{j-1}}{2}
- params[“derivatives”]bool
If the projections are derivatives. Only for FBP.
- params[“calc_derivatives”]bool
Calculate derivatives of the sinogram if not done yet.
- params[“opencl”]bool
Implement the tomographic reconstruction in opencl as implemented in Silx
- params[“autosave”]bool
Save the data at the end without asking
- params[“vmin_plot”]float
Minimum value for the gray level at each display
- params[“vmax_plot”]float
Maximum value for the gray level at each display
- params[“colormap”]str
Colormap
- params[“showrecons”]bool
If to show the reconstructed slices
- reconsndarray
A 2-dimensional array containing the reconstructed slice.