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
Hi, I'm encountering an issue when decoding 16-bit TIFF images using the nvImageCodec library. The decoded image appears to be duplicated and the range of pixel values is different from the expected range.
Expected result:
The decoded image should match the original image, both in terms of pixel values and visual appearance.
Actual result:
The decoded image appears to be duplicated and the range of pixel values is different from the expected range.
Expected Output:
Actual Output:
Minimum reproducible example
import cupy as cp
import numpy as np
from nvidia import nvimgcodec
import matplotlib.pyplot as plt
from tifffile import imread, imwrite
def sh_info(img, header=""):
print(header)
print(f"\tShape: {img.shape}")
print(f"\tMin value: {img.min()}")
print(f"\tMax value: {img.max()}")
print(f"\tData type: {img.dtype}")
# Creating a random 16-bit image
arr = np.random.random((4096,4096))
arr *= 60000
arr[100:400, 100:400] = 61000
arr = arr.astype(np.uint16)
sh_info(arr, "Original Image")
# Writing the image to a tif file and reading it back
imwrite('test.tif', arr, dtype=np.uint16)
img0 = imread('test.tif')
sh_info(img0, "tifffile Decoded Image")
# Decode the image using nvimgcodec
params = nvimgcodec.DecodeParams(color_spec=nvimgcodec.ColorSpec.UNCHANGED, allow_any_depth=True)
dec = nvimgcodec.Decoder()
img_decoded = dec.read('test.tif', params)
# Convert the decoded image to a CuPy array
cp_img = cp.asarray(img_decoded).get()
sh_info(cp_img, "nvImageCodec Decoded Image")
# Create a figure with 3 subplots
plt.figure(figsize=(15, 5))
plt.subplot(1, 3, 1)
plt.title('Original Image')
plt.imshow(arr)
plt.subplot(1, 3, 2)
plt.title("tifffile Decoded Image")
plt.imshow(img0)
plt.subplot(1, 3, 3)
plt.title('nvImageCodec Decoded Image')
plt.imshow(cp_img)
plt.tight_layout()
plt.show()
The allow_any_depth=True parameter in DecodeParams seems to be causing the issue. However, setting it to False is not a viable solution for me, as I need to preserve the original data type of the image. When allow_any_depth is set to False, the only remaining issue is the incorrect range of pixel values.
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:
Version
0.2.0.7
Describe the bug.
Hi, I'm encountering an issue when decoding 16-bit TIFF images using the nvImageCodec library. The decoded image appears to be duplicated and the range of pixel values is different from the expected range.
Expected result:
The decoded image should match the original image, both in terms of pixel values and visual appearance.
Actual result:
The decoded image appears to be duplicated and the range of pixel values is different from the expected range.
Expected Output:
Actual Output:
Minimum reproducible example
Environment details
Relevant log output
No response
Other/Misc.
The
allow_any_depth=True
parameter inDecodeParams
seems to be causing the issue. However, setting it to False is not a viable solution for me, as I need to preserve the original data type of the image. When allow_any_depth is set to False, the only remaining issue is the incorrect range of pixel values.Check for duplicates
The text was updated successfully, but these errors were encountered: