24 #include <Eigen/Dense> 34 template<
typename Type>
40 void resize(
unsigned w,
unsigned h) {
43 m_data.resize(m_width * m_height);
54 const Type &
operator[](
unsigned idx)
const {
return m_data[idx]; }
57 Type &
operator()(
unsigned x,
unsigned y) {
return m_data[x + y * m_width]; }
59 const Type &
operator()(
unsigned x,
unsigned y)
const {
return m_data[x + y * m_width]; }
62 template<
typename OtherType,
class BinaryOp>
66 for (
unsigned i = 0; i < m_width*m_height; i++)
67 m_data[i] = op(m_data[i], rhs.m_data[i]);
72 template<
class UnaryOp>
74 for (
unsigned i = 0; i < m_width*m_height; i++)
75 m_data[i] = op(m_data[i]);
79 template<
typename OtherType>
81 return performBinaryOp(rhs, [](
const Type &a,
const OtherType &b)->Type {
return a-b; });
84 template<
typename OtherType>
86 return performBinaryOp(rhs, [](
const Type &a,
const OtherType &b)->Type {
return a+b; });
89 template<
typename OtherType>
91 return performBinaryOp(rhs, [](
const Type &a,
const OtherType &b)->Type {
return a*b; });
94 template<
typename OtherType>
96 return performBinaryOp(rhs, [](
const Type &a,
const OtherType &b)->Type {
return a/b; });
99 template<
typename OtherType>
101 return performUnaryOp([&factor](
const Type &a)->Type {
return a*factor; });
104 template<
typename OtherType>
106 return performUnaryOp([&factor](
const Type &a)->Type {
return a+factor; });
113 for (
unsigned y = 0; y < m_height; y++)
114 for (
unsigned x = 0; x < m_width; x++)
115 m_data[x + y * m_width] = other(x*stride, y*stride);
121 x = std::min(std::max(x - 0.5f, 0.0f), m_width - 1.001f);
122 y = std::min(std::max(y - 0.5f, 0.0f), m_height - 1.001f);
129 const Type &v00 = (*this)(ix+0, iy+0);
130 const Type &v01 = (*this)(ix+0, iy+1);
131 const Type &v10 = (*this)(ix+1, iy+0);
132 const Type &v11 = (*this)(ix+1, iy+1);
134 return (v00 * (1.0f - fracX) + v10 * fracX) * (1.0f - fracY) +
135 (v01 * (1.0f - fracX) + v11 * fracX) * fracY;
140 template <
typename scalarType>
142 x = std::min(std::max(x - 0.5f, 0.0f), m_width - 1.001f);
143 y = std::min(std::max(y - 0.5f, 0.0f), m_height - 1.001f);
150 const scalarType &v00 = (*this)(ix+0, iy+0)[channel];
151 const scalarType &v01 = (*this)(ix+0, iy+1)[channel];
152 const scalarType &v10 = (*this)(ix+1, iy+0)[channel];
153 const scalarType &v11 = (*this)(ix+1, iy+1)[channel];
155 return (v00 * (1.0f - fracX) + v10 * fracX) * (1.0f - fracY) +
156 (v01 * (1.0f - fracX) + v11 * fracX) * fracY;
160 std::swap(m_width, other.m_width);
161 std::swap(m_height, other.m_height);
162 std::swap(m_data, other.m_data);
165 unsigned m_width = 0;
166 unsigned m_height = 0;
167 std::vector<Type> m_data;
171 template<
typename Type>
174 Type totalSum = Type(0);
175 for (
unsigned y = 0; y < img.
getHeight(); y++) {
176 Type rowSum = Type(0);
177 for (
unsigned x = 0; x < img.
getWidth(); x++)
186 template<
typename Type,
typename KernelType>
190 for (
unsigned y = 0; y < src.
getHeight(); y++) {
191 for (
unsigned x = 0; x < src.
getWidth(); x++) {
192 Type sum = src(x, y) * kernel[0];
193 for (
unsigned i = 1; i < kernel.size(); i++) {
194 int x0 = std::max<int>(0, (int)x - (
int)i);
195 int x1 = std::min<int>(src.
getWidth()-1, (int)x + (
int)i);
197 sum += (src(x0, y) + src(x1, y)) * kernel[i];
206 template<
typename Type,
typename KernelType>
210 for (
unsigned y = 0; y < src.
getHeight(); y++) {
211 for (
unsigned x = 0; x < src.
getWidth(); x++) {
212 Type sum = src(x, y) * kernel[0];
213 for (
unsigned i = 1; i < kernel.size(); i++) {
214 int y0 = std::max<int>(0, (int)y - (
int)i);
215 int y1 = std::min<int>(src.
getHeight()-1, (int)y + (
int)i);
217 sum += (src(x, y0) + src(x, y1)) * kernel[i];
226 void normalizeFilterKernel(std::vector<float> &kernel);
228 void normalizeFilterKernelEnergy(std::vector<float> &kernel);
238 #endif // FLOATIMAGE_H Definition: CameraPathEvaluation.cpp:10