Using Eigen Array-of-Arrays for RGB images

前端 未结 3 751
耶瑟儿~
耶瑟儿~ 2021-01-05 05:47

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, an

相关标签:
3条回答
  • 2021-01-05 06:07

    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.

    0 讨论(0)
  • 2021-01-05 06:10

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

    0 讨论(0)
  • 2021-01-05 06:13

    I think Eigen was not meant to be used in this way (with vectors as "scalar" types). I don't know what causes some of the expressions to compile, but for the ones that don't, it's because Eigen sees a + operation on two Arrays, with the left Array's scalar = Array3f, right Array's scalar = float and flags it incompatible.

    0 讨论(0)
提交回复
热议问题