compare Mat element-wise
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);
}
}
so, what error ? (btw, you got i,j in reverse. it's row,col in opencv, not x,y)
how about
cv::min()
? link. And be carful usingsalient.at<uchar>(i, j) = 1 - m.at<uchar>(i, j);
because there is no saturation. Usecv::subtract()
instead.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.