C++ OpenCV max/argmax for 3D matrix

Viewed 51

I have a three-dimensional intensity volume of size 256 x 256 x 256 and I want to perform an max/argmax operation, i.e., I want to estimate the maximum in the third dimension and the corresponding index using OpenCV in C++.

What is the fastest way to perform these operations?

#include <opencv2/opencv.hpp>
#include <opencv2/core/core.hpp>

void maxArgMax(const cv::Mat &volIn, cv::mat &imMagOut, cv::Mat &imIdxOut)
{
    // what to do here?
}

int main()
{
    int dims[] = { 256, 256, 256 };
    cv::Mat vol(3, dims, CV_32FC1);

    cv::Mat imMag(dims[0], dims[1], CV_32FC1, vol.at<float>(0)); // this should include the max. magnitude
    cv::Mat imIdx(dims[0], dims[1], CV_8UC1); // this should include the corresponding index

    maxArgMax(vol, imMag, imIdx);

    return 0;
}
0 Answers
Related