sitk-registration-sys

Crates.iositk-registration-sys
lib.rssitk-registration-sys
version0.2.0
created_at2025-03-01 18:55:18.383739+00
updated_at2025-09-12 17:16:40.505476+00
descriptionregister and interpolate images
homepagehttps://github.com/wimpomp/sitk-registration-sys
repositoryhttps://github.com/wimpomp/sitk-registration-sys
max_upload_size
id1573952
size7,685,359
(wimpomp)

documentation

https://docs.rs/sitk-registration-sys

README

sitk-registration-sys

This crate does two things:

  • find an affine transform or translation that transforms one image into the other
  • use bspline or nearest neighbor interpolation to apply a transformation to an image

To do this, SimpleITK, which is written in C++, is used. An adapter library is created using autocxx to expose the required functionality in SimpleITK. Because of this, compilation of this crate requires quite some time, several GB of memory, up to 50 GB of hard disk space, as well as cmake, a C++ compiler, llvm and git. Use at your own risk!

Examples

Registration

use ndarray::Array2;
use sitk_registration_sys::registration::{AffineTransform, julia_image};

let j = julia_image(0f32, 0f32).unwrap();
let shape = j.shape();
let origin = [
    ((shape[1] - 1) as f64) / 2f64,
    ((shape[0] - 1) as f64) / 2f64,
];
let s = AffineTransform::new([1.2, 0., 0., 1., 5., 7.], origin, [shape[0], shape[1]]);
let k: Array2<_> = s.transform_image_bspline(j.view()).unwrap().into();
let t = AffineTransform::register_affine(j.view(), k.view()).unwrap().inverse().unwrap();
let d = (t.matrix() - s.matrix()).powi(2).sum();
assert!(d < 0.025, "d: {}, t: {:?}", d, t.parameters);

Interpolation

use ndarray::Array2;
use sitk_registration_sys::registration::{AffineTransform, julia_image};

let j = julia_image(-120f32, 10f32).unwrap();
let k = julia_image(0f32, 0f32).unwrap();
let shape = j.shape();
let origin = [
    ((shape[1] - 1) as f64) / 2f64,
    ((shape[0] - 1) as f64) / 2f64,
];
let transform = AffineTransform::new([1., 0., 0., 1., 120., -10.], origin, [shape[0], shape[1]]);
let n: Array2<_> = transform.transform_image_bspline(j.view()).unwrap().into();
let d = (k.mapv(|x| x as f64) - n.mapv(|x| x as f64)).powi(2).sum();
assert!(d <= (shape[0] * shape[1]) as f64);
Commit count: 7

cargo fmt