Conjugate gradient¶
3D
This script uses the SheppLogan phantom.
# Create a simulated geometry
rtksimulatedgeometry -n 180 -o geometry.xml
# You may add "--arc 200" to make the scan short or "--proj_iso_x 200" to offset the detector
# Create projections of the phantom file
rtkprojectshepploganphantom -g geometry.xml -o projections.mha --spacing 2 --size 256
# Reconstruct
rtkconjugategradient -p . -r projections.mha -o 3dcg.mha -g geometry.xml --spacing 2 --size 256 -n 10
# Create a reference volume for comparison
rtkdrawshepploganphantom --spacing 2 --size 256 -o ref.mha
2D
The same reconstruction can be performed using the original 2D Shepp-Logan phantom. RTK can perform 2D reconstructions through images wide of 1 pixel in the y direction. The following script performs the same reconstruction as above in a 2D environment and use the 2D Shepp-Logan.
# Generate geometry for fan-beam setup
rtksimulatedgeometry -n 720 -o geometry.xml --arc 360
# Create projections of the phantom file
# Note the sinogram being 3 pixels wide in the y direction to allow back-projection interpolation in a 2D image
rtkprojectgeometricphantom -g geometry.xml -o projections.mha --spacing 2 --size=512,3,512 --phantomfile SheppLogan-2d.txt --phantomscale=256,1,256
# Perform Conjugate Gradient reconstruction
rtkconjugategradient -p . -r projections.mha -o cg.mha -g geometry.xml --spacing 2 --size 256 1 256 -n 10
# Create a reference volume for comparison
rtkdrawgeometricphantom --spacing 2 --size=256,1,256 --phantomfile SheppLogan-2d.txt -o ref.mha --phantomscale=256,1,256
Noisy Reconstruction
In the presence of noise, all projection data may not be equally reliable. The conjugate gradient algorithm can be modified to take this into account, and each pixel of the projections can be associated with a weight. The higher the weight, the more reliable the pixel data. Download noisy projections and the associated weights, as well as the geometry, and run the following to compare the regular least squares reconstruction (without weights) and the weighted least squares reconstruction.
# Create a simulated geometry
rtksimulatedgeometry -n 180 -o geometry.xml
# You may add "--arc 200" to make the scan short or "--proj_iso_x 200" to offset the detector
# Create projections of the phantom file
rtkprojectshepploganphantom -g geometry.xml -o projections.mha --spacing 2 --size 256
# Perform least squares reconstruction
rtkconjugategradient -p . -r noisyLineIntegrals.mha -o LeastSquares.mha -g geom.xml -n 20
# Perform weighted least squares reconstruction
rtkconjugategradient -p . -r noisyLineIntegrals.mha -o WeightedLeastSquares.mha -g geom.xml -w weightsmap.mha -n 10
# Create a reference volume for comparison
rtkdrawshepploganphantom --spacing 2 --size 256 -o ref.mha
Command line options¶
usage: __main__.py [-h] [-V] [-v] --geometry GEOMETRY --output OUTPUT
[--niterations NITERATIONS] [--time] [--input INPUT]
[--weights WEIGHTS] [--regweights REGWEIGHTS]
[--gamma GAMMA] [--tikhonov TIKHONOV] [--nocudacg]
[--mask MASK] [--nodisplaced] --path PATH --regexp REGEXP
[--nsort] [--submatch SUBMATCH] [--nolineint]
[--newdirection NEWDIRECTION [NEWDIRECTION ...]]
[--neworigin NEWORIGIN [NEWORIGIN ...]]
[--newspacing NEWSPACING [NEWSPACING ...]]
[--lowercrop LOWERCROP [LOWERCROP ...]]
[--uppercrop UPPERCROP [UPPERCROP ...]]
[--binning BINNING [BINNING ...]] [--wpc WPC [WPC ...]]
[--spr SPR] [--nonneg NONNEG] [--airthres AIRTHRES]
[--i0 I0] [--idark IDARK] [--component COMPONENT]
[--radius RADIUS [RADIUS ...]] [--multiplier MULTIPLIER]
[--origin ORIGIN [ORIGIN ...]] [--size SIZE [SIZE ...]]
[--dimension DIMENSION [DIMENSION ...]]
[--spacing SPACING [SPACING ...]]
[--direction DIRECTION [DIRECTION ...]] [--like LIKE]
[--fp {Joseph,CudaRayCast,JosephAttenuated,Zeng,CudaZeng}]
[--bp {VoxelBasedBackProjection,Joseph,CudaVoxelBased,CudaRayCast,JosephAttenuated,Zeng,CudaZeng}]
[--step STEP] [--attenuationmap ATTENUATIONMAP]
[--sigmazero SIGMAZERO] [--alphapsf ALPHAPSF]
[--inferiorclipimage INFERIORCLIPIMAGE]
[--superiorclipimage SUPERIORCLIPIMAGE]
[--output-every OUTPUT_EVERY]
[--iteration-file-name ITERATION_FILE_NAME]
Named Arguments¶
- -V, --version
show program’s version number and exit
- -v, --verbose
Verbose execution
Default:
False- --geometry, -g
XML geometry file name
- --output, -o
Output file name
- --niterations, -n
Number of iterations
Default:
5- --time, -t
Records elapsed time during the process
Default:
False- --input, -i
Input volume
- --weights, -w
Weights file for Weighted Least Squares (WLS)
- --regweights
Local regularization weights file
- --gamma
Laplacian regularization weight
Default:
0.0- --tikhonov
Tikhonov regularization weight
Default:
0.0- --nocudacg
Do not perform conjugate gradient calculations on GPU
Default:
False- --mask, -m
Apply a support binary mask: reconstruction kept null outside the mask
- --nodisplaced
Disable the displaced detector filter
Default:
False
Input projections and their pre-processing¶
- --path, -p
Path containing projections
- --regexp, -r
Regular expression to select projection files in path
- --nsort
Numeric sort for regular expression matches
Default:
False- --submatch
Index of the submatch that will be used to sort matches
Default:
0- --nolineint
Disable raw to line integral conversion, just casts to float
Default:
False- --newdirection
New value of input projections (before pre-processing)
- --neworigin
New origin of input projections (before pre-processing)
- --newspacing
New spacing of input projections (before pre-processing)
- --lowercrop
Lower boundary crop size
Default:
[0]- --uppercrop
Upper boundary crop size
Default:
[0]- --binning
Shrink / Binning factos in each direction
Default:
[1]- --wpc
Water precorrection coefficients (default is no correction)
- --spr
Boellaard scatter correction: scatter-to-primary ratio
Default:
0- --nonneg
Boellaard scatter correction: non-negativity threshold
- --airthres
Boellaard scatter correction: air threshold
- --i0
I0 value (when assumed constant per projection), 0 means auto
- --idark
IDark value, i.e., value when beam is off
Default:
0- --component
Vector component to extract, for multi-material projections
- --radius
Radius of neighborhood for conditional median filtering
Default:
[0]- --multiplier
Threshold multiplier for conditional median filtering
Default:
0
Output 3D image properties¶
- --origin
Origin (default=centered)
- --size
Size
Default:
[256]- --dimension
Dimension (Deprecated) Use –size instead.
- --spacing
Spacing
Default:
[1]- --direction
Direction
- --like
Copy information from this image (origin, size, spacing, direction)
Projectors¶
- --fp, -f
Possible choices: Joseph, CudaRayCast, JosephAttenuated, Zeng, CudaZeng
Forward projection method
Default:
'Joseph'- --bp, -b
Possible choices: VoxelBasedBackProjection, Joseph, CudaVoxelBased, CudaRayCast, JosephAttenuated, Zeng, CudaZeng
Back projection method
Default:
'VoxelBasedBackProjection'- --step
Step size along ray (for CudaRayCast only, default to the minimum voxel spacing of the input volume if set to 0)
Default:
0.0- --attenuationmap
Attenuation map relative to the volume to perform the attenuation correction (JosephAttenuated, Zeng and CudaZeng)
- --sigmazero
PSF value at a distance of 0 meter of the detector (Zeng and CudaZeng only)
- --alphapsf
Slope of the PSF against the detector distance (Zeng and CudaZeng only)
- --inferiorclipimage
Inferior clip of the ray for each pixel of the projections (Joseph only)
- --superiorclipimage
Superior clip of the ray for each pixel of the projections (Joseph only)
Iteration reporting¶
- --output-every
Output intermediate reconstruction after some iterations
- --iteration-file-name
File name to output intermediate iterations with {i} as a placeholder for iteration number



