Camera
nanodrr.geometry
¶
Extrinsics¶
nanodrr.camera.extrinsics.make_rt_inv
¶
make_rt_inv(
rotation: Float[Tensor, "B 3"],
translation: Float[Tensor, "B 3"],
orientation: str | None = "AP",
isocenter: Float[Tensor, 3] | None = None,
) -> Float[Tensor, "B 4 4"]
Construct camera-to-world (extrinsic inverse) matrices.
Computes extrinsic_inv = pose @ reorient, where pose encodes a
ZXY Euler rotation and translation, and reorient is a fixed
orientation-dependent transform.
| PARAMETER | DESCRIPTION |
|---|---|
rotation
|
(B, 3) ZXY Euler angles in degrees.
TYPE:
|
translation
|
(B, 3) Camera position in mm, relative to
TYPE:
|
orientation
|
Acquisition orientation — one of
TYPE:
|
isocenter
|
Optional (3,) volume center in world coordinates.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[Tensor, 'B 4 4']
|
(B, 4, 4) camera-to-world matrices. |
Source code in src/nanodrr/camera/extrinsics.py
nanodrr.camera.extrinsics.invert_rt_inv
¶
invert_rt_inv(
extrinsic_inv: Float[Tensor, "B 4 4"],
orientation: str | None = "AP",
isocenter: Float[Tensor, 3] | None = None,
) -> tuple[Float[Tensor, "B 3"], Float[Tensor, "B 3"]]
Recover rotation and translation from camera-to-world matrices.
Inverts the composition performed by make_rt_inv. The
orientation and isocenter arguments must match those used during
construction to obtain correct results.
| PARAMETER | DESCRIPTION |
|---|---|
extrinsic_inv
|
(B, 4, 4) camera-to-world matrices.
TYPE:
|
orientation
|
Acquisition orientation — one of
TYPE:
|
isocenter
|
Optional (3,) volume center in world coordinates.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
rotation
|
(B, 3) ZXY Euler angles in degrees.
TYPE:
|
translation
|
(B, 3) Camera position in mm, relative to
TYPE:
|
Source code in src/nanodrr/camera/extrinsics.py
Intrinsics¶
nanodrr.camera.intrinsics.make_k_inv
¶
make_k_inv(
sdd: float,
delx: float,
dely: float,
x0: float,
y0: float,
height: int,
width: int,
dtype: dtype | None = None,
device: device | None = None,
) -> Float[Tensor, "1 3 3"]
Build the inverse intrinsic matrix \(\mathbf K^{-1}\) for a cone-beam projector.
where delx \(= \Delta_x\) and dely \(= \Delta_y\).
The returned matrix is the analytical inverse of the intrinsic matrix:
| PARAMETER | DESCRIPTION |
|---|---|
sdd
|
Source-to-detector distance (mm).
TYPE:
|
delx
|
Pixel spacing in x (mm/px).
TYPE:
|
dely
|
Pixel spacing in y (mm/px).
TYPE:
|
x0
|
Principal-point offset from detector centre in x (mm).
TYPE:
|
y0
|
Principal-point offset from detector centre in y (mm).
TYPE:
|
height
|
Detector height in pixels.
TYPE:
|
width
|
Detector width in pixels.
TYPE:
|
dtype
|
Optional tensor dtype.
TYPE:
|
device
|
Optional tensor device.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[Tensor, '1 3 3']
|
(1, 3, 3) inverse intrinsic matrix. |
Source code in src/nanodrr/camera/intrinsics.py
Homography¶
nanodrr.camera.homography.resample
¶
resample(
img: Float[Tensor, "B C H W"],
k_inv_old: Float[Tensor, "B 3 3"],
k_inv_new: Float[Tensor, "B 3 3"],
) -> Float[Tensor, "B C H W"]
Resample an image from one camera's (inverse) intrinsic to another's.
Each target pixel \(p'\) is mapped back to a source pixel via the homography
and bilinearly interpolated. Out-of-bounds regions are filled with zeros.
| PARAMETER | DESCRIPTION |
|---|---|
img
|
Batch of images.
TYPE:
|
k_inv_old
|
Inverse intrinsic matrices of the source images.
TYPE:
|
k_inv_new
|
Inverse intrinsic matrices of the target images.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[Tensor, 'B C H W']
|
Resampled images. |