Here is my code for a 2D matrix. I tested it.
cv::Mat Utilities::Sub2Ind(int width, int height, cv::Mat X, cv::Mat Y) { std::vector<int> index; cv::transpose(Y,Y); cv::MatConstIterator_<int> iterX = X.begin<int>(), it_endX = X.end<int>(); cv::MatConstIterator_<int> iterY = Y.begin<int>(), it_endY = Y.end<int>(); for (int j = 0; j < X.cols; ++j,++iterX) {
Gilad source share