Using Eigen Array-of-Arrays for RGB images

前端 未结 3 776
耶瑟儿~
耶瑟儿~ 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.

提交回复
热议问题