- some bugfixes
This commit is contained in:
1 parent
ef9e257f75
commit
4306c26690
5 files changed
+108
-39
No files matched your search
+44
-4
@@ -100,9 +100,32 @@ fn matrix_inverse(matrix: Array2<f64>) -> Array2<f64> {
|
||||
inv
|
||||
}
|
||||
|
||||
#[derive(Deserialize)]
|
||||
struct TransformS {
|
||||
parameters: Vec<f64>,
|
||||
dparameters: Vec<f64>,
|
||||
center: Vec<f64>,
|
||||
shape: Vec<usize>,
|
||||
}
|
||||
|
||||
impl<D: Dimension> From<TransformS> for Transform<D> {
|
||||
fn from(t: TransformS) -> Self {
|
||||
let ndim = t.shape.len();
|
||||
Self {
|
||||
parameters: t.parameters,
|
||||
dparameters: t.dparameters,
|
||||
center: t.center,
|
||||
shape: t.shape,
|
||||
ndim,
|
||||
dimension: PhantomData::default(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// a struct describing the transform
|
||||
/// generic parameter N = # image dimensions
|
||||
#[derive(Clone, Debug, Deserialize, Serialize, PartialEq)]
|
||||
#[serde(from = "TransformS")]
|
||||
pub struct Transform<D: Dimension = Ix2> {
|
||||
/// flattened NxN rotation matrix + N translation parameters
|
||||
pub parameters: Vec<f64>,
|
||||
@@ -112,7 +135,9 @@ pub struct Transform<D: Dimension = Ix2> {
|
||||
pub center: Vec<f64>,
|
||||
/// the shape of images for which this transform is meant
|
||||
pub shape: Vec<usize>,
|
||||
#[serde(skip)]
|
||||
ndim: usize,
|
||||
#[serde(skip)]
|
||||
dimension: PhantomData<D>,
|
||||
}
|
||||
|
||||
@@ -463,12 +488,12 @@ impl<D: Dimension> Transform<D> {
|
||||
T: 'a + Clone + AsPrimitive<f64>,
|
||||
G: Into<FixedMu>,
|
||||
{
|
||||
let mut registration = Registration::new(fixed_mu);
|
||||
let mut registration = Registration::new(fixed_mu)?;
|
||||
if let Some(steps) = steps {
|
||||
registration.set_steps(steps);
|
||||
}
|
||||
if let Some(initial_guess) = initial_guess {
|
||||
registration.set_initial_guess(initial_guess);
|
||||
registration.set_initial_guess(initial_guess)?;
|
||||
}
|
||||
registration.register(fixed, moving)
|
||||
}
|
||||
@@ -488,12 +513,12 @@ impl<D: Dimension> Transform<D> {
|
||||
T: 'a + Clone + AsPrimitive<f64>,
|
||||
G: Into<FixedMu>,
|
||||
{
|
||||
let mut registration = Registration::new(fixed_mu);
|
||||
let mut registration = Registration::new(fixed_mu)?;
|
||||
if let Some(steps) = steps {
|
||||
registration.set_steps(steps);
|
||||
}
|
||||
if let Some(initial_guess) = initial_guess {
|
||||
registration.set_initial_guess(initial_guess);
|
||||
registration.set_initial_guess(initial_guess)?;
|
||||
}
|
||||
registration.register_debug(fixed, moving)
|
||||
}
|
||||
@@ -571,6 +596,11 @@ impl<D: Dimension> Transform<D> {
|
||||
Self::from_scaling(scaling) * self
|
||||
}
|
||||
|
||||
pub fn with_center(mut self, center: Vec<f64>) -> Self {
|
||||
self.center = center;
|
||||
self
|
||||
}
|
||||
|
||||
/// read a transform from a file
|
||||
pub fn from_file(path: PathBuf) -> Result<Self, Error> {
|
||||
let file = File::open(path)?;
|
||||
@@ -677,6 +707,16 @@ impl<D: Dimension> Transform<D> {
|
||||
matrix
|
||||
}
|
||||
|
||||
pub fn with_parameters(mut self, parameters: Vec<f64>) -> Self {
|
||||
self.parameters = parameters;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_dparameters(mut self, dparameters: Vec<f64>) -> Self {
|
||||
self.dparameters = dparameters;
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_matrix(mut self, matrix: ArrayView2<f64>) -> Self {
|
||||
let mut parameters = matrix
|
||||
.slice(s![..self.ndim, ..self.ndim])
|
||||
|
||||
Reference in new issue
Block a user