Blender  V3.3
sample_test.cc
Go to the documentation of this file.
1 // Copyright (c) 2007, 2008 libmv authors.
2 //
3 // Permission is hereby granted, free of charge, to any person obtaining a copy
4 // of this software and associated documentation files (the "Software"), to
5 // deal in the Software without restriction, including without limitation the
6 // rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
7 // sell copies of the Software, and to permit persons to whom the Software is
8 // furnished to do so, subject to the following conditions:
9 //
10 // The above copyright notice and this permission notice shall be included in
11 // all copies or substantial portions of the Software.
12 //
13 // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14 // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15 // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16 // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17 // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
18 // FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
19 // IN THE SOFTWARE.
20 
21 #include "libmv/image/sample.h"
22 #include "testing/testing.h"
23 
24 using namespace libmv;
25 
26 namespace {
27 
28 TEST(Image, Nearest) {
29  Array3Du image(2, 2);
30  image(0, 0) = 0;
31  image(0, 1) = 1;
32  image(1, 0) = 2;
33  image(1, 1) = 3;
34  EXPECT_EQ(0, SampleNearest(image, -0.4f, -0.4f));
35  EXPECT_EQ(0, SampleNearest(image, 0.4f, 0.4f));
36  EXPECT_EQ(3, SampleNearest(image, 0.6f, 0.6f));
37  EXPECT_EQ(3, SampleNearest(image, 1.4f, 1.4f));
38 }
39 
40 TEST(Image, Linear) {
41  Array3Df image(2, 2);
42  image(0, 0) = 0;
43  image(0, 1) = 1;
44  image(1, 0) = 2;
45  image(1, 1) = 3;
46  EXPECT_EQ(1.5, SampleLinear(image, 0.5, 0.5));
47 }
48 
49 TEST(Image, DownsampleBy2) {
50  Array3Df image(2, 2);
51  image(0, 0) = 0;
52  image(0, 1) = 1;
53  image(1, 0) = 2;
54  image(1, 1) = 3;
55  Array3Df resampled_image;
56  DownsampleChannelsBy2(image, &resampled_image);
57  ASSERT_EQ(1, resampled_image.Height());
58  ASSERT_EQ(1, resampled_image.Width());
59  ASSERT_EQ(1, resampled_image.Depth());
60  EXPECT_FLOAT_EQ(6. / 4., resampled_image(0, 0));
61 }
62 
63 TEST(Image, DownsampleBy2MultiChannel) {
64  Array3Df image(2, 2, 3);
65  image(0, 0, 0) = 0;
66  image(0, 1, 0) = 1;
67  image(1, 0, 0) = 2;
68  image(1, 1, 0) = 3;
69 
70  image(0, 0, 1) = 5;
71  image(0, 1, 1) = 6;
72  image(1, 0, 1) = 7;
73  image(1, 1, 1) = 8;
74 
75  image(0, 0, 2) = 9;
76  image(0, 1, 2) = 10;
77  image(1, 0, 2) = 11;
78  image(1, 1, 2) = 12;
79 
80  Array3Df resampled_image;
81  DownsampleChannelsBy2(image, &resampled_image);
82  ASSERT_EQ(1, resampled_image.Height());
83  ASSERT_EQ(1, resampled_image.Width());
84  ASSERT_EQ(3, resampled_image.Depth());
85  EXPECT_FLOAT_EQ((0 + 1 + 2 + 3) / 4., resampled_image(0, 0, 0));
86  EXPECT_FLOAT_EQ((5 + 6 + 7 + 8) / 4., resampled_image(0, 0, 1));
87  EXPECT_FLOAT_EQ((9 + 10 + 11 + 12) / 4., resampled_image(0, 0, 2));
88 }
89 } // namespace
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
3D array (row, column, channel).
Definition: array_nd.h:325
int Depth() const
Definition: array_nd.h:340
int Height() const
Definition: array_nd.h:338
int Width() const
Definition: array_nd.h:339
depth_tx normal_tx diffuse_light_tx specular_light_tx volume_light_tx environment_tx ambient_occlusion_tx aov_value_tx in_weight_img image(1, GPU_R32F, Qualifier::WRITE, ImageType::FLOAT_2D_ARRAY, "out_weight_img") .image(3
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
T SampleNearest(const Array3D< T > &image, float y, float x, int v=0)
Nearest neighbor interpolation.
T SampleLinear(const Array3D< T > &image, float y, float x, int v=0)
Linear interpolation.
void DownsampleChannelsBy2(const Array3Df &in, Array3Df *out)