# how to prove subtract value opencv

I need to prove pixle subtract value is right , I'm using this code :

subtract(image1,image2, min); //subtract image1 - image2

cout << endl << endl << "image 1 pixel : " << endl << endl;

for (int y = 0; y < 10; y++)//To loop through all the pixels 10x10
{
for (int x = 0; x < 10; x++) //4 55
{
pix_val = image1.at<uchar>(x, y);
cout << pix_val << " , ";
}
cout << endl;

}

cout << endl << endl << "image 2 pixel : " << endl << endl;

for (int x = 0; x < 10; x++)//To loop through all the pixels 10x10
{
for (int y = 0; y < 10; y++)
{
pix_val = image2.at<uchar>(x, y);
cout << pix_val << " , ";
}
cout << endl;

}

cout <<endl<<endl<< "min pixel : " << endl<<endl;

for (int x = 0; x < 10; x++)//To loop through all the pixels 10x10
{
for (int y = 0; y < 10; y++)
{
pix_val = min.at<uchar>(x, y);
cout << pix_val <<" , ";
}
cout << endl;

}


but the result is different

but not all value match.

Please help me, i need to prove subtract value with number.

Thank you.

edit retag close merge delete

## Comments

you swap x and y value in first loop

( 2017-07-03 06:58:23 -0500 )edit

to avoid the obvious problems with your for-loops (type, x,y), rather use:

cout <<  some_mat(Rect(0,0,10,10)) << endl;

( 2017-07-03 07:20:26 -0500 )edit

I'm sorry, I'm not careful enough. Thank you for your answer. actually, i really need help, and I want to consult with you @LBerger and @berak is it okay?

( 2017-07-03 19:13:25 -0500 )edit