CV_16F meanStdDev reports nonzero deviation for constant images 🤖🤖🤖
Maintainers usually reply within 1 day
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Stale
- Domain
- computer-vision, performance
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
- No Dockerfile or Docker Compose file
- Has a pull request template
- Read the contributing guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from opencv/opencv
-
dnn: CumProd crashes when the scan axis has length 0Possibly taken @sshivensolanki claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
-
dnn: Trilu does not mask rows past the last column when the input has more rows than columnsPossibly taken @sshivensolanki claimed this today. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
Maintainers usually reply within 1 day
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
feature
Difficulty 2/5 1-3 hours Newbie friendliness 62/100
Maintainers usually reply within 1 day
-
dnn: Shape layer asserts when start > end instead of returning an empty shapePossibly taken @sshivensolanki claimed this 2 days ago. Openbug
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Maintainers usually reply within 1 day
Similar issues
-
bot-triaged module: correctness (silent) module: fft triage review
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 68/100
patrickjquinn/Marathon-Shell#84 ·
Maintainers usually reply within 1 day
-
Difficulty 1/5 Under an hour Newbie friendliness 78/100
sav-oss-org/ptusa_main#1610 ·
Maintainers usually reply within 1 day
-
Difficulty 2/5 1-3 hours Newbie friendliness 74/100
open-astro/AlpacaBridge#2606 · 1 comment ·
Maintainers usually reply within 1 day
-
Refactor force_torque_system integration test to use EcmScopePossibly taken @patelshivani2283-lab claimed this today. Open
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
Maintainers usually reply within 1 day