-
Notifications
You must be signed in to change notification settings - Fork 53
/
sampling.cpp
77 lines (56 loc) · 2.25 KB
/
sampling.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
/**
This file is part of Active Appearance Models (AMM).
Copyright Christoph Heindl 2015
Copyright Sebastian Zambal 2015
AMM 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.
AMM 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 AMM. If not, see <http://www.gnu.org/licenses/>.
*/
#include "catch.hpp"
#include <imagealign/sampling.h>
TEST_CASE("sampling-bilinear")
{
namespace ia = imagealign;
ia::Sampler<ia::SAMPLE_BILINEAR> s;
cv::Mat img(2, 2, CV_8UC1);
img.at<uchar>(0,0) = 0;
img.at<uchar>(0,1) = 64;
img.at<uchar>(1,0) = 128;
img.at<uchar>(1,1) = 192;
typedef cv::Matx<double, 2, 1> PointType;
// Pixel centers
REQUIRE(s.sample<uchar>(img, PointType(0.0, 0.0)) == 0);
REQUIRE(s.sample<uchar>(img, PointType(0.0, 1.0)) == 128);
REQUIRE(s.sample<uchar>(img, PointType(1.0, 0.0)) == 64);
REQUIRE(s.sample<uchar>(img, PointType(1.0, 1.0)) == 192);
// Off-centers
REQUIRE(s.sample<uchar>(img, PointType(0.5, 0.0)) == 32);
REQUIRE(s.sample<uchar>(img, PointType(0.5, 0.5)) == 96);
}
TEST_CASE("sampling-nearest")
{
namespace ia = imagealign;
ia::Sampler<ia::SAMPLE_NEAREST> s;
cv::Mat img(2, 2, CV_8UC1);
img.at<uchar>(0,0) = 0;
img.at<uchar>(0,1) = 64;
img.at<uchar>(1,0) = 128;
img.at<uchar>(1,1) = 192;
typedef cv::Matx<double, 2, 1> PointType;
// Pixel centers
REQUIRE(s.sample<uchar>(img, PointType(0.0, 0.0)) == 0);
REQUIRE(s.sample<uchar>(img, PointType(0.0, 1.0)) == 128);
REQUIRE(s.sample<uchar>(img, PointType(1.0, 0.0)) == 64);
REQUIRE(s.sample<uchar>(img, PointType(1.0, 1.0)) == 192);
// Off-centers
REQUIRE(s.sample<uchar>(img, PointType(0.5, 0.0)) == 0);
REQUIRE(s.sample<uchar>(img, PointType(0.5, 0.5)) == 0);
REQUIRE(s.sample<uchar>(img, PointType(1.1, 0.0)) == 64);
}