axtimwalde/mpicbg

Erroneous fitting of AffineModel3D

Closed this issue · 2 comments

Using the Groovy script below, I get a worsening in the z distances between paired sets of 3D points after fitting an affine model to the points. Please see also this forum discussion for more explanations.

import mpicbg.models.AffineModel3D;

a= [[15.434072, 118.46311,  10.952252],
[23.95161,  189.82367,  10.95459],
[40.960674, 399.33954,  11.08748],
[43.76619,  150.31279,  11.009996],
[67.97006,  464.56473,  11.146028],
[89.45972,  420.82678,  11.108215],
[105.28226, 252.01321,  11.045548],
[109.44038, 427.18225,  11.092786],
[113.30713, 229.50784,  10.992185],
[128.27286, 459.59274,  11.145987],
[132.80798, 405.80847,  11.114774],
[144.65749, 298.88016,  10.997809],
[150.35008, 40.110073,  10.84678],
[165.03986, 342.00388,  11.039748],
[194.90036, 384.04898,  11.049682],
[289.29044, 462.5165,   11.085374],
[295.09573, 452.19348,  11.074145],
[325.4797,  413.4804,   11.028268],
[358.28165, 466.71954,  11.04538],
[381.8618,  100.59195,  10.840279],
[388.5433,  490.98703,  11.147079],
[398.84198, 323.97894,  10.9963],
[419.34824, 98.5917,    10.797312],
[437.37817, 293.4611,   10.886358],
[454.27036, 488.56296,  11.074659],
[492.7722,  89.76044,   10.838887]];

//println(a);

b = [[14.861066,    119.465096, 11.229203],
[23.153625, 190.55356,  11.325839],
[39.960358, 400.47815,  11.571323],
[42.946514, 151.00925,  11.269929],
[67.094986, 465.64297,  11.6274395],
[88.742325, 421.832,    11.574621],
[104.649506,    253.10426,  11.303434],
[108.3977,  428.46942,  11.539685],
[112.60796, 230.27635,  11.358875],
[127.60289, 460.66956,  11.609537],
[132.10135, 406.78476,  11.543575],
[143.98784, 299.7424,   11.344606],
[150.05653, 40.651775,  11.142687],
[164.54166, 343.27408,  11.38195],
[194.5087,  385.09262,  11.461491],
[288.96295, 464.2268,   11.511548],
[294.7023,  453.58936,  11.509766],
[324.9036,  415.1506,   11.439083],
[358.2236,  468.41248,  11.535271],
[381.70197, 101.64196,  11.174496],
[388.29242, 492.62183,  11.5207815],
[398.53986, 325.3781,   11.397941],
[419.23538, 99.69395,   11.1963625],
[437.44797, 294.90387,  11.284115],
[454.7347,  490.30087,  11.491287],
[492.82825, 90.981766,  11.147794]];

//println(b);

c = [1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1,  1, 1, 1, 1, 1, 1]

model = new AffineModel3D();
model.fit((double[][])a.transpose(), (double[][])b.transpose(), (double[])c);

println(model);

for (e in b) {
    println(model.applyInverse((double[]) e));
}

@imagejan Sorry for the late reply. At first glance this looks like an ill-shaped problem. All z-corrdinates are more or less in the same plane +-noise. I assume that Matlab (as you point out in the related forum post) has some mechanism to treat such a situation differently. AffineModel3D implements only the most direct way to invert the matrix. Before digging into this: Do you think that your data carries any information about z? If that is not the case, then you should use an AffineModel2D.

@imagejan I think we concluded in http://forum.imagej.net/t/incorrect-calculation-of-affine-transformation-in-descriptor-based-registration-plugin/455/11 that this is a precision artifact when facing almost coplanar data. Can be fixed by exploring the data more but would cost more time in the non-coplanar (typical) case. So I leave it for now.