Skip to content

Commit 2d89c5d

Browse files
Initial commit
0 parents  commit 2d89c5d

15 files changed

Lines changed: 345 additions & 0 deletions

.gitignore

Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
# Byte-compiled / optimized / DLL files
2+
__pycache__/
3+
*.py[cod]
4+
*$py.class
5+
6+
# Distribution / packaging
7+
.Python
8+
build/
9+
develop-eggs/
10+
dist/
11+
downloads/
12+
eggs/
13+
.eggs/
14+
lib/
15+
lib64/
16+
parts/
17+
sdist/
18+
var/
19+
wheels/
20+
share/python-wheels/
21+
*.egg-info/
22+
.installed.cfg
23+
*.egg
24+
MANIFEST
25+
26+
# PyInstaller
27+
# Usually these files are written by a python script from a template
28+
# before PyInstaller builds the exe, so as to inject date/other infos into it.
29+
*.manifest
30+
*.spec
31+
32+
# Installer logs
33+
pip-log.txt
34+
pip-delete-this-directory.txt
35+
36+
# Unit test / coverage reports
37+
htmlcov/
38+
.tox/
39+
.nox/
40+
.coverage
41+
.coverage.*
42+
.cache
43+
nosetests.xml
44+
coverage.xml
45+
*.cover
46+
*.py,cover
47+
.hypothesis/
48+
.pytest_cache/
49+
cover/
50+
51+
# Translations
52+
*.mo
53+
*.pot
54+
55+
# Django stuff:
56+
*.log
57+
local_settings.py
58+
db.sqlite3
59+
db.sqlite3-journal
60+
61+
# Flask stuff:
62+
instance/
63+
.webassets-cache
64+
65+
# Scrapy stuff:
66+
.scrapy
67+
68+
# Sphinx documentation
69+
docs/_build/
70+
71+
# PyBuilder
72+
.pybuilder/
73+
target/
74+
75+
# Jupyter Notebook
76+
.ipynb_checkpoints
77+
78+
# IPython
79+
profile_default/
80+
ipython_config.py
81+
82+
# pyenv
83+
# For a library or package, you might want to ignore these files since the code is
84+
# intended to run in multiple environments; otherwise, check them in:
85+
# .python-version
86+
87+
# pipenv
88+
# According to pypa/pipenv#598, it is recommended to include Pipfile.lock in version control.
89+
# However, in case of collaboration, if having platform-specific dependencies or dependencies
90+
# having no cross-platform support, pipenv may install dependencies that don't work, or not
91+
# install all needed dependencies.
92+
#Pipfile.lock
93+
94+
# poetry
95+
# Similar to Pipfile.lock, it is generally recommended to include poetry.lock in version control.
96+
# This is especially recommended for binary packages to ensure reproducibility, and is more
97+
# commonly ignored for libraries.
98+
# https://python-poetry.org/docs/basic-usage/#commit-your-poetrylock-file-to-version-control
99+
#poetry.lock
100+
101+
# PEP 582; used by e.g. github.com/David-OConnor/pyflow
102+
__pypackages__/
103+
104+
# Celery stuff
105+
celerybeat-schedule
106+
celerybeat.pid
107+
108+
# SageMath parsed files
109+
*.sage.py
110+
111+
# Environments
112+
.env
113+
.venv
114+
env/
115+
venv/
116+
ENV/
117+
env.bak/
118+
venv.bak/
119+
120+
# Spyder project settings
121+
.spyderproject
122+
.spyproject
123+
124+
# Rope project settings
125+
.ropeproject
126+
127+
# mkdocs documentation
128+
/site
129+
130+
# mypy
131+
.mypy_cache/
132+
.dmypy.json
133+
dmypy.json
134+
135+
# Pyre type checker
136+
.pyre/
137+
138+
# pytype static type analyzer
139+
.pytype/
140+
141+
# Cython debug symbols
142+
cython_debug/
143+
144+
# PyCharm
145+
# JetBrains specific template is maintainted in a separate JetBrains.gitignore that can
146+
# be found at https://github.com/github/gitignore/blob/main/Global/JetBrains.gitignore
147+
# and can be added to the global gitignore or merged into this file. For a more nuclear
148+
# option (not recommended) you can uncomment the following to ignore the entire idea folder.
149+
#.idea/

LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2022 wiktorowski211
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# DEnse Displacement Sampling - deformable image registration
2+
3+
This package provides Python wrapper around [DEEDS](https://github.com/mattiaspaul/deedsBCV), an efficient version for 3D discrete deformable image registration which is reaching the highest accuracy in several benchmarks [[1]](https://pubmed.ncbi.nlm.nih.gov/27254856/)[[2]](https://arxiv.org/abs/2109.11572) and serves as a good baseline for new solutions.
4+
5+
## Referencing and citing
6+
If you use this implementation or parts of it please cite:
7+
8+
>"MRF-Based Deformable Registration and Ventilation Estimation of Lung CT."
9+
by Mattias P. Heinrich, M. Jenkinson, M. Brady and J.A. Schnabel
10+
IEEE Transactions on Medical Imaging 2013, Volume 32, Issue 7, July 2013, Pages 1239-1248
11+
http://dx.doi.org/10.1109/TMI.2013.2246577
12+
13+
and
14+
15+
>"Multi-modal Multi-Atlas Segmentation using Discrete Optimisation and Self-Similarities"
16+
by Mattias P. Heinrich, Oskar Maier and Heinz Handels
17+
VISCERAL Challenge@ ISBI, Pages 27-30 2015
18+
http://ceur-ws.org/Vol-1390/visceralISBI15-4.pdf
19+
20+
## Installation
21+
Current version requires an Unix-based system.
22+
```
23+
pip install git+https://github.com/wiktorowski211/deeds-registration
24+
```
25+
26+
## Usage
27+
```
28+
from deeds import registration
29+
import SimpleITK as sitk
30+
31+
fixed = sitk.ReadImage(PATH)
32+
moving = sitk.ReadImage(PATH)
33+
34+
moved = registration(fixed, moving)
35+
```
36+
37+
## Limitations
38+
Input images must:
39+
- have the same dimensions,
40+
- be a SimpleITK image object.

deeds/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
from .registration import registration

deeds/libs/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2017 mattiaspaul
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

deeds/libs/__init__.py

Whitespace-only changes.

deeds/libs/deedsBCV.so

162 KB
Binary file not shown.

deeds/registration.py

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
import os
2+
import tempfile
3+
import subprocess
4+
5+
try:
6+
import importlib.resources as pkg_resources
7+
except ImportError:
8+
# Try backported to PY<37 `importlib_resources`.
9+
import importlib_resources as pkg_resources
10+
11+
from .utils import *
12+
13+
14+
def registration(fixed, moving, verbose=True):
15+
libs_path = pkg_resources.files('deeds.libs')
16+
17+
deeds_path = os.path.join(libs_path, "deedsBCV.so")
18+
19+
stdout = None if verbose else subprocess.DEVNULL
20+
21+
# TODO: Use in-memory communication instead of the filesystem
22+
with tempfile.TemporaryDirectory() as tmp_dir:
23+
fixed_path = os.path.join(tmp_dir, "fixed.nii.gz")
24+
moving_path = os.path.join(tmp_dir, "moving.nii.gz")
25+
moved_path = os.path.join(tmp_dir, "moved")
26+
27+
save_nifty(fixed, fixed_path)
28+
save_nifty(moving, moving_path)
29+
30+
command = f"{deeds_path} -F {fixed_path} -M {moving_path} -O {moved_path}"
31+
32+
subprocess.run(command.split(), stdout=stdout)
33+
34+
moved_path = f"{moved_path}_deformed.nii.gz"
35+
36+
moved = load_nifty(moved_path)
37+
38+
return moved

deeds/tests/__init__.py

Whitespace-only changes.

deeds/tests/test_registration.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
import unittest
2+
3+
from ..registration import registration
4+
from ..utils import *
5+
6+
7+
class TestStringMethods(unittest.TestCase):
8+
9+
def test_deeds_registration(self):
10+
fixed = load_nifty('samples/fixed.nii.gz')
11+
moving = load_nifty('samples/moving.nii.gz')
12+
13+
moved = registration(fixed, moving)
14+
15+
dice_before = compute_dice_score(fixed, moving)
16+
dice_after = compute_dice_score(fixed, moved)
17+
18+
self.assertGreater(dice_after, dice_before)

0 commit comments

Comments
 (0)