Utilities
Utility routines for visualization or further processing.
The adrt.utils module contains routines which are useful for
visualization or other basic processing tasks. These routines help to
transform outputs from the core algorithms into forms which may be
easier to process elsewhere, for example by aligning the quadrants of
the ADRT into a single contiguous image, or interpolating the
irregular ADRT angles into a regular spacing.
Output Stitching
These routines manipulate ADRT outputs by slicing, rotating, and aligning them to make the results suitable for further processing or visualization.
- adrt.utils.truncate(a, /)[source]
Truncate and rotate a rectangular ADRT output into a square.
ADRT output arrays consist of four rectangular quadrants with different orientations, such that the image data is not stacked in a corresponding position (see the illustration in Forward Transform).
This function fixes both aspects. It slices each ADRT quadrant into a square, and rotates them so that they are stacked in a consistent orientation (in particular, this forms an inverse for
adrt.core.adrt_init()).For this routine the input array a must have the same relative shape of an ADRT output, but the base dimension
Nneed not be a power of two. The array may also have any number of leading batch dimensions.- Parameters:
a (numpy.ndarray) – An ADRT output array with rectangular quadrants.
- Returns:
An array with four square quadrants each rotated into a consistent orientation.
- Return type:
Notes
This routine can be used to:
Slice the output of
adrt.bdrt()before collapsing withnumpy.mean()to produce the standard transpose toadrt.adrt().Slice and rotate the result of
adrt.iadrt()before collapsing withnumpy.mean().Invert
adrt.core.adrt_init().
- adrt.utils.stitch_adrt(a, /, *, remove_repeated=False)[source]
Reshape and align ADRT quadrants output into a contiguous image.
The ADRT routine,
adrt.adrt(), produces an output array which is divided into four separate quadrants, each containing the Radon transform results for a range of angles. This routine stitches these channels together so that they form a contiguous output. This may be especially useful in order to visualize the output as an image.The input array should have the relative shape of an ADRT output (but the base dimension
Nneed not be a power of two). Any number of optional leading dimensions will be treated as batch dimensions and will be preserved in the output.The output array will be four times as wide as any one original quadrant (with four fewer columns if remove_repeated is
True), and will have an additionalN-1rows added.- Parameters:
a (numpy.ndarray) – Array of ADRT output data to be stitched.
remove_repeated (bool, optional) – If
False(default) all columns are preserved in the output. IfTrue, the redundant last column in each quadrant is removed.
- Returns:
The input data repositioned to form a contiguous array.
- Return type:
Notes
The columns which are removed by remove_repeated are only truly redundant if a has the symmetries of a real ADRT output.
See Forward Transform for a description of the ADRT output quadrants.
The function
unstitch_adrt()provides an inverse for this operation.
- adrt.utils.unstitch_adrt(a, /)[source]
Slice a stitched ADRT output back into individual quadrants.
This function provides an inverse for
stitch_adrt()and re-slices, flips, and rotates its output into separate quadrants.- Parameters:
a (numpy.ndarray) – Array of stitched ADRT output data.
- Returns:
The input data re-separated into ADRT quadrants with the relative shape of an ADRT output.
- Return type:
Notes
This function applies an inverse regardless of the remove_repeated argument that was specified when stitching so long as the ADRT output that was stitched respected the symmetries of a real ADRT output. In other cases, the removed columns may not have been redundant.
Interpolation
We provide a simple routine which interpolates the unevenly spaced ADRT angles into evenly spaced angles as in a more conventional sinogram.
- adrt.utils.interp_to_cart(a, /)[source]
Interpolate an ADRT output into a regular Cartesian grid.
The angles and offsets used in an ADRT output are irregularly-spaced to enable reuse of intermediate calculations. This routine provides a basic interpolation operation which resamples these angles into an even-spacing.
The ADRT result is interpolated into a uniform Cartesian grid in the Radon domain \((\theta, t)\). Where \(\theta\) is the normal direction of the line, and \(t\) is the distance of the line to the origin. Upon a coordinate transformation, a nearest neighbor interpolation is performed.
For an ADRT output of size
N, the interpolated array has shape(N, 4*N)with an optional batch dimension preserved.- Parameters:
a (numpy.ndarray of float) – ADRT output array to interpolate.
- Returns:
Interpolated Cartesian grid data.
- Return type:
Notes
See the coordinate transform section for more details on the coordinate transform.
Coordinate Information
These functions provide information on the angle and offset coordinates which are represented in an ADRT output, or the closest correspondence between regularly-spaced Cartesian coordinates to the unevenly spaced ADRT coordinates.
- adrt.utils.coord_adrt(n, /)[source]
Compute coordinates for each entry in an ADRT output.
The ADRT sums values in an input image along lines of pixels. These lines are selected to approximate continuous lines at various angles, and meet the edge of the input image at each possible offset.
This function computes the offset and angle for each entry in the
arrayoutput ofadrt.adrt(). These are returned as a pair(offset, angle).The integer argument n specifies the size of the ADRT domain. This is the size of the \(N \times N\) input image or equivalently the final dimension of the ADRT output with shape
(4, 2*n-1, n).The return value output, contains the offset coordinate of each ADRT component and has the same size as the ADRT output.
The angle return value stores the angles in radians that the corresponding digital line is designed to approximate. This array is squeezed to save memory and is broadcastable with the full ADRT output. Consider
numpy.broadcast_to()to expand this array to full size, if desired.- Parameters:
n (int) – The size of the ADRT domain. Either the size of the input image
(n, n), or equivalently the final dimension of the ADRT output(4, 2*n-1, n). Must be a power of two.- Returns:
offset (numpy.ndarray of numpy.float64) – 3D array of dimensions
(4, 2*n-1, n)containing Radon domain offset coordinates of the ADRT domain for each of four quadrants.angle (numpy.ndarray of numpy.float64) – 3D array of dimensions
(4, 1, n)containing Radon domain theta (angle) coordinates of the ADRT domain for each of four quadrants in radians. These angles are measured in radians, and are in the canonical range from \(-\pi/2\) through \(\pi/2\).
Notes
See the coordinate transform section for more details on how the Radon domain relates to the ADRT domain, and Forward Transform for more information on the ADRT.
- adrt.utils.coord_cart_to_adrt(theta, t, n)[source]
Convert continuous Radon points to the closest ADRT indices.
Given points \((\theta, t)\) in the continuous Radon domain, where \(\theta\) is in radians and t is in normalized coordinates between \(-1/\sqrt{2}\) and \(1/\sqrt{2}\), find the index of the closest corresponding entry in an ADRT output. This is the digital ADRT line with height and slope most closely matching these input coordinates.
This function can be used to find entries in the ADRT that most closely approximate a line in a continuous Radon transform. The input arrays theta, and t represent the continuous (Cartesian) Radon coordinates \(\theta\) and \(t\), respectively.
The argument n gives the size of the ADRT domain over which to query. This is the size of the \(N \times N\) input image or equivalently the final dimension of the ADRT output with shape
(4, 2*n-1, n).Coordinates are provided in NumPy arrays which allow multiple points to be queried at once. The arrays must have the same shape, which can otherwise be arbitrary.
The return values are quadrant, height, slope, and factor. The first three of these are indices into an ADRT output (as in
adrt_out[quadrant, height, slope]), and the final coordinate is a scaling factor which may be applied to the value of this entry. The output arrays all have the same shape as the input arrays theta and t.- Parameters:
theta (numpy.ndarray of float) – Angle \(\theta\) coordinates in continuous Radon space, in radians to be converted to the closest ADRT index.
t (numpy.ndarray of float) – Offset \(t\) coordinates in continuous Radon space. In normalized coordinates between \(-1/\sqrt{2}\) and \(1/\sqrt{2}\).
n (int) – The size of the ADRT domain. Either the size of the input image
(n, n), or equivalently the final dimension of the ADRT output(4, 2*n-1, n). Must be a power of two.
- Returns:
quadrant (numpy.ndarray of numpy.uint8) – Quadrant indices in ADRT domain. These are integers from
0through3, inclusive.height (numpy.ndarray of numpy.int64) – The intercept indices in the ADRT domain.
slope (numpy.ndarray of numpy.uint64) – The slope/angle indices in the ADRT domain.
factor (numpy.ndarray of numpy.float64) – A transformation factor for each identified ADRT entry.
Notes
When the provided theta value is a multiple of \(\pi/4\) and so lies exactly on the boundary between quadrants, the height and slope indices for the lower indexed quadrant are provided.
See the coordinate transform section for more details on how the Radon domain relates to the ADRT domain.