Projection Filters and Transforms
- leapctype.tomographicModels.allocate_projections(self, val=0.0, astensor=False, forOffsetScanFilteringStep=False)
Allocates projection data
It is not necessary to use this function. It is included simply for convenience.
- Parameters:
val (float) – value to fill the array with
astensor (bool) – if true turns array into a pytorch tensor
- Returns:
numpy array/ pytorch tensor if numAngles, numRows, and numCols are all positive, None otherwise
- leapctype.tomographicModels.Laplacian(self, g, numDims=2, smoothLaplacian=False)
Applies a Laplacian operation to each projection
The CT geometry parameters must be set prior to running this function.
- Parameters:
g (C contiguous float32 numpy array or torch tensor) – projection data
numDims (int) – if 2 calculates the sum of the second derivatives along the rows and columns, if 1 calculates the second derivative along the columns
smoothLaplacian (bool) – if true, applies an extra low pass filter (given by [0.25, 0.5, 0.25]) to smooth the result
- Returns:
g, the same as the input
- leapctype.tomographicModels.transmission_filter(self, g, H, isAttenuationData=True)
Applies a 2D Filter to each transmission projection
The CT geometry parameters must be set prior to running this function.
- Parameters:
g (C contiguous float32 numpy array or torch tensor) – projection data
H (C contiguous float32 2D numpy array) – frequency response of filter (must be real-valued)
isAttenuationData (bool) – true if the input data is attenuation data, false if it is not (e.g., transmission, raw)
- Returns:
g, the same as the input
- leapctype.tomographicModels.applyTransferFunction(self, x, LUT, sampleRate, firstSample=0.0)
Applies a transfer function to arbitrary 3D data, i.e., x = LUT(x)
- Parameters:
x (C contiguous float32 numpy array or torch tensor) – 3D data (input and output)
LUT (C contiguous float32 numpy array or torch tensor) – lookup table with transfer function values
sampleRate (float) – the step size between samples
firstSample (float) – the value of the first sample in the lookup table
- Returns:
true if operation was sucessful, false otherwise
- leapctype.tomographicModels.applyDualTransferFunction(self, x, y, LUT, sampleRate, firstSample=0.0)
Applies a 2D transfer function to arbitrary 3D data pair, i.e., x,y = LUT(x,y)
- Parameters:
x (C contiguous float32 numpy array or torch tensor) – 3D data of first component (input and output)
y (C contiguous float32 numpy array or torch tensor) – 3D data of second component (input and output)
LUT (C contiguous float32 numpy array or torch tensor) – lookup table with transfer function values
sampleRate (float) – the step size between samples
firstSample (float) – the value of the first sample in the lookup table
- Returns:
true if operation was sucessful, false otherwise
- leapctype.tomographicModels.sinogram_replacement(self, g, priorSinogram, metalTrace, windowSize=None)
replaces specified region in projection data with other projection data
This routine provides a robust solution to metal artifact reduction (MAR).
- Parameters:
g (C contiguous float32 numpy array or torch tensor) – projection data to alter
priorSinogram (C contiguous float32 numpy array or torch tensor) – projection data to use for patching
metalTrace (C contiguous float32 numpy array or torch tensor) – projection mask showing where to do the patching
windowSize (3-element int array) – window size in each of the three dimensions, default is [30, 1, 50]
- Returns:
true if operation was sucessful, false otherwise
- leapctype.tomographicModels.scatter_model(self, f, source, energies, detector, sigma, scatterDist, jobType=-1)
simulates first order scatter through an object composed of a single material type (but variable density)
This is a complicated function and one should refer to the demo script: d31_scatter_correction.py for a full working demonstration.
This routine requires that one down-sample the CT detector pixels, volume voxels, and number of source spectra samples. The volume should be no larger than 200^3 voxels The projection data should be no larger than 256^2 The source spectra should have no more than 20 samples (we recommend about 10 samples)
Note that source and energies are defined on a course grid and the number of samples has an almost linear effect on the computation time of these routines. But detector, sigma, scatterDist are sampled from 1 keV to int(ceil(energies[-1])) in 1 keV bins These three arguments MUST be specified like this and the fine sampling here does not effect computation time
- Parameters:
f (C contiguous float32 numpy array or torch tensor) – volume data in mass density units
source (numpy array) – source spectra (including response due to filters)
energies (numpy array) – energy samples for source spectra
detector (numpy array) – detector response (sampled from 1 keV to int(ceil(energies[-1])) in 1 keV bins)
sigma (2D numpy array) – sigma[0,:] = sigmaPE, sigma[1,:] = sigmaCS, sigma[2,:] = sigmaRS, energy samples same as detector response
scatterDist (3D numpy array) – incoherent and coherent scatter distributions [2 x number of energy bins x 181]
jobType (int) – if -1 estimates scatter correction gain factor, if 1 estimates scatter simulation (adds scatter to data) gain factor, and if 0 estimates scatter transmission
- Returns:
Returns gain factor or scatter transmission numpy array based on the jobType parameter
- leapctype.tomographicModels.crop_cols(self, colRange, g=None)
Crops columns from projection data
This function crops columns from the projection data. The appropriate CT geometry parameters are updated (e.g., centerCol, numCols, moduleCenters, etc) and if the input projection data is given, the selected projection columns are removed
- Parameters:
colRange (2-element numpy array) – the range of detector column indices to keep, all other columns will be removed
g (C contiguous float32 numpy array or torch tensor) – projection data to operate on (optional)
- Returns:
If g is given, then a new numpy array is returned with the selected columns (the 3rd dimension) removed from the data
- leapctype.tomographicModels.crop_projections(self, rowRange, colRange=None, g=None)
Crops rows and columns from projection data
This function crops rows and columns from the projection data. The appropriate CT geometry parameters are updated (e.g., centerRow, centerCol, numRows, numCols, moduleCenters, etc) and if the input projection data is given, the selected projection rows and columns are removed
- Parameters:
colRange (2-element numpy array) – the range of detector column indices to keep, all other rows will be removed
rowRange (2-element numpy array) – the range of detector column indices to keep, all other rows will be removed
g (C contiguous float32 numpy array or torch tensor) – projection data to operate on (optional)
- Returns:
If g is given, then a new numpy array is returned with the selected rows and columns (the 2nd and 3rd dimensions) removed from the data
- leapctype.tomographicModels.crop_rows(self, rowRange, g=None)
Crops rows from projection data
This function crops rows from the projection data. The appropriate CT geometry parameters are updated (e.g., centerRow, numRows, moduleCenters, etc) and if the input projection data is given, the selected projection rows are removed
- Parameters:
rowRange (2-element numpy array) – the range of detector column indices to keep, all other rows will be removed
g (C contiguous float32 numpy array or torch tensor) – projection data to operate on (optional)
- Returns:
If g is given, then a new numpy array is returned with the selected rows (the 2nd dimension) removed from the data
- leapctype.tomographicModels.down_sample_projections(self, factors, g=None)
down-samples the given projection data
This function applies an anti-aliasing filter and down-samples projection data and updates the CT geometry parameters accordingly. This anti-aliasing filter is the same one used in the LowPassFilter function.
- Parameters:
factors – 3-element array of down-sampling factors
g (C contiguous float32 numpy array or torch tensor) – projection data to down-sample
- Returns:
down-sampled array (if projection data was provided in the arguments)
- leapctype.tomographicModels.up_sample_projections(self, factors, g=None, dims=None)
up-samples the given projection data
This function up-samples projection data and updates the CT geometry parameters accordingly. The up-sampling is performed using trilinear interpolation.
- Parameters:
factors – 3-element array of up-sampling factors
g (C contiguous float32 numpy array or torch tensor) – projection data to up-sample
- Returns:
up-sampled array (if projection data was provided in the arguments)
- leapctype.tomographicModels.rebin_parallel(self, g, order=6)
rebin data from fan-beam to parallel-beam or cone-beam to cone-parallel
The CT geometry parameters must be defined before running this function. After the completion of this algorithm, the CT geometry parameters will be modified as necessary and the number of projections may reduce. If the number of projections does reduce most LEAP functions will work correctly, but we recommend that users resize their arrays.
- Parameters:
g (C contiguous float32 numpy array or torch tensor) – projection data
order (int) – the order of the interpolating polynomial
- leapctype.tomographicModels.rebin_curved(self, g, fanAngles, order=6)
rebin data from a curved array of detector modules
Note that if your data is already sampled on a curved detector, you do not need to use this function. Real curved detectors are composed of a series of detector modules curved around a polygon shape. There are often gaps between modules that need to be accounted for and that is what this function does.
- Parameters:
g (C contiguous float32 numpy array or torch tensor) – projection data
fanAngles (C contiguous float32 numpy array) – array of the fan angle (degrees) of every detector pixel in a row
order (int) – the order of the interpolating polynomial
- leapctype.tomographicModels.expNeg(self, x)
Returns exp(-x), converting attenuation data to transmission data
- leapctype.tomographicModels.negLog(self, x)
Returns -log(x), converting transmission data to attenuation data