对 RGB 图像使用特征数组数组

2023-11-25

我正在尝试使用 Eigen 库进行一些简单的图像处理。我将使用 Array3f 作为 RGB 三元组,并使用 Array 来保存 RGB 图像。这似乎部分有效,我可以方便地对图像进行组件式加法、乘法和除法。但某些操作(特别是涉及减法或求反)似乎会产生编译错误。这是一个最小的例子:

#include <Eigen/Core>

using namespace Eigen;

int main(void)
{
    typedef Array<Array3f, Dynamic, Dynamic> MyArray;
    MyArray m(2,2);

    // all of the following should have the same mathematical effect

    Array3f v = -Array3f(5.0f);             // this compiles

    MyArray a = m + v;                      // this compiles
    MyArray b = m + Array3f(-5.0f);         // this compiles
    MyArray c = m + (-Array3f(5.0f));       // this doesn't compile
    MyArray d = m - Array3f(5.0f);          // this doesn't compile
}

上面的代码给了我三个错误:

./Eigen/src/Core/CwiseBinaryOp.h:128:7: error: no member named
      'YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY' in
      'Eigen::internal::static_assertion<false>'
      EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,typename Lhs::Scalar,typename Rhs::Scalar);
...

./Eigen/src/Core/CwiseBinaryOp.h:187:14: error: no matching function for call to object of type 'const
      Eigen::internal::scalar_sum_op<Eigen::Array<float, 3, 1, 0, 3, 1> >'
      return derived().functor()(derived().lhs().coeff(index),
...

./Eigen/src/Core/../plugins/ArrayCwiseBinaryOps.h:208:10: error: no viable conversion from 'const
      CwiseBinaryOp<internal::scalar_sum_op<Scalar>, const Eigen::Array<Eigen::Array<float, 3, 1, 0, 3, 1>, -1, -1, 0, -1, -1>, const
      Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<float>, const Eigen::Array<float, 3, 1, 0, 3, 1> > >' to 'const
      CwiseUnaryOp<internal::scalar_add_op<Scalar>, const Eigen::Array<Eigen::Array<float, 3, 1, 0, 3, 1>, -1, -1, 0, -1, -1> >'
  return *this + (-scalar);
...

如果有人感兴趣:上面的示例可以在 Eigen 3.3rc1 上编译并运行良好(很可能自 Eigen 3.3-alpha 以来的任何东西都可以)。

我仍然认为此功能是实验性的,因为它既没有记录,也不是测试套件的一部分(据我所知)。

本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)

对 RGB 图像使用特征数组数组 的相关文章

随机推荐