cucim
cucim copied to clipboard
Accessing metadata can cause segmentation fault!
The following code results in Segmentation fault (core dumped)
:
import numpy as np
from tifffile import imwrite
from cucim import CuImage
# Create image array
img_array = np.ones((128, 128, 3)).astype(np.uint8)
print(f'RGB image shape: {img_array.shape}')
img_array = np.concatenate([img_array, 255 * np.ones_like(img_array[..., 0])[...,np.newaxis]], axis=2)
print(f'RGBA image shape: {img_array.shape}')
filename = 'test_cucim.tiff'
imwrite(filename, img_array, shape=img_array.shape, tile=(16, 16))
obj = CuImage(filename)
print(obj.metadata)
while it works if:
- the image is RGB instead of RGBA, or
- access the metadata through the extracted region instead:
img = obj.read_region()
print(img.metadata)
{'cucim': {'associated_images': [], 'channel_names': ['R', 'G', 'B', 'A'], 'coord_sys': 'LPS', 'dims': 'YXC', 'direction': [[1.0, 0.0, 0.0], [0.0, 1.0, 0.0], [0.0, 0.0, 1.0]], 'dtype': {'bits': 8, 'code': 1, 'lanes': 1}, 'ndim': 3, 'origin': [0.0, 0.0, 0.0], 'path': 'test_cucim.tiff', 'resolutions': {'level_count': 1, 'level_dimensions': [[0, 1065353216]], 'level_downsamples': [1.0], 'level_tile_sizes': [[0, 0]]}, 'shape': [128, 128, 4], 'spacing': [1.0, 1.0, 1.0], 'spacing_units': ['micrometer', 'micrometer', 'color'], 'typestr': '|u1'}}
Thanks @drbeh for reporting this issue!