torchreg
torchreg is a tiny (~300 lines) PyTorch-based library for 2D and 3D image registration.
Usage
Affine Registration of two image tensors is done via:
from torchreg import AffineRegistration
# Load images as torch Tensors
big_alice = ... # Tensor with shape [1, 3 (color channel), 1024 (pixel), 1024 (pixel)]
small_alice = ... # Tensor with shape [1, 3 (color channel), 1024 (pixel), 1024 (pixel)]
# Intialize AffineRegistration
reg = AffineRegistration(is_3d=False)
# Run it!
moved_alice = reg(big_alice, small_alice)
Features
Multiresolution approach to save compute (per default 1/4 + 1/2 of original resolution for 500 + 100 iterations)
reg = AffineRegistration(scales=(4, 2), iterations=(500, 100))
Choosing which operations (translation, rotation, zoom, shear) to optimize
reg = AffineRegistration(with_zoom=False, with_shear=False)
Custom initial parameters
reg = AffineRegistration(zoom=torch.Tensor([[1.5, 2.]]))
Custom dissimilarity functions and optimizers
def dice_loss(x1, x2):
dim = [2, 3, 4] if len(x2.shape) == 5 else [2, 3]
inter = torch.sum(x1 * x2, dim=dim)
union = torch.sum(x1 + x2, dim=dim)
return 1 - (2. * inter / union).mean()
reg = AffineRegistration(dissimilarity_function=dice_loss, optimizer=torch.optim.Adam)
CUDA support (NVIDIA GPU)
moved_alice = reg(moving=big_alice.cuda(), static=small_alice.cuda())
After the registration is run, you can apply it to new images (coregistration)
another_moved_alice = reg.transform(another_alice, shape=(256, 256))
with desired output shape.
You can access the affine
affine = reg.get_affine()
and the four parameters (translation, rotation, zoom, shear)
translation = reg.parameters[0]
rotation = reg.parameters[1]
zoom = reg.parameters[2]
shear = reg.parameters[3]
Installation
pip install torchreg
Examples/Tutorials
There are three example notebooks:
- examples/basics.ipynb shows the basics by using small cubes/squares as image data
- examples/images.ipynb shows how to register alice_big.jpg to alice_small.jpg
- examples/mri.ipynb shows how to register MR images (Nifti files) including co-, parallel and multimodal registration
Background
If you want to know how the core of this package works, read the blog post!
TODO
- Add 2D support to SyN, NCC and LinearElasticity
- Add tests for SyN
Metadata
Release files for torchreg 0.1.3
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| torchreg-0.1.3.tar.gz | 7.0 kB | Without provenance | Details for torchreg-0.1.3.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| torchreg-0.1.3-py3-none-any.whl | Python 3 | none | any | Details for torchreg-0.1.3-py3-none-any.whl |
Total release size: 16.0 kB
Release files / torchreg-0.1.3.tar.gz
| Download URL | torchreg-0.1.3.tar.gz |
|---|---|
| Size | 7.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3e1b5fb9a0ae86ffa9232db655645412c884e7cd8378701cd50f9570a8cd0301
|
|
BLAKE2b-256 checksum How to use checksums |
9a78024d4a80ec67c2008e5fba4b10915a56d3497e55148c3c0b7e22bbce1a76
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-21-generic
|
Release files / torchreg-0.1.3-py3-none-any.whl
| Download URL | torchreg-0.1.3-py3-none-any.whl |
|---|---|
| Size | 9.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
e2580150566026400a086c1043bbdccc808996ed86bafd7a23a0610e3193693b
|
|
BLAKE2b-256 checksum How to use checksums |
09b41c443f97cf1bc4c1ea96b605160215ec15c2b475997f712da76091e84b2a
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.1.3 CPython/3.12.3 Linux/6.11.0-21-generic
|
Security for torchreg 0.1.3
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.