operations on arrays: more cv::Mat return signatures (Feature #2305)


Added by Hilton Bristow over 12 years ago. Updated over 9 years ago.


Status:Open Start date:2012-08-25
Priority:Normal Due date:
Assignee:Vadim Pisarevsky % Done:

0%

Category:core
Target version:3.0
Difficulty: Pull request:

Description

I would like to request more Mat/MatExpr return signatures for elementwise operations on arrays, including:

Mat exp(const Mat& src);
Mat pow(const Mat& src, float exp);
Mat sqrt(const Mat& src);
Mat square(const Mat& src);
Mat log(const Mat& src);

That will make for more readable code when doing the following type of operations:
L = I - exp( diag(D) * log(W) );

Obviously this will trigger a lot of unnecessary memory allocations, so non-const (in-place) versions or versions that return MatExpr would be appreciated as well/instead.


History

Updated by Stefan R over 12 years ago

I can contribute the following:

cv::Mat mul(const cv::Mat& a, const cv::Mat& b)
{
    cv::Mat tmp;
    cv::multiply(a, b, tmp);
    return tmp;
}

cv::Mat pow(const cv::Mat& src, double power)
{
    cv::Mat tmp;
    if( power == 2.0 ){
        cv::multiply(src, src, tmp);
    } else {
        cv::pow(src, power, tmp);
    }    
    return tmp;
}

cv::Mat sqrt(const cv::Mat& src)
{
    cv::Mat tmp;
    cv::sqrt(src, tmp);
    return tmp;
}

Updated by Vadim Pisarevsky over 12 years ago

let's postpone it; the proposed "naive" implementation is very inefficient. Need to think how to do it properly.

  • Target version changed from 2.4.3 to 3.0

Updated by Leszek Swirski almost 12 years ago

Could it be an idea to embrace Eigen for such things? These are exactly the sorts of things that Eigen is good at doing efficiently.

Updated by Maksim Shabunin over 9 years ago

Issue has been transferred to GitHub: https://github.com/Itseez/opencv/issues/4415

Also available in: Atom PDF