Data
nanodrr.data
¶
Subject
¶
Subject(
imagedata: Float[Tensor, "1 1 D H W"],
labeldata: Float[Tensor, "1 1 D H W"],
voxel_to_world: Float[Tensor, "4 4"],
world_to_voxel: Float[Tensor, "4 4"],
voxel_to_grid: Float[Tensor, "4 4"],
isocenter: Float[Tensor, 3],
max_label: int | None = None,
)
Wrapper for a CT volume and (optional) labelmap that is compatible with
torch.nn.functional.grid_sample.
Fuses all spatial transforms required for sampling (world → voxel → grid) so
that rendering only needs to perform a single matmul.
Source code in src/nanodrr/data/io.py
from_filepath
classmethod
¶
from_filepath(
imagepath: str | Path,
labelpath: str | Path | None = None,
convert_to_mu: bool = True,
mu_water: float = 0.0192,
mu_bone: float = 0.0573,
hu_bone: float = 1000.0,
max_label: int | None = None,
) -> Subject
Load a subject from NIfTI (or any TorchIO-supported) file paths.
| PARAMETER | DESCRIPTION |
|---|---|
imagepath
|
Path to the CT volume. |
labelpath
|
Optional path to a label map. |
convert_to_mu
|
Convert Hounsfield units to linear attenuation.
TYPE:
|
mu_water
|
Linear attenuation coefficient of water (mm⁻¹).
TYPE:
|
max_label
|
Override the maximum label index. If provided,
TYPE:
|
Source code in src/nanodrr/data/io.py
from_images
classmethod
¶
from_images(
image: ScalarImage,
label: LabelMap | None = None,
convert_to_mu: bool = True,
mu_water: float = 0.0192,
mu_bone: float = 0.0573,
hu_bone: float = 1000.0,
max_label: int | None = None,
) -> Subject
Construct a subject from TorchIO image objects.
| PARAMETER | DESCRIPTION |
|---|---|
image
|
CT volume as a
TYPE:
|
label
|
Optional segmentation as a
TYPE:
|
convert_to_mu
|
Convert Hounsfield units to linear attenuation.
TYPE:
|
mu_water
|
Linear attenuation coefficient of water (mm⁻¹).
TYPE:
|
max_label
|
Override the maximum label index. If provided,
TYPE:
|
Source code in src/nanodrr/data/io.py
nanodrr.data.preprocess
¶
hu_to_mu
¶
hu_to_mu(
data: Float[Tensor, "1 1 D H W"],
mu_water: float = 0.0192,
mu_bone: float = 0.0573,
hu_bone: float = 1000.0,
) -> Float[Tensor, "1 1 D H W"]
Convert Hounsfield units to linear attenuation coefficients.
Uses bilinear scaling with air-water model for HU ≤ 0 and water-bone model for HU > 0:
| PARAMETER | DESCRIPTION |
|---|---|
data
|
CT volume in Hounsfield Units with shape (1, 1, D, H, W).
TYPE:
|
mu_water
|
Linear attenuation coefficient of water [1/mm] at target energy. Default 0.0192 corresponds to ~70 keV (typical CT effective energy).
TYPE:
|
mu_bone
|
Linear attenuation coefficient of cortical bone [1/mm] at target energy. Default 0.0573 corresponds to ~70 keV.
TYPE:
|
hu_bone
|
HU value corresponding to pure cortical bone. Default 1000. Typical range is 1000-2000 depending on bone type and scanner.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
Float[Tensor, '1 1 D H W']
|
Linear attenuation coefficients [1/mm] with same shape as input. |
References
NIST XCOM database for mass attenuation coefficients. Water density: 1.0 g/cm³, cortical bone density: 1.92 g/cm³.
Source code in src/nanodrr/data/preprocess.py
nanodrr.data.demo
¶
download_deepfluoro
¶
Download a subject from the DeepFluoro dataset.