使用RAPIDS cucim读取float64格式TIFF图像遇错求助
使用cucim读取float64格式TIFF图像遇到的问题
问题背景
尝试用cucim读取一张CT扫描生成的float64格式.tiff图像(shape=(657, 668))为数组,因未找到类似imread的函数,参照网上示例编写了如下代码:
import numpy as np from cucim import CuImage im_path = r'/mnt/c/Users/.../filename.tiff' im_obj = CuImage(im_path) count = im_obj.resolutions['level_count'] dimensions = im_obj.resolutions['level_dimensions'] region = im_obj.read_region(location=(0, 0), level=count-1, size=dimensions[count-1]) im_arr = np.asarray(region)
运行报错与警告
执行代码后出现以下警告和错误:
[Warning] Loading image('/mnt/c/Users/.../filename.tiff') with a slow-path. The pixel format of the loaded image would be RGBA (4 channels) instead of RGB! RuntimeError: This format (compression: 1, sample_per_pixel: 1, planar_config: 1, photometric: 1) is not supported yet!: Sorry, can not handle images with 64-bit samples
疑问
- 不清楚
slow-path的含义 - 未在cucim文档中找到dtype支持相关内容
- 询问是否操作有误,当前需求能否实现?是否应先用imageio读取图像,再使用cucim的其他功能?
环境信息
Ubuntu 22.04.3 LTS on WSL2 Build cuda_12.2.r12.2/compiler.33191640_0 cucim 24.04.00 cuda12_py310_240410_ga24abfd_0 rapidsai (conda安装)
解答
问题原因
- 格式支持限制:错误提示明确说明cucim当前版本无法处理64位采样的图像,这是核心问题——你的float64格式TIFF不在cucim的支持范围内。
- slow-path含义:这是cucim的降级处理机制,当它无法使用GPU加速的快速路径处理图像时,会切换到CPU上的慢速处理流程;同时因为无法正确识别单通道CT图像的格式,错误推断为RGBA通道,因此出现警告。
解决方案
- 格式转换后读取:如果可以接受精度损失,先将float64格式的TIFF转换为cucim支持的格式(如float32、uint16),再用cucim读取处理。
- 混合方案:先用imageio或Pillow等支持float64 TIFF的库读取图像到CPU数组,再转换为CUDA数组(例如用
cupy.asarray(im_arr)),之后再使用cucim的GPU加速功能处理。这种方案能保留CT图像的原始精度,更适合医疗影像场景。
操作结论
你的代码逻辑没有错误,问题源于cucim的格式支持限制,当前直接用cucim读取float64 TIFF的需求无法实现。优先推荐第二种混合方案,既能保留图像精度,又能利用cucim的GPU功能。
内容的提问来源于stack exchange,提问作者user8188435
相关产品推荐
相关产品推荐

