cv2.imread() from 16-bit TIFF creates arrays where np.maximum() fails in function context but works directly
Nobody has claimed this yet.
Assessment
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Newbie friendliness
- 35/100
- Issue type
- Bug
- Clarity
- Mostly clear
- Activity status
- Quiet
- Tech stack
- numpy, python
- Domain
- computer-vision
Research direction
Start by running test_cv2_issue.py with the attached 0000.tif under the reported Python, OpenCV, and NumPy versions, then compare the direct and function-context np.maximum() results. Done means the context-dependent failure is reproduced and its scope or cause is established, with the HLS hue result and array layout checked against the report.
Written by the indexing model from the issue text.
Description
Environment (fill in your exact versions):
- Platform: macOS-15.6.1 (arm64)
- Python 3.14.2
- OpenCV: 4.11.0
- NumPy: 2.2.6
Bug Description:
- cv2.imread() with 16-bit TIFF files creates float32 arrays that cause np.maximum() and np.minimum() to behave inconsistently. When these numpy functions are called inside another function, they return incorrect values, but when called directly on the same arrays, they work correctly.
Key Symptoms:
- Context-dependent failure: np.maximum() works when called directly, fails when called inside functions
- Incorrect HLS conversion: Causes hue channel (H) to be 0 instead of ≈46.6
- Array properties: Non-C-contiguous (strides: (24000, 12) for 1300×2000 image)
- Specific to: Photoshop-created 16-bit TIFFs (random syntetic TIFFs generated by CV2 don't trigger bug)
Impact:
- Any image processing using np.maximum()/np.minimum() on OpenCV-loaded float32 arrays in functions produces wrong results.
Workaround:
- Use Python's max()/min() instead of np.maximum()/np.minimum(). But it is extremely slower for large images.
The bug does not show up with python 3.12.
In attachment a sample image and the script that allows to reproduce the bug.
- Dominant language
- Python
- Stars
- 5.4k
- Forks
- 1k
- Avg merge
- 22h 17m
- Merged PRs (30d)
- 3
Contributor 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-python
-
[DOC] README file Open
Difficulty 1/5 Under an hour Newbie friendliness 85/100
opencv/opencv-python#1217 · 3 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 72/100
opencv/opencv-python#1165 · 2 comments · 1 reaction ·
-
Difficulty 5/5 Over a week Newbie friendliness 25/100
opencv/opencv-python#1273 · 1 comment ·
-
Difficulty 4/5 3-5 days Newbie friendliness 45/100
opencv/opencv-python#1272 · 1 comment ·
-
Difficulty 3/5 1-2 days Newbie friendliness 70/100
opencv/opencv-python#1268 · 1 comment ·
All issues in opencv/opencv-python
Similar issues
-
area: harness bug status: needs-triage
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Human-Agent-Society/reef#625 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 70/100
-
Difficulty 1/5 Under an hour Newbie friendliness 80/100
learningequality/kolibri#15351 · 2 comments ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
-
Name consistency Open
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
eellak/triplestore#65 · 1 comment ·