compare Mat element-wise

asked 2015-09-12 15:04:07 -0500

updated 2015-09-13 01:28:50 -0500

berak gravatar image

i want to compare element by element of 2 Mat s1,s2 and put smaller value in 3rd Mat salient. i have put Code below Build Succesfull but then still there is error

Mat downs,ups,s1,s2,m,salient;
s1 = ups / downs;
s2 = downs / ups;

    for (int i = 0; i < ups.cols; i++)
    {
        for (int j = 0; j < ups.rows; j++)
        {

            if (s1.at<uchar>(i, j) > s2.at<uchar>(i, j))
            {
                m.at<uchar>(i, j) = s2.at<uchar>(i, j);
            }
            else
            {
                m.at<uchar>(i, j) = s1.at<uchar>(i, j);
            }

            salient.at<uchar>(i, j) = 1 - m.at<uchar>(i, j);
        }
    }
edit retag flag offensive close merge delete

Comments

1

so, what error ? (btw, you got i,j in reverse. it's row,col in opencv, not x,y)

berak gravatar imageberak ( 2015-09-13 01:30:50 -0500 )edit
1

how about cv::min()? link. And be carful using salient.at<uchar>(i, j) = 1 - m.at<uchar>(i, j); because there is no saturation. Use cv::subtract() instead.

matman gravatar imagematman ( 2015-09-13 11:31:27 -0500 )edit

Mat salient = 255 - cv::min(r1,r2); even

(if you want to invert it, the max number is probably 255 for uchar).

imho, all those for loops are not nessecary.

berak gravatar imageberak ( 2015-09-13 11:46:19 -0500 )edit