Ask Your Question
0

How to find average pixel value of an grayscale image in c++?

asked 2018-08-04 02:22:19 -0600

Samjith888 gravatar image

I'm going to classify the image into black or not. So i have to find the average pixel value of the image..

edit retag flag offensive close merge delete

Comments

really ??? please explain, why you think, you need the average for this.

berak gravatar imageberak ( 2018-08-04 02:35:55 -0600 )edit

If the average will be lesser than a specific value (eg: 100) then i can realize that this image has more black shades and i can classify this.If its like 0 to 30 then i can consider it as black image in humans view.

Samjith888 gravatar imageSamjith888 ( 2018-08-04 03:06:44 -0600 )edit

Do you know any other method to find whether the image is black or not?

Samjith888 gravatar imageSamjith888 ( 2018-08-04 03:14:14 -0600 )edit

1 answer

Sort by ยป oldest newest most voted
0

answered 2018-08-04 03:33:18 -0600

berak gravatar image

we can use:

Scalar m = cv::mean(img);
Mat bin = img > m[0]; // syntax sugar for 'threshold()'

but better, opencv has an automatic threshold method:

Mat bin;
cv::threshold(img, bin, 0, 255, THRESH_OTSU);
edit flag offensive delete link more

Comments

Yeah. It works. Thank you..

Samjith888 gravatar imageSamjith888 ( 2018-08-06 00:16:03 -0600 )edit

Question Tools

1 follower

Stats

Asked: 2018-08-04 02:22:19 -0600

Seen: 19,263 times

Last updated: Aug 04 '18