Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Finding sum of all pixel values of a gray image

I want to find the sum of all pixel values of a gray image(Mat type). For that i need to access each pixel's intensity value. How can I do this in java? I'm using opencv library with it. In OpenCV we can use the following code:

for(int j=r.y;j<(r.y+r.height);j++)
    {
      for (int i=r.x;i<(r.x+r.width);i++)
      {
         int d= gray_image.at<uchar>(j,i);
         sum+=d;
      }
    }

Please suggest a solution to code it in java. Thanks!! I have tried it by using "Raster" as follows:

Raster raster = Gray_image.getRaster();

but I'm getting following error: The method getRaster() is undefined for the type Mat

Please help me!!