Blender  V3.3
convolve_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 <iostream>
22 
23 #include "libmv/image/convolve.h"
24 #include "libmv/image/image.h"
25 #include "libmv/numeric/numeric.h"
26 #include "testing/testing.h"
27 
28 using namespace libmv;
29 
30 namespace {
31 
33  Vec kernel, derivative;
34  ComputeGaussianKernel(1, &kernel, &derivative);
35  EXPECT_EQ(7, kernel.size());
36  // TODO(keir): Put in a more thorough test here!
37 }
38 
40  FloatImage im(10, 10);
41  im.Fill(1);
42  FloatImage blured;
43  ConvolveGaussian(im, 3, &blured);
44  EXPECT_NEAR(im(5, 5), 1, 1e-7);
45 }
46 
48  FloatImage im(10, 10), convolved, filtered;
49  im.Fill(1);
50  BoxFilterHorizontal(im, 3, &filtered);
51  Vec kernel(3);
52  kernel.setConstant(1.);
53  ConvolveHorizontal(im, kernel, &convolved);
54  EXPECT_EQ(filtered(5, 5), 3);
55  EXPECT_TRUE(filtered == convolved);
56 }
57 
59  FloatImage image(5, 5), filtered;
60  // A single 1.0 inside a 5x5 image should expand to a 3x3 square.
61  image.Fill(0);
62  image(2, 2) = 1.0;
63  BoxFilter(image, 3, &filtered);
64  for (int j = 0; j < 5; j++) {
65  for (int i = 0; i < 5; i++) {
66  if (i == 0 || i == 4 || j == 0 || j == 4) {
67  EXPECT_EQ(0.0, filtered(j, i));
68  } else {
69  EXPECT_EQ(1.0, filtered(j, i));
70  }
71  }
72  }
73 }
74 
75 TEST(Convolve, BlurredImageAndDerivativesChannelsFlat) {
76  FloatImage im(10, 10), blurred_and_derivatives;
77  im.Fill(1);
78  BlurredImageAndDerivativesChannels(im, 1.0, &blurred_and_derivatives);
79  EXPECT_NEAR(blurred_and_derivatives(5, 5, 0), 1.0, 1e-7);
80  EXPECT_NEAR(blurred_and_derivatives(5, 5, 1), 0.0, 1e-7);
81  EXPECT_NEAR(blurred_and_derivatives(5, 5, 2), 0.0, 1e-7);
82 }
83 
84 TEST(Convolve, BlurredImageAndDerivativesChannelsHorizontalSlope) {
85  FloatImage image(10, 10), blurred_and_derivatives;
86  for (int j = 0; j < 10; ++j) {
87  for (int i = 0; i < 10; ++i) {
88  image(j, i) = 2 * i;
89  }
90  }
91  BlurredImageAndDerivativesChannels(image, 0.9, &blurred_and_derivatives);
92  EXPECT_NEAR(blurred_and_derivatives(5, 5, 0), 10.0, 1e-7);
93  EXPECT_NEAR(blurred_and_derivatives(5, 5, 1), 2.0, 1e-7);
94  EXPECT_NEAR(blurred_and_derivatives(5, 5, 2), 0.0, 1e-7);
95 }
96 
97 TEST(Convolve, BlurredImageAndDerivativesChannelsVerticalSlope) {
98  FloatImage image(10, 10), blurred_and_derivatives;
99  for (int j = 0; j < 10; ++j) {
100  for (int i = 0; i < 10; ++i) {
101  image(j, i) = 2 * j;
102  }
103  }
104  BlurredImageAndDerivativesChannels(image, 0.9, &blurred_and_derivatives);
105  EXPECT_NEAR(blurred_and_derivatives(5, 5, 0), 10.0, 1e-7);
106  EXPECT_NEAR(blurred_and_derivatives(5, 5, 1), 0.0, 1e-7);
107  EXPECT_NEAR(blurred_and_derivatives(5, 5, 2), 2.0, 1e-7);
108 }
109 
110 } // namespace
EXPECT_EQ(BLI_expr_pylike_eval(expr, nullptr, 0, &result), EXPR_PYLIKE_INVALID)
ATTR_WARN_UNUSED_RESULT const BMVert const BMEdge * e
3D array (row, column, channel).
Definition: array_nd.h:325
void Fill(T value)
Definition: array_nd.h:152
SyclQueue void void size_t num_bytes SyclQueue void const char void *memory_device_pointer KernelContext int kernel
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
Eigen::VectorXd Vec
Definition: numeric.h:61
void ConvolveHorizontal(const Array3Df &in, const Vec &kernel, Array3Df *out_pointer, int plane)
Definition: convolve.cc:168
TEST(PolynomialCameraIntrinsics2, ApplyOnFocalCenter)
void BoxFilterHorizontal(const Array3Df &in, int window_size, Array3Df *out_pointer)
Definition: convolve.cc:255
void BlurredImageAndDerivativesChannels(const Array3Df &in, double sigma, Array3Df *blurred_and_gradxy)
Definition: convolve.cc:233
void ConvolveGaussian(const Array3Df &in, double sigma, Array3Df *out_pointer)
Definition: convolve.cc:182
void Convolve(const Array3Df &in, const Vec &kernel, Array3Df *out_pointer, int plane)
Definition: convolve.cc:102
void ComputeGaussianKernel(double sigma, Vec *kernel, Vec *derivative)
Definition: convolve.cc:32
void BoxFilter(const Array3Df &in, int box_width, Array3Df *out)
Definition: convolve.cc:323