title: Different Pixel Values in MATLAB and C++ with OpenCV
body: <p>I see there are similar questions to this but don't quiet answer what I am asking so here is my question.</p>
  
  <p>In C++ with OpenCV I run the code I will provide below and it returns an average pixel value of 6.32. However, when I open the image and use the mean function in MATLAB it returns an average pixel intensity of approximately 6.92ish. As you can see I convert the OpenCV values to double to try to ease this issue and have found that openCV loads the image as a set of integers whereas MATLAB loads the image as decimal values that are approximately but not quite the same obviously as the integers. So my question is, being new to coding, which is correct? I'm assuming MATLAB is returning more accurate values and if that is the case I would like to know if there is a way to load the images in the same fashion to avoid the discrepancy.</p>
  
  <p>Thank you, Code below</p>
  
  <pre><code>    Mat img = imread("Cells2.tif");
  cv::cvtColor(img, img, CV_BGR2GRAY);
  cv::imshow("stuff",img);
  Mat dst;
  if(img.channels() == 3)
  {
      img.convertTo(dst, CV_64FC1);
  }
  else if (img.channels() == 1) 
  {
      img.convertTo(dst, CV_64FC1);
  }
  cv::imshow("output",dst/255);
  int NumPixels = img.total();
  
  
  double avg;
  double c = 0; 
  double std;
      for(int y = 0; y &lt; dst.cols; y++)
      { 
  
          for(int x = 0; x &lt; dst.rows; x++)
          {
              c+=dst.at&lt;double&gt;(x,y)*255;
          }
      }
  
  avg = c/NumPixels;
  cout &lt;&lt; "asfa = " &lt;&lt; c &lt;&lt; endl;
  double deviation;
  
  double var;
  double z = 0;
  double q;
      //for(int a = 0; a&lt;= img.cols; a++)
  for(int y = 0; y&lt; dst.cols; y++)
      {
          //for(int b = 0; b&lt;= dst.rows; b++)
          for(int x = 0; x&lt; dst.rows; x++)
          {
              q=dst.at&lt;double&gt;(x,y);
  
              deviation = q - avg;
              z = z + pow(deviation,2);
              //cout &lt;&lt; "q = " &lt;&lt; q &lt;&lt; endl;
          }
  
      }
  
  var = z/(NumPixels);
  std = sqrt(var);
  cv::Scalar avgPixel = cv::mean(dst);
  
  cout &lt;&lt; "Avg Value = " &lt;&lt; avg &lt;&lt; endl;
  cout &lt;&lt; "StdDev = " &lt;&lt; std &lt;&lt; endl;
  cout &lt;&lt; "AvgPixel =" &lt;&lt; avgPixel;
  
  cvWaitKey(0);
  return 0;
  </code></pre>
  
  <p>}</p>