21#ifndef LIBMV_IMAGE_SAMPLE_H_
22#define LIBMV_IMAGE_SAMPLE_H_
32 const int j = int(
round(
x));
33 return image(
i, j,
v);
37 const int ix =
static_cast<int>(
x);
42 }
else if (ix >
size - 2) {
62 const T im11 = image(y1, x1,
v);
63 const T im12 = image(y1, x2,
v);
64 const T im21 = image(y2, x1,
v);
65 const T im22 = image(y2, x2,
v);
67 return T(dy * (dx * im11 + (1.0 - dx) * im12) +
68 (1 - dy) * (dx * im21 + (1.0 - dx) * im22));
81 for (
int i = 0;
i < image.
Depth(); ++
i) {
82 const T im11 = image(y1, x1,
i);
83 const T im12 = image(y1, x2,
i);
84 const T im21 = image(y2, x1,
i);
85 const T im22 = image(y2, x2,
i);
87 sample[
i] =
T(dy * (dx * im11 + (1.0 - dx) * im12) +
88 (1 - dy) * (dx * im21 + (1.0 - dx) * im22));
96 int height =
in.Height() / 2;
97 int width =
in.Width() / 2;
98 int depth =
in.Depth();
100 out->Resize(height, width, depth);
103 for (
int r = 0; r < height; ++r) {
104 for (
int c = 0; c < width; ++c) {
105 for (
int k = 0; k < depth; ++k) {
107 (*out)(r, c, k) = (
in(2 * r, 2 * c, k) +
108 in(2 * r + 1, 2 * c, k) +
109 in(2 * r, 2 * c + 1, k) +
110 in(2 * r + 1, 2 * c + 1, k)) / 4.0f;
125 sampled->
Resize(2 * half_width + 1, 2 * half_width + 1, channels);
126 for (
int r = -half_width; r <= half_width; ++r) {
127 for (
int c = -half_width; c <= half_width; ++c) {
128 for (
int i = 0;
i < channels; ++
i) {
129 (*sampled)(r + half_width, c + half_width,
i) =
ATTR_WARN_UNUSED_RESULT const BMVert * v
static DBVT_INLINE btScalar size(const btDbvtVolume &a)
3D array (row, column, channel).
void Resize(int height, int width, int depth=1)
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.
Array3D< float > Array3Df
void DownsampleChannelsBy2(const Array3Df &in, Array3Df *out)
void LinearInitAxis(float x, int size, int *x1, int *x2, float *dx)
void SamplePattern(const FloatImage &image, double x, double y, int half_width, int channels, FloatImage *sampled)