I am currently reading this book. The author wrote a code snippet on page 83 in order to (if i understand it correctly) calculate the element-wise power of two matrices. But i think the code doesn't fulfill its purpose because the matrix dst
does not contain the element-wise power after the execution.
Here is the original code:
const Mat* arrays[] = { src1, src2, dst, 0 };
float* ptrs[3];
NAryMatIterator it(arrays, (uchar**)ptrs);
for( size_t i = 0; i < it.nplanes; i++, ++it )
{
for( size_t j = 0; j < it.size; j++ )
{
ptrs[2][j] = std::pow(ptrs[0][j], ptrs[1][j]);
}
}
Since the parameter of the constructor or cv::NAryMatIterator
is const cv::Mat **
, i think change of values in the matrix dst
is not allowed.
I tried to assign ptrs[2][j]
back in dst
but failed to get the correct indices of dst
. My questions are as follows:
- Is there a convenient method for the matrix element-wise power, like
A .^ B
in Matlab? - Is there a way to use
cv::NAryMatIterator
to achieve this goal? If no, then what is the most efficient way to implement it?