# Revision history [back]

### cvtColor vs reading image directly

I have the following:

string input = "test.jpg";

cv::Mat img1;
cv::cvtColor(tmp, img1, CV_BGR2GRAY);

isMatEqual(img1, img2);


where isMatEqual():

bool isMatEqual(const cv::Mat & a, const cv::Mat & b)
{
if ( (a.rows != b.rows) || (a.cols != b.cols) )
return false;
cv::Scalar s = sum( a - b );
return (s[0]==0) && (s[1]==0) && (s[2]==0);
}


However I am not getting an equality when comparing the 2 images. If I am forced to read the image in first and then do a cvtColor() transform to grayscale, what would be a correct parameter to set such that img1 == img2?

### cvtColor vs reading image directly

I have the following:

string input = "test.jpg";

cv::Mat img1;
cv::cvtColor(tmp, img1, CV_BGR2GRAY);

isMatEqual(img1, img2);


where isMatEqual():

bool isMatEqual(const cv::Mat & a, const cv::Mat & b)
{
if ( (a.rows != b.rows) || (a.cols != b.cols) )
return false;
cv::Scalar s = sum( a - b );
return (s[0]==0) && (s[1]==0) && (s[2]==0);
}


However I am not getting an equality when comparing the 2 images. If I am forced to read the image in first and then do a cvtColor() transform to grayscale, what would be a correct parameter to set such that img1 == img2?

Edit: I saw a similar question: https://stackoverflow.com/questions/7461075/opencv-image-conversion-from-rgb-to-grayscale-using-imread-giving-poor-results but I am unable to reproduce the answer given with my input.