使用本征阵列-的阵列的RGB图像 [英] Using Eigen Array-of-Arrays for RGB images

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

问题描述

我试图使用本征库进行一些简单的图像处理。我会使用Array3f用于RGB三人间和一个数组来保存RGB图像。这似乎部分工作,我可以方便做组件明智的加法,乘法和图像的分工。但是,某些操作(特别是涉及到减法或否定)似乎创建编译错误。下面是一个小例子:

 的#include<艾根/酷睿>使用本征空间;INT主要(无效)
{
    typedef的数组< Array3f,动态,动态> MYARRAY;
    MYARRAY米(2,2);    //以下所有应具有相同的数学效果    Array3f V = -Array3f(5.0F); //这个编译    MYARRAY一个= M + V; //这个编译
    MYARRAY B = M + Array3f(-5.0f); //这个编译
    MYARRAY C = M +(-Array3f(5.0F)); //这不会编译
    MYARRAY D =米 - Array3f(5.0F); //这不会编译
}

以上code给我三个错误:

  ./艾根/ 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:错误:呼叫没有匹配的功能类型的对象'常量
      本征::内部:: scalar_sum_op<本征::阵列<浮球,3,1,0,3,1> >'
      返回导出()。仿函数()(来源()。LHS()。COEFF(指数),
..../Eigen/src/Core/../plugins/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> >'
  返回*本+(-scalar);
...


解决方案

的问题是,艾根用懒惰的评价和( - Array3f(5.0F))是实际上一个前pression,而不是一个数组。我不知道到底发生了什么失败,我没有足够的时间来看看它现在。我继续之前,我不得不说,有是 Array3f(浮点)没有有效的构造,并会继续答案 Array3f(5.0F,4.0F ,3.1F)代替。

简单快速和容易的黑客会迫使否定阵列的评价,并使用 + 操作。不理想的原因很多,但

  MYARRAY C = M +(-Array3f(5.0F,4.0F,3.1F))的eval()。

工作。优点:快速实施。缺点:没有懒惰的评价,因为的eval()将创建一个新的否定数组。也使得code更恶心。

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

解决方案

The problem is that Eigen is using lazy evaluation and that (-Array3f(5.0f)) is actually an expression and not an array. I'm not sure exactly what's failing and I don't have enough time to look into it right now. Before I continue, I have to say that there is no valid constructor for Array3f(float) and will continue the answer Array3f(5.0f, 4.0f, 3.1f) instead.

The simple fast and easy hack would be to force evaluation of the negated array and use a + operation. Not ideal for many reasons, but

MyArray c = m + (-Array3f(5.0f, 4.0f, 3.1f)).eval();

works. Advantage: quickly implemented. Disadvantage: no lazy evaluation, as the eval() will create a new negated array. Also makes the code much uglier.

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

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