Ask Your Question
0

Finding sum of all pixel values of a gray image

asked 2015-12-02 00:48:49 -0600

VPallavi gravatar 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!!

edit retag flag offensive close merge delete

Comments

in c++you can use mean

LBerger gravatar imageLBerger ( 2015-12-02 01:14:14 -0600 )edit

I need to find in java.

VPallavi gravatar imageVPallavi ( 2015-12-02 01:18:20 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
1

answered 2015-12-02 01:25:17 -0600

berak gravatar image

http://docs.opencv.org/java/3.0.0/org...

(the docs are your friend !)

edit flag offensive delete link more

Comments

Eduardo gravatar imageEduardo ( 2015-12-02 03:17:31 -0600 )edit

I think Integral Images are great if your image isn't changing and you have to do many different sums of rectangles super fast ...but no point in creating one just so you can take one intergral.

lindsay gravatar imagelindsay ( 2019-09-19 08:17:01 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2015-12-02 00:48:49 -0600

Seen: 10,276 times

Last updated: Dec 02 '15