2014-09-29 64 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方法的參數來設定所需的元素的位置。