Reputation: 11
I'm a novice in openCV and here goes my first doubt about matrix dimension subjects.
I am computing the Histogram of a colored image by means of the function cv::calcHist(..).
The resulting matrix is, as I expected, a 3D matrix. I guess the third dimension means the color for each RGB color channel but I don't know how to access them. After computing it, I have a matrix of 3 dimensions and 1 channel, and I'd like to be able to access each single dimension.
I think split function can't help here since it only splits a matrix into its channels.
Debugging I obtain the following relevant info from the 3Dhistrogram matrix:
Dimensions: 3, Rows: -1, Columns: -1, Size: 256
I know I can obtain the individual color histogram by splitting first the image into the 3 channels and computing the 1D histogram of each one afterwards but I'm curious about knowing how work the dimensions in openCV.
Thanks in advance!
Upvotes: 1
Views: 389
Reputation: 10852
Here is from Opencv's reference on MatND class:
// 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;
So, you can use array of 3 elements as an argument of .at method to set required element position.
Upvotes: 0