-
Notifications
You must be signed in to change notification settings - Fork 53
/
warp.cpp
124 lines (89 loc) · 3.3 KB
/
warp.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
/**
This file is part of Image Alignment.
Copyright Christoph Heindl 2015
Image Alignment is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
Image Alignment is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Image Alignment. If not, see <http://www.gnu.org/licenses/>.
*/
#define CATCH_CONFIG_MAIN
#include "catch.hpp"
#include <imagealign/warp.h>
TEST_CASE("warp-translational")
{
namespace ia = imagealign;
typedef ia::WarpTranslationF W;
W w;
w.setIdentity();
REQUIRE(w.parameters()(0,0) == 0.f);
REQUIRE(w.parameters()(1,0) == 0.f);
REQUIRE(w.numParameters() == 2);
W::Traits::ParamType p;
p(0,0) = 10.f;
p(1,0) = 5.f;
w.setParameters(p);
W::Traits::PointType x(5.f, 5.f);
W::Traits::PointType wx = w(x);
REQUIRE(wx(0) == 15.f);
REQUIRE(wx(1) == 10.f);
cv::Matx<float, 2, 2> j;
j << 1, 0, 0, 1;
REQUIRE(cv::norm(w.jacobian(W::Traits::PointType(10,10)) - j) == Catch::Detail::Approx(0));
}
TEST_CASE("warp-euclidean")
{
namespace ia = imagealign;
typedef ia::WarpEuclideanF W;
W w;
w.setIdentity();
REQUIRE(w.parameters()(0,0) == 0.f);
REQUIRE(w.parameters()(1,0) == 0.f);
REQUIRE(w.parameters()(2,0) == 0.f);
REQUIRE(w.numParameters() == 3);
W::Traits::ParamType p;
p(0,0) = 5.f;
p(1,0) = 5.f;
p(2,0) = 3.1415f;
w.setParameters(p);
W::Traits::PointType x(0.f, 0.f);
W::Traits::PointType wx = w(x);
REQUIRE(wx(0) == 5.f);
REQUIRE(wx(1) == 5.f);
x = W::Traits::PointType(10.f, 15.f);
wx = w(x);
REQUIRE(wx(0) == Catch::Detail::Approx(-10.f + 5.f).epsilon(0.01));
REQUIRE(wx(1) == Catch::Detail::Approx(-15.f + 5.f).epsilon(0.01));
}
TEST_CASE("warp-similarity")
{
namespace ia = imagealign;
typedef ia::WarpSimilarityF W;
W w;
w.setIdentity();
REQUIRE(w.parameters()(0,0) == 0.f);
REQUIRE(w.parameters()(1,0) == 0.f);
REQUIRE(w.parameters()(2,0) == 0.f);
REQUIRE(w.parameters()(3,0) == 0.f);
REQUIRE(w.numParameters() == 4);
w.setParametersInCanonicalRepresentation(W::Traits::ParamType(5.f, 5.f, 1.7f, 2.0f));
W::Traits::ParamType pr = w.parametersInCanonicalRepresentation();
REQUIRE(pr(0,0) == Catch::Detail::Approx(5));
REQUIRE(pr(1,0) == Catch::Detail::Approx(5));
REQUIRE(pr(2,0) == Catch::Detail::Approx(1.7));
REQUIRE(pr(3,0) == Catch::Detail::Approx(2));
w.setParametersInCanonicalRepresentation(W::Traits::ParamType(5.f, 5.f, 3.1415f, 2.f));
W::Traits::PointType x(0.f, 0.f);
W::Traits::PointType wx = w(x);
REQUIRE(wx(0) == 5.f);
REQUIRE(wx(1) == 5.f);
x = W::Traits::PointType(10.f, 15.f);
wx = w(x);
REQUIRE(wx(0) == Catch::Detail::Approx(-20.f + 5.f).epsilon(0.01));
REQUIRE(wx(1) == Catch::Detail::Approx(-30.f + 5.f).epsilon(0.01));
}