Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inconsistency when reading floating point .exr image file #1047

Open
Shrinidhibhat87 opened this issue Oct 19, 2023 · 3 comments
Open

Inconsistency when reading floating point .exr image file #1047

Shrinidhibhat87 opened this issue Oct 19, 2023 · 3 comments

Comments

@Shrinidhibhat87
Copy link

Shrinidhibhat87 commented Oct 19, 2023

When reading a floating point image of extension .exr there is an inconsistency with regards to the format and shape.
I verified this with two different systems.
Both were on ubuntu 20.04.
Imageio version: 2.31.5

The image is attached as a zip file:
a.zip

The python script:

#!/usr/bin/env python3
import imageio.v3 as iio
import numpy as np

if __name__ == '__main__':
    im = iio.imread('~/Downloads/a.exr')
    print("format", im.shape, im.dtype)
    print("range: [{}, {}] m".format(np.min(im), np.max(im)))

Output system 1:
format (1, 200, 300, 3) uint8
range: [255, 255]

Output system 2:
format (200,300) float32
range: [1.0, 1.0] m

I want system 1 to also showcase the same behaviour as system 2. Why is this inconsistency happening?

To give more context, reading the image using opencv with the cv2.IMREAD_UNCHANGED flag set results in
format (200,300) float32
range: [1.0, 1.0] m

Whereas without the flag, the response is the same as system 1
format (1, 200, 300, 3) uint8
range: [255, 255]

@Pandede
Copy link
Contributor

Pandede commented Nov 2, 2023

Did the systems have different version of opencv? It seems the default flags of cv2.imread is changed since an unknown version.
However, you may change the flags in imageio:

import imageio.v3 as iio
import numpy as np

im = iio.imread('a.exr', flags=cv2.IMREAD_UNCHANGED)
print(im.shape)                 # (200, 300)
print(im.dtype)                 # float32
print(np.min(im), np.max(im))   # 1.0 1.0

@Shrinidhibhat87
Copy link
Author

Did the systems have different version of opencv? It seems the default flags of cv2.imread is changed since an unknown version. However, you may change the flags in imageio:

import imageio.v3 as iio
import numpy as np

im = iio.imread('a.exr', flags=cv2.IMREAD_UNCHANGED)
print(im.shape)                 # (200, 300)
print(im.dtype)                 # float32
print(np.min(im), np.max(im))   # 1.0 1.0

Thanks for your reply :)

The version of OpenCV that both the systems had was 4.8.1. But regardless of OpenCV, we expected the same behaviour when reading from imageio, but we got different results.

Can you please tell me which version of imageio are you using and testing this on? Because, you seemed to have used cv2.IMREAD_UNCHANGED
flag when reading via imageio and I cannot see an import of cv2 done in the code above.

By running your code, I get an error saying
TypeError: read() got an unexpected keyword argument 'flags'

I have not seen documentation on imageio which specifies the usage of the argument 'flags'.

So your above response has not helped us resolve the issue that we are facing

@Pandede
Copy link
Contributor

Pandede commented Nov 5, 2023

@Shrinidhibhat87 The version of mine is 2.31.6.
I guess the error is raised as the plugin for reading the image is not opencv. Try this:

import imageio.v3 as iio
im = iio.imread('a.exr', plugin='opencv', flags=cv2.IMREAD_UNCHANGED)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants