AcademySoftwareFoundation / AcademySoftwareFoundation/OpenImageIO
[BUG] ImageBuf returns incorrect pixel data for single-channel EXRs
- Dominant language
- C++
- Stars
- 2.4k
- Forks
- 698
- Avg merge
- 3d 9h
- Merged PRs (30d)
- 48
Description
**Describe the bug**
Loading single-channel EXRs produce different pixel values if loaded with ImageInput instead of ImageBuf.
ImageBuf produces incorrect pixel values (at least for single channel uint images)
**To Reproduce**
Steps to reproduce the behavior:
1. Produce an EXR with a single-channel matte (such as a VRayObjectID )
2. Load with ImageInput and ImageBuf
3. ImageInput has correct pixel values, ImageBuf does not
**Expected behavior**
Pixel data should be the same for ImageBuf as for ImageInput
**Evidence**
```
import numpy as np
import OpenImageIO as oiio
exr_path = "VRayObjectID.0001.exr"
image = oiio.ImageInput.open(exr_path)
# Read pixels as native uint
pixels = image.read_image(format=image.spec().format)
np.unique(pixels)
# These pixel values are correct
# array([ 0, 3, 10, 13, 14, 17, 18, 20, 23, 24, 25, 27, 29, 35, 37, 58, 64,
74, 81, 87, 93, 95, 97, 98], dtype=uint32)
# Incorrect values:
image = oiio.ImageBuf(exr_path)
pixels = image.get_pixels(format=image.nativespec().format)
np.unique(pixels)
# These pixel values are incorrect
# array([ 0, 809500672, 824180736, 827326464, 828375040, 830996480,
831520768, 832569344, 834142208, 834666496, 835190784, 836239360,
837287936, 839647232, 840171520, 845676544, 847249408, 848560128,
849477632, 850264064, 851050496, 851312640, 851574784, 851705856],
dtype=uint32)
```
iinfo for the image
```
VRayObjectID.0001.exr : 872 x 712, 1 channel, uint openexr
channel list: VRayObjectID
cameraAperture: 36
cameraFarClip: 1e+30
cameraFarRange: 1e+18
cameraFNumber: 8
cameraFocalLength: 40
cameraFov: 87.135
cameraNearClip: 0
cameraNearRange: 0
cameraProjection: 0
cameraTargetDistance: 1e+18
compression: "zip"
PixelAspectRatio: 0.99975
screenWindowCenter: 0, 0
screenWindowWidth: 1
vrayInfo/peakMemory: "16277.81 MiB"
vrayInfo/rendertime: " 0h 21m 57.1s"
vrayInfo/vraycore: "4.30.01"
oiio:ColorSpace: "Linear"
oiio:subimages: 1
```
**Platform information:**
- OIIO branch/version: 2.2.17.0 and 2.3.11.0
- OS: MacOS / Linux
**IF YOU ALREADY HAVE A CODE FIX:** There is no need to file a separate issue,
please just go straight to making a [pull request](https://github.com/OpenImageIO/oiio/pulls).
Contributor guide
Research direction
Start by reproducing the issue with the provided Python snippet, comparing ImageInput.read_image(format=image.spec().format) with ImageBuf.get_pixels(format=image.nativespec().format) on a single-channel uint EXR. Trace the ImageBuf and ImageInput loading paths for OpenEXR images; done means both APIs return the same native pixel values.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- computer-graphics
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100