2014-09-29 66 views
1

我是openCV中的新手,这是我对矩阵维度主题的第一个怀疑。颜色直方图中的访问维数openCV

我正在通过函数cv :: calcHist(..)来计算彩色图像的直方图。

正如我所料,得到的矩阵是一个3D矩阵。我猜第三维意味着每个RGB颜色通道的颜色,但我不知道如何访问它们。计算完成后,我有一个3维和1个通道的矩阵,我希望能够访问每个维度。

我觉得split函数在这里不能帮忙,因为它只是将矩阵分解到它的通道中。

调试我获得来自3Dhistrogram矩阵以下相关信息:

外形尺寸:3, 行:-1, 列:-1, 尺寸:256

我知道我可以通过将第一幅图像分成3个通道并计算每幅图像的一维直方图,获得单独的颜色直方图,但我很好奇知道如何在openCV中处理尺寸。

在此先感谢!

+0

你见过这个[教程](http://docs.opencv.org/doc/tutorials/imgproc/histograms/histogram_calculation/histogram_calculation.html)吗? – beaker 2014-09-29 16:47:01

+0

嗨,感谢您的回答,但是他们之前正在分割图像并按照我提到的计算个别直方图。 我正在处理由直接计算直方图产生的3维矩阵:彩色图像:c: 这更多的是关于如何处理这些尺寸(无通道)而不是直方图的问题。 – Pablo 2014-09-29 17:25:31

回答

0

这里是从opencv的对MatND类参考:

// return pointer to the element (versions for 1D, 2D, 3D and generic nD cases) 
    uchar* ptr(int i0); 
    const uchar* ptr(int i0) const; 
    uchar* ptr(int i0, int i1); 
    const uchar* ptr(int i0, int i1) const; 
    uchar* ptr(int i0, int i1, int i2); 
    const uchar* ptr(int i0, int i1, int i2) const; 
    uchar* ptr(const int* idx); 
    const uchar* ptr(const int* idx) const; 

    // convenient template methods for element access. 
    // note that _Tp must match the actual matrix type - 
    // the functions do not do any on-fly type conversion 
    template<typename _Tp> _Tp& at(int i0); 
    template<typename _Tp> const _Tp& at(int i0) const; 
    template<typename _Tp> _Tp& at(int i0, int i1); 
    template<typename _Tp> const _Tp& at(int i0, int i1) const; 
    template<typename _Tp> _Tp& at(int i0, int i1, int i2); 
    template<typename _Tp> const _Tp& at(int i0, int i1, int i2) const; 
    template<typename _Tp> _Tp& at(const int* idx); 
    template<typename _Tp> const _Tp& at(const int* idx) const; 

所以,可以使用3个元素的数组作为.AT方法的参数来设定所需的元素的位置。