如何将Argb32加载到Eigen Matrix中以获得最佳性能?

时间:2013-01-27 13:21:12

标签: c++ image-processing eigen

给定一个Int数组,一个Argb32图像,我怎样才能将其加载到Eigen Matrixes中?最好的方法是什么?

目标是创建一个小型图像处理库。而作为第一部分,我想从RGB转换为灰度。

有没有办法在不进行任何内存复制的情况下将int []加载到3个特征矩阵中?

(当引用eigen时,它的线性代数库)。

1 个答案:

答案 0 :(得分:3)

是的,使用Map<>具有适当内跨步的类,例如:

unsigned char* data = ...;
int w, h; // the width and height
typedef Map<Matrix<unsigned char,Dynamic,Dynamic>, 0, InnerStride<4> > Slide;
Slice red(data, w, h), green(data+1, w, h), blue(data+2, w, h);

然后你可以开始玩它们,例如,构建一个灰度级浮点版本:

MatrixXf gray = (red.cast<float>() * 11 + green.cast<float>() * 16 + blue.cast<float>() * 5)/(32.*255.);