CV_16F meanStdDev reports nonzero deviation for constant images 🤖🤖🤖

Open
#30,964 0 comments 0 reactions 0 assignees View on GitHub

Maintainers usually reply within 1 day

@ternaus is already working on this.

Since Nov 19, 2026.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Clearly specified
Activity status
Stale
Tech stack
cpp, opencv, python

Research direction

Start by locating the CV_16F CPU fallback for meanStdDev, which the issue identifies as accumulating the first moment in float while accumulating squares in double. Compare its results with the included CV_32F and float64 references for both reproductions. The issue is already under work in open pull request #30965; completion should produce the expected mean and zero deviation for the constant image and accurate statistics for the four-sample case.

Written by the indexing model from the issue text.

Description

System Information

OpenCV 5.1.0 (opencv-python-headless 5.1.0.95), macOS ARM64, Apple M4 Max, Python 3.11, NumPy 2.4.6. The current 5.x CPU fallback still accumulates the CV_16F first moment in float.

Detailed description

A constant 512 × 512 CV_16FC3 image filled with the binary16 representation of 0.7 reports mean 0.6999161243438721 and standard deviation 0.019771052840606818 on the tested ARM64 wheel. The expected result is mean 0.7001953125 and standard deviation zero. This affects normalization of low-variance and constant FP16 images using per-channel statistics.

meanStdDev loses representable FP16 contributions when mixed with larger values. For the four samples below, CV_16F reports mean 0.5 and standard deviation 0.5000000000000018. Widening the source to CV_32F and computing the reference in float64 both give mean 0.5000000298023224 and standard deviation 0.4999999701976776.

The public results are CV_64F. The CV_16F fallback currently keeps its partial sum in float while accumulating squares in double. As a downstream workaround Albucore allocates a full float32 image before computing per-channel statistics.

Related discussion is in #25019.

Steps to reproduce
import cv2 as cv
import numpy as np

for image in (
    np.full((512, 512, 3), 0.7, dtype=np.float16),
    np.array([[1, 2**-24, 1, 2**-24]], dtype=np.float16),
):
    for dtype in (np.float16, np.float32):
        mean, stddev = cv.meanStdDev(image.astype(dtype))
        print(dtype, mean.ravel(), stddev.ravel())

Issue submission checklist
  • I report the issue, it's not a question.
  • I searched for an existing report and checked the CPU implementation.
  • I reproduced the issue with the latest released OpenCV wheel.
Dominant language
C++
Stars
91.6k
Forks
57.1k
Avg merge
3d 3h
Merged PRs (30d)
210

Getting set up

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from opencv/opencv

All issues in opencv/opencv

Similar issues

More C++ issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.