gadomski / cpd

C++ implementation of the Coherent Point Drift point set registration algorithm.
http://www.gadom.ski/cpd
GNU General Public License v2.0
400 stars 124 forks source link

Unable to obtain the Translation Vector with Rigid and Affine Transformation #65

Closed aanwark closed 8 years ago

aanwark commented 8 years ago

Hi Pete,

First of all thank you for your wonderful effort. I was impressed by Andriy's work and wanted to implement it in C++ but luckily I found your work. I have tried to use your code in order to obtain affine transformation between two point sets. However, I found one problem, after obtaining the Rotation matrix from the C++ implementation (which is quite similar to Matlab's version of Rotation Matrix), I am not able to obtain the translation vector. The C++ implementation gives a 4x4 matrix which should contain the translation vector in the last column (first three values), however I only get zeros there. While on Matlab, I am successfully able to extract the translation vector. Perhaps it may be due to a bug in affine.cpp lines 63 to 76. I am not sure about it, therefore need your advice. I am sharing my results from C++ as well as Matlab implementations as under:

C++: 0.4128260.6724760.01615030 -0.8109320.499356-0.03642180 0.0255316-0.02015811.08613_0 0___-0____0____0

MATLAB:

0.41450.67000.0225-0.0068 -0.80700.4973-0.03220.0282 0.0506-0.03821.0859_-0.3342 0___0__0___1

Thanks.

gadomski commented 8 years ago

@denoza thank you for the report! You're absolutely right that the translation vectors were not provided. I've amended that omission in a new branch, issues/65-translation (PR #66). If you'd be willing to check out that branch and verify that you're able to get the needed translation vector, I would be much obliged.

One note, the rotation matrix from this C++ library should be D x D — i.e. if you have three-dimensional points, the rotation matrix should be a 3x3. If you're seeing something different, can you let me know? That would be a different issue.

gadomski commented 8 years ago

@denoza I've merged this fix into master. If something isn't right, please feel free to re-open this issue.

aanwark commented 8 years ago

Hi Pete, Thank you for your fix. I checked the new branch and the code does provide the translation vector as well as scaling factor now. However, the Rotation Matrix should be 3x3 in my case, however it shows 4x4, while translation vector should be 3x1 while I get 4x1. I am sharing my output as under,

Rotation (Just like mentioned before in my first comment): 0.4128260.6724760.01615030 -0.8109320.499356-0.03642180 0.0255316-0.02015811.08613_0 0___-0____0____0

Translation: -0.0129799 0.0213095 -0.35583 0

gadomski commented 8 years ago

@denoza are you sure your input matrices only have three columns? I just ran a quick little test locally and was not able to replicate your issue. For reference, here's the test code I used:

#include <cpd/rigid.hpp>

int main(int argc, char** argv) {
    cpd::Matrix X(5, 2);
    X << 0, 0, 1, 0, 2, 0, 0, 1, 0, 2;
    cpd::Matrix Y(5, 2);
    Y << 1, 1, 2, 1, 3, 1, 1, 2, 1, 3;
    auto result = cpd::rigid(X, Y);
    std::cout << "Rotation matrix: \n" << result.rotation << "\n";
    std::cout << "Translation matrix: \n" << result.translation << "\n";
    return 0;
}

Compile and run to see the output matrices (you'll have to change paths for your system):

g++ build/dimensions.cpp -o build/dimensions -I/Users/gadomski/local/include -I/usr/local/include/eigen3 -std=c++11 -lcpd -lfgt -L/Users/gadomski/local/lib && build/dimensions

I see output that looks like:

Rotation matrix: 1 1.11022e-16 3.33067e-16 1 Translation matrix: -1 -1

2x2 rotation matrix, 2x1 translation vector.

aanwark commented 8 years ago

Hi Pete, You are right, actually I checked again to find out that my function which I wrote to read the .txt file into Eigen::MatrixXd had a bug. The code has no problem.

gadomski commented 8 years ago

Great, glad it's working ok.

On Tue, May 10, 2016 at 2:39 AM, denoza notifications@github.com wrote:

Hi Pete, You are right, actually I checked again to find out that my function which I wrote to read the .txt file into Eigen::MatrixXd had a bug. The code has no problem.

— You are receiving this because you modified the open/close state. Reply to this email directly or view it on GitHub https://github.com/gadomski/cpd/issues/65#issuecomment-218094051

Peter Gadomski Physical Scientist Cold Regions Research & Engineering Lab pete.gadomski@gmail.com 530.440.4630