register¶
xvr.register.initializers
¶
PoseInitializer
¶
Strategy for computing the initial pose estimate before optimization.
Concrete implementations expose two pieces of metadata read by
Register during setup, plus a callable that produces a RigidTransform
given the current X-ray context.
| ATTRIBUTE | DESCRIPTION |
|---|---|
orientation |
Patient orientation for the DRR.
TYPE:
|
reverse_x_axis |
Horizontally flip the rendered DRRs.
TYPE:
|
__call__
¶
__call__(ctx: XrayContext) -> RigidTransform
FixedPose
¶
Initial pose specified manually as Euler angles and a translation.
Useful when an approximate pose is already known, e.g., from a prior scan, a clinical estimate, or a hand-tuned guess.
| ATTRIBUTE | DESCRIPTION |
|---|---|
rot |
Rotation angles in degrees as (rx, ry, rz), ZXY convention. |
xyz |
Translation in mm as (x, y, z). |
eps |
Small value added to inputs to avoid degenerate gradients.
TYPE:
|
ModelPose
¶
Initial pose predicted by a neural network from the X-ray image.
The checkpoint dictates orientation and reverse_x_axis; users do not
set these directly.
| ATTRIBUTE | DESCRIPTION |
|---|---|
ckpt |
Path to the model checkpoint.
TYPE:
|
volume |
Path to the CT image the warp is defined against (Register's imagepath).
TYPE:
|
warp |
SimpleITK transform reframing the predicted pose into the CT's frame. None for patient-specific models already in the CT's frame.
TYPE:
|
antipodal |
Initialize from the antipode of the predicted pose.
TYPE:
|
DicomPose
¶
Initial pose parsed from pose parameters in the DICOM metadata.
xvr.register.logging
¶
OptimizationLogger
dataclass
¶
OptimizationLogger(
losses: list[float],
scales: list[float],
rescale_factors: list[float],
times: list[float],
rots: Float[Tensor, "N 3"],
xyzs: Float[Tensor, "N 3"],
)
Log the intermediates of a multiscale optimization run.
RegistrationResult
¶
RegistrationResult(
drr: DRR,
pose: Pose,
init_pose: RigidTransform,
gt: Float[Tensor, "1 1 H W"],
log: OptimizationLogger | None = None,
)
The result of a registration run.
| PARAMETER | DESCRIPTION |
|---|---|
drr
|
The DRR renderer with detector geometry.
TYPE:
|
pose
|
The optimized pose model.
TYPE:
|
init_pose
|
The initial pose estimate.
TYPE:
|
gt
|
The preprocessed ground truth X-ray.
TYPE:
|
log
|
The optimization log.
TYPE:
|
Source code in src/xvr/register/logging.py
save
¶
Save the registration result to a checkpoint file.
| PARAMETER | DESCRIPTION |
|---|---|
path
|
Output file path. |
Source code in src/xvr/register/logging.py
xvr.register.loss
¶
load_loss_function
¶
Initialize a loss function for 2D/3D registration.
| PARAMETER | DESCRIPTION |
|---|---|
loss
|
Either the name of a loss function in
TYPE:
|
**kwargs
|
Optional arguments for the constructor of the loss function.
TYPE:
|
Source code in src/xvr/register/loss.py
xvr.register.losses.gmncc
¶
GradientMultiscaleNormalizedCrossCorrelation2d
¶
GradientMultiscaleNormalizedCrossCorrelation2d(
mncc_patch_size: int = 9,
gncc_patch_size: int = 11,
sigma: float = 0.0,
beta: float = 0.5,
)
A weighted average of gradient and multiscale NCC.
Source code in src/xvr/register/losses/gmncc.py
xvr.register.plot
¶
RegistrationOutput
¶
gif
¶
gif(
logger: OptimizationLogger, width: int = 600, duration: int = 500
) -> RegistrationOutput
Animate between GT and predictions as an infinitely looping GIF.
| PARAMETER | DESCRIPTION |
|---|---|
logger
|
OptimizationLogger with .gt, .init_pose, .final_pose, and .drr.
TYPE:
|
width
|
Display width in pixels when rendered in Jupyter.
TYPE:
|
duration
|
Time per frame in milliseconds.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RegistrationOutput
|
RegistrationOutput that renders inline in Jupyter and can be saved to disk. |
Source code in src/xvr/register/plot.py
plot
¶
plot(
logger: OptimizationLogger,
method: VizMethod = "edges",
histeq_strength: float = 0.5,
width: int = 900,
**kwargs: Any,
) -> RegistrationOutput
Visualise registration results (GT | GT vs initial pred | GT vs final pred).
| PARAMETER | DESCRIPTION |
|---|---|
logger
|
OptimizationLogger with .gt, .init_pose, .final_pose, and .drr.
TYPE:
|
method
|
Comparison method, one of "overlay", "checkerboard", "edges".
TYPE:
|
histeq_strength
|
Histogram equalisation strength (0.0 = off, 1.0 = full).
TYPE:
|
width
|
Display width in pixels when rendered in Jupyter.
TYPE:
|
**kwargs
|
Forwarded to the chosen method function. "checkerboard" accepts n_patches (int, default 8); "edges" accepts sigma (float, default 2.0).
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RegistrationOutput
|
RegistrationOutput that renders inline in Jupyter and can be saved to disk. |
Source code in src/xvr/register/plot.py
xvr.register.pose
¶
Pose
¶
Optimizable pose defined on the global chart.
Source code in src/xvr/register/pose.py
xvr.register.register
¶
Register
¶
2D/3D image registration.
Performs multiscale gradient-based registration of a CT volume to an X-ray image by optimizing a differentiable image similarity metric over the pose parameters of a DRR renderer.
The strategy used to compute the initial pose estimate is supplied via the
initializer argument. See PoseInitializer for the contract; built-in
implementations include FixedPose and ModelPose.
| ATTRIBUTE | DESCRIPTION |
|---|---|
imagepath |
Path to the CT image.
TYPE:
|
initializer |
Strategy for computing the initial pose before optimization.
Also supplies the CT orientation and DRR
TYPE:
|
labelpath |
Path to the segmentation label map. If None, uses the full image.
TYPE:
|
labels |
Label indices to include in the DRR. If None, uses all labels. |
metric |
Image similarity metric, either a string key or a custom nn.Module.
TYPE:
|
metric_kwargs |
Additional keyword arguments passed to the loss function.
TYPE:
|
scales |
Downsampling scale(s) for multiscale registration. |
n_itrs |
Number of optimization iterations per scale. |
lr_rot |
Learning rate for rotation parameters.
TYPE:
|
lr_xyz |
Learning rate for translation parameters.
TYPE:
|
lr_reduce_factor |
Factor by which to reduce the learning rate on plateau.
TYPE:
|
patience |
Number of steps without improvement before reducing the learning rate. |
threshold |
Minimum change to qualify as an improvement.
TYPE:
|
max_n_plateaus |
Number of learning rate reductions before early stopping.
TYPE:
|
device |
Torch device to run on.
TYPE:
|
__call__
¶
__call__(
filename: str,
crop: int = 0,
linearize: bool = True,
subtract_background: bool = False,
equalize: bool = False,
reducefn: str | int | Callable = "max",
parameterization: str = "euler_angles",
convention: str | None = "ZXY",
init_only: bool = False,
savepath: Path | str | None = None,
saveplot: bool = False,
) -> RegistrationResult
Run registration on an X-ray image.
Preprocesses the X-ray, computes an initial pose estimate via
self.initializer, and runs multiscale gradient-based optimization
to refine the pose.
| PARAMETER | DESCRIPTION |
|---|---|
filename
|
Path to the X-ray image.
TYPE:
|
crop
|
Number of pixels to crop from the image border.
TYPE:
|
linearize
|
Convert image to linear attenuation values.
TYPE:
|
subtract_background
|
Subtract background from the image.
TYPE:
|
equalize
|
Apply histogram equalization during optimization.
TYPE:
|
reducefn
|
Reduction function for multi-frame images. |
parameterization
|
Representation of SO(3) for pose optimization.
TYPE:
|
convention
|
If
TYPE:
|
init_only
|
Return initial pose estimate result without optimization.
TYPE:
|
savepath
|
Location to save the registration results. |
saveplot
|
Save plots of registration results.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
RegistrationResult
|
A RegistrationResult with the optimized pose and full optimization log. |
Source code in src/xvr/register/register.py
parse_scales
¶
Convert absolute downscale factors to sequential rescale ratios for an image pyramid.
| PARAMETER | DESCRIPTION |
|---|---|
scales
|
Absolute downscale factors relative to the original image (e.g. [8, 4, 2, 1]). A scale of 1.0 snaps back to full cropped resolution. |
crop
|
Total pixels cropped from the original image (crop/2 from each side).
TYPE:
|
height
|
Height of the cropped image in pixels.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
list[float]
|
Sequential rescale ratios between consecutive pyramid levels. |