title: entropy for a gray image in opencv
body: <p>I need code to find entropy of an image.</p>
  
  <pre><code>for(int i=0;i&lt;grey_image.rows;i++)
  {
      for(int j=1;j&lt;grey_image.cols;j++)
      {
          //cout&lt;&lt;i&lt;&lt;" "&lt;&lt;j&lt;&lt;" "&lt;&lt;(int)grey_image.at&lt;uchar&gt;(i,j)&lt;&lt;endl;
          int a=(int)grey_image.at&lt;uchar&gt;(i,j);
          int b=(int)grey_image.at&lt;uchar&gt;(i,j-1);
          int x=a-b;
          if(x&lt;0)
              x=0-x;
          probability_array[x]++;
          //grey_image.at&lt;uchar&gt;(i,j) = 255;
      }
  }
  //calculating probability
  int n=rows*cols;
  for(int i=0;i&lt;256;i++)
  {
      probability_array[i]/=n;
      //cout&lt;&lt;probability_array[i]&lt;&lt;endl;
  }
  // galeleo team formula
  float entropy=0;
  for(int i=0;i&lt;256;i++)
  {
      if (probability_array[i]&gt;0)
      {
          float x=probability_array[i]*log(probability_array[i]);
          entropy+=x;
      }
  }
  return 0-entropy;
  </code></pre>
  
  <p>Actually I am using this to dump in a programmable camera to measure entropy. Now I want to use it in windows system. I am getting entropy of a gray image as zero.Please help me out. Where did I go wrong.</p>