-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
659df57
commit b1cc415
Showing
8 changed files
with
153 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,3 +9,4 @@ docs/build | |
.vscode | ||
**flycheck*.py | ||
/.DS_Store | ||
output |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,43 @@ | ||
"""Util functions for automated tests.""" | ||
|
||
import logging | ||
from pathlib import Path | ||
from torchvision.datasets.utils import download_url | ||
|
||
logger = logging.getLogger(__name__) | ||
|
||
_sampledata = { | ||
'CT-chest': 'http://www.slicer.org/w/img_auth.php/3/31/CT-chest.nrrd', | ||
} | ||
|
||
def download_sampledata(name: str = 'CT-chest', root: str = "~/datasets/") -> Path: | ||
"""Download the sample volumes for testing, if they are not already present. | ||
Args: | ||
name (str, optional): The name of the volume, used as a key to the public domain downloadable data. Defaults to 'CT-chest'. | ||
root (str, optional): The root where datasets are kept. A new dataset directory will be created in `root`, called `DeepDRR_SampleData`. Defaults to "~/datasets/". | ||
Returns: | ||
Path: The path to the downloaded file. | ||
""" | ||
if name not in _sampledata: | ||
logger.error(f"unrecognized sample data name: {name}. Options are:\n{list(_sampledata.keys())}") | ||
|
||
root = Path(root).expanduser() | ||
if not root.exists(): | ||
root.mkdir() | ||
|
||
dataset_dir = root / 'DeepDRR_SampleData' | ||
if not dataset_dir.exists(): | ||
dataset_dir.mkdir() | ||
|
||
fpath = dataset_dir / f"{name}.nrrd" | ||
if fpath.exists(): | ||
return fpath | ||
|
||
logger.info(f"Downloading sample volume to {fpath}") | ||
|
||
download_url(_sampledata[name], root=dataset_dir, filename=fpath.name) | ||
|
||
logger.info("Done.") | ||
return fpath |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,6 +6,7 @@ scikit-image | |
pydicom | ||
scipy | ||
pyvista | ||
pynrrd | ||
# pycuda # docs build machines don't have GPUs | ||
|
||
flake8 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,3 +8,4 @@ pydicom | |
scipy | ||
pyvista | ||
pycuda | ||
pynrrd |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,7 +5,7 @@ | |
|
||
setuptools.setup( | ||
name="deepdrr", | ||
version="1.1.0a1", | ||
version="1.1.0a2", | ||
author="Benjamin D. Killeen", | ||
author_email="[email protected]", | ||
description="A Catalyst for Machine Learning in Fluoroscopy-guided Procedures.", | ||
|
@@ -23,6 +23,7 @@ | |
"pyvista", | ||
"scipy", | ||
"pyvista", | ||
"pynrrd" | ||
], | ||
extras_require={"gpu": ["pycuda"]}, | ||
include_package_data=True, | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,37 @@ | ||
#!/usr/bin/env python3 | ||
|
||
from pydicom.data import get_testdata_file | ||
import numpy as np | ||
from pathlib import Path | ||
import deepdrr | ||
from deepdrr import geo | ||
from deepdrr.utils import testing | ||
from PIL import Image | ||
|
||
|
||
def test_simple(): | ||
file_path = get_testdata_file("CT_small.dcm") | ||
volume = deepdrr.Volume.from_dicom(file_path) | ||
print(volume) | ||
class TestSingleVolume: | ||
output_dir = Path.cwd() / 'output' | ||
output_dir.mkdir(exist_ok=True) | ||
|
||
def test_simple(self): | ||
file_path = testing.download_sampledata("CT-chest") | ||
volume = deepdrr.Volume.from_nrrd(file_path) | ||
carm = deepdrr.MobileCArm(isocenter=volume.center_in_world) | ||
with deepdrr.Projector( | ||
volume=volume, | ||
carm=carm, | ||
step=0.1, # stepsize along projection ray, measured in voxels | ||
mode="linear", | ||
max_block_index=200, | ||
spectrum="90KV_AL40", | ||
photon_count=100000, | ||
add_scatter=False, | ||
threads=8, | ||
neglog=True, | ||
) as projector: | ||
image = projector.project() | ||
|
||
image = (image * 255).astype(np.uint8) | ||
Image.fromarray(image).save(self.output_dir / 'test_simple.png') | ||
|
||
if __name__ == "__main__": | ||
TestSingleVolume().test_simple() |