You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When reading an 1ch 8bit image, nvimgcodec returns a 3ch 8bit image. OpenCV has the same behaviour when not specifying a format. When specifying flagging IMREAD_UNCHANGED it reads as 1ch. PIL reads correctly by default.
Minimum reproducible example
#!/usr/bin/env python3
from pathlib import Path
import numpy as np
from PIL import Image
from nvidia import nvimgcodec
test_file = Path("test_im.png")
size = (512, 512)
im_data = np.random.uniform(0, 255, size=size).astype(np.uint8)
print(f"Saving image with {im_data.shape=}")
Image.fromarray(im_data).save(test_file)
decoder = nvimgcodec.Decoder()
nv_img = decoder.decode(test_file.read_bytes())
print(f"NV image with {nv_img.shape=}")
import cv2
cv_img = cv2.imread(str(test_file))
print(f"CV default image with {cv_img.shape=}")
cv_img = cv2.imread(str(test_file), cv2.IMREAD_UNCHANGED)
print(f"CV unchanged image with {cv_img.shape=}")
pil_image = Image.open(test_file)
print(f"PIL default image with {pil_image.size=}")
Example output of the "Minimum reproducible example"
Saving image with im_data.shape=(512, 512)
NV image with nv_img.shape=(512, 512, 3)
CV default image with cv_img.shape=(512, 512, 3)
CV unchanged image with cv_img.shape=(512, 512)
PIL default image with pil_image.size=(512, 512)
Other/Misc.
No response
Check for duplicates
I have searched the open bugs/issues and have found no duplicates for this bug report
The text was updated successfully, but these errors were encountered:
It is our intention to provide 3ch by default (even if the input is 1-channel), unless specified to decode to grayscale. However, we should probably decode the original number of channels when UNCHANGED is selected. Would that behaviour be OK for you?
Since this is a new library and version <1, would it be possible to change defaults to UNCHANGED (and unchanged to keep the same ch/bit depth) to minimize suprise? I don't think silent implicit conversion from one format to another should be desired behaviour.
Version
0.3.0.5
Describe the bug.
When reading an 1ch 8bit image, nvimgcodec returns a 3ch 8bit image. OpenCV has the same behaviour when not specifying a format. When specifying flagging IMREAD_UNCHANGED it reads as 1ch. PIL reads correctly by default.
Minimum reproducible example
Environment details
Relevant log output
Example output of the "Minimum reproducible example" Saving image with im_data.shape=(512, 512) NV image with nv_img.shape=(512, 512, 3) CV default image with cv_img.shape=(512, 512, 3) CV unchanged image with cv_img.shape=(512, 512) PIL default image with pil_image.size=(512, 512)
Other/Misc.
No response
Check for duplicates
The text was updated successfully, but these errors were encountered: