Ask Your Question
0

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

asked Aug 4 '18

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..

Preview: (hide)

Comments

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

berak gravatar imageberak (Aug 4 '18)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 (Aug 4 '18)edit

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

Samjith888 gravatar imageSamjith888 (Aug 4 '18)edit

1 answer

Sort by » oldest newest most voted
0

answered Aug 4 '18

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);
Preview: (hide)

Comments

Yeah. It works. Thank you..

Samjith888 gravatar imageSamjith888 (Aug 6 '18)edit

Question Tools

1 follower

Stats

Asked: Aug 4 '18

Seen: 19,612 times

Last updated: Aug 04 '18