# 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](https://github.com/SimpleITK/SimpleITK.git), which is written in C++, is used. An adapter library is created using [autocxx](https://crates.io/crates/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); ```