对RGB图像使用特征数组阵列 [英] Using Eigen Array-of-Arrays for RGB images

查看:131
本文介绍了对RGB图像使用特征数组阵列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图使用Eigen库进行一些简单的图像处理。我将使用Array3f的RGB三元组和一个数组来保存一个RGB图像。这似乎部分工作,我可以方便地做图像的分量加法,乘法和除法。但某些操作(特别涉及减法或否定)似乎会产生编译错误。这里是一个最小示例:

  #include< Eigen / Core& 

使用命名空间Eigen;

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

//所有以下应该有相同的数学效果

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)); //这不编译
MyArray d = m - Array3f(5.0f); //这不编译
}

上面的代码给我三个错误: / p>

  ./艾根/ src目录/核心/ CwiseBinaryOp.h:128:7:错误:没有成员命名为
'YOU_MIXED_DIFFERENT_NUMERIC_TYPES__YOU_NEED_TO_USE_THE_CAST_METHOD_OF_MATRIXBASE_TO_CAST_NUMERIC_TYPES_EXPLICITLY 在
'征::内部:: static_assertion<假>'
EIGEN_CHECK_BINARY_COMPATIBILIY(BinaryOp,类型名LHS ::标量,类型名右轴::标量);
...

./Eigen/src/Core/CwiseBinaryOp.h:187:14:错误:没有匹配函数呼叫类型为const
本征的'对象: :internal :: scalar_sum_op< Eigen :: Array< float,3,1,0,3,1> >'
return derived()。functor()(derived()。lhs()。coeff(index),
...

./Eigen/src/核心/../插件/ ArrayCwiseBinaryOps.h:208:10:错误:从'常量
CwiseBinaryOp<没有可行的转换;内部:: scalar_sum_op<标量>中常量征::阵列<本征::阵列<浮动, 3,1,0,3,1>中-1,-1,0,-1,-1>中常量
征:: CwiseUnaryOp&所述;本征::内部:: scalar_opposite_op&所述漂浮>中常量征: :数组<浮球,3,1,0,3,1>>>'到'常量
CwiseUnaryOp<内部:: scalar_add_op<标量>中常量征::阵列<本征::阵列<浮动, 3,1,0,3,1,-1,-1,0,-1,-1>'
return * this +(-scalar);
...


解决方案

在万一有人有兴趣:上面的例子编译并运行良好艾根与3.3rc1(因为艾根最有可能的事情3.3-α是罚款以及)。



我仍然认为这个功能作为实验,因为它既不证明,也不部分测试套件(据我所知)。


I'm trying to use the Eigen library for some simple image processing. I'd use Array3f for an RGB triple and an Array to hold an RGB image. This seems to work partially, and I can conveniently do component-wise addition, multiplication and division of images. But certain operations (specifically involving subtraction or negation) seem to create compile errors. Here is a minimal example:

#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
}

The above code gives me three errors:

./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);
...

解决方案

In case someone is interested: The above example compiles and runs fine with Eigen 3.3rc1 (most likely anything since Eigen 3.3-alpha is fine as well).

I would still consider this feature as experimental, since it is neither documented, nor part of the test suite (as far as I see).

这篇关于对RGB图像使用特征数组阵列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆