How to calculate the average with CV_32F foramt? [closed]

asked 2019-11-19 18:45:36 -0500

Hi all. Good morning :)

I have a question about the CV_32F Format.

I want to calculate the pixel average with CV_8U, CV_32F format images.

So, I used the API as below: cv::mean() cv::meanStdDev()

The case of CV_8U, it works well. I can get the average value. But the CV_32F couldn't. It always returned nan value.

So... my question is 'how to calculate the average with CV_32F format image?'.

Please advise for me :)

Thank you!

Best regards, William Kim

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by Luckygg
close date 2019-11-20 17:34:35.075794

Comments

1

That sounds like the CV_32F contains a NaN to begin with. Try running patchNaNs before mean to see if that fixes it.

Tetragramm gravatar imageTetragramm ( 2019-11-20 00:14:13 -0500 )edit

cannot reproduce:

Mat m(13,13,CV_32F);
randu(m,0,1);
cout << m << endl;
Scalar M = mean(m);
cout << M << endl;
[0.497418, 0, 0, 0]
berak gravatar imageberak ( 2019-11-20 00:59:14 -0500 )edit

Oh, thank you Tetragramm! I tried 'pathchNaNs' before called 'mean', it works well. Thank you :)

Luckygg gravatar imageLuckygg ( 2019-11-20 17:33:47 -0500 )edit