- registration getting better
This commit is contained in:
1 parent
bb3d46cc9d
commit
001df705ef
3 files changed
+52
-35
No files matched your search
+18
-14
@@ -19,7 +19,7 @@ pub enum Optimizer {
|
||||
|
||||
impl Default for Optimizer {
|
||||
fn default() -> Self {
|
||||
Self::ASGD
|
||||
Self::LBFGS
|
||||
}
|
||||
}
|
||||
|
||||
@@ -61,16 +61,16 @@ impl RegistrationStep {
|
||||
///
|
||||
/// Uses a multi-resolution pyramid with downsampling matching SimpleElastix:
|
||||
/// schedule [8, 4, 2, 1] → σ = [4.0, 2.0, 1.0, 0.5] at spacing=1.
|
||||
/// 512 iterations per level, 2048–8192 cached random samples.
|
||||
/// Uses all pixels at all levels for deterministic, precise convergence.
|
||||
pub fn default_steps(ndim: usize, n: usize) -> Vec<Self> {
|
||||
if ndim == 1 {
|
||||
return vec![Self {
|
||||
sigma: Sigma::Absolute(vec![1.0; 1]),
|
||||
samples: SamplingArg::Random(2048.min(n)),
|
||||
samples: SamplingArg::Random(n),
|
||||
n_bins: 32,
|
||||
tolerance: 1e-6,
|
||||
tolerance: 1e-8,
|
||||
edge: 0.05,
|
||||
max_iterations: 1500,
|
||||
max_iterations: 2048,
|
||||
learning_rate: 1.0,
|
||||
downsample: 1,
|
||||
}];
|
||||
@@ -78,19 +78,23 @@ impl RegistrationStep {
|
||||
// Pyramid with downsampling: schedule [8,4,2,1], sigma [4,2,1,0.5]
|
||||
let sigma_schedule: Vec<f64> = vec![4.0, 2.0, 1.0, 0.5];
|
||||
let downsample_schedule: Vec<usize> = vec![8, 4, 2, 1];
|
||||
let n_levels = sigma_schedule.len();
|
||||
sigma_schedule
|
||||
.iter()
|
||||
.zip(downsample_schedule.iter())
|
||||
.map(|(&s, &d)| {
|
||||
.enumerate()
|
||||
.map(|(level, (&s, &d))| {
|
||||
let n_pixels = (n / (d * d)).max(4);
|
||||
let n_samples = n_pixels.min(8192).max(2048);
|
||||
let is_finest = level == n_levels - 1;
|
||||
// Use all pixels at all levels for deterministic results
|
||||
let (max_iter, tol) = if is_finest { (2048, 1e-8) } else { (512, 1e-6) };
|
||||
Self {
|
||||
sigma: Sigma::Absolute(vec![s; ndim]),
|
||||
samples: SamplingArg::Random(n_samples),
|
||||
samples: SamplingArg::Random(n_pixels),
|
||||
n_bins: 32,
|
||||
tolerance: 1e-6,
|
||||
tolerance: tol,
|
||||
edge: 0.05,
|
||||
max_iterations: 512,
|
||||
max_iterations: max_iter,
|
||||
learning_rate: 1.0,
|
||||
downsample: d,
|
||||
}
|
||||
@@ -318,7 +322,7 @@ impl<D: Dimension> Registration<D> {
|
||||
continue;
|
||||
}
|
||||
let bf = BSpline::<0, _>::new(f.view());
|
||||
let bm = BSpline::<1, _>::new(m.view());
|
||||
let bm = BSpline::<3, _>::new(m.view());
|
||||
let metric = MattesMetric::new(bf, bm, samples, n_bins, edge)?
|
||||
.with_fixed_mu(self.fixed_mu.clone());
|
||||
|
||||
@@ -344,7 +348,7 @@ impl<D: Dimension> Registration<D> {
|
||||
tolerance,
|
||||
maximum_step_length: 1.0,
|
||||
sp_a: 20.0,
|
||||
sp_alpha: 1.0,
|
||||
sp_alpha: 0.602,
|
||||
scales: Some(scales),
|
||||
..Default::default()
|
||||
};
|
||||
@@ -418,7 +422,7 @@ impl<D: Dimension> Registration<D> {
|
||||
}
|
||||
|
||||
let bf = BSpline::<0, _>::new(f.view());
|
||||
let bm = BSpline::<1, _>::new(m.view());
|
||||
let bm = BSpline::<3, _>::new(m.view());
|
||||
let n_samples = match &samples {
|
||||
SamplingArg::Fixed(n) => *n,
|
||||
SamplingArg::Random(n) => *n,
|
||||
@@ -449,7 +453,7 @@ impl<D: Dimension> Registration<D> {
|
||||
tolerance,
|
||||
maximum_step_length: 1.0,
|
||||
sp_a: 20.0,
|
||||
sp_alpha: 1.0,
|
||||
sp_alpha: 0.602,
|
||||
scales: Some(scales),
|
||||
..Default::default()
|
||||
};
|
||||
|
||||
Reference in new issue
Block a user