【发布时间】:2021-10-25 23:27:43
【问题描述】:
我想读取 *.hdr 文件格式的环境图。好像很流行的库都不支持.hdr文件读取,比如OpenCV、PIL等。那么如何将.hdr文件读入numpy数组呢?
【问题讨论】:
我想读取 *.hdr 文件格式的环境图。好像很流行的库都不支持.hdr文件读取,比如OpenCV、PIL等。那么如何将.hdr文件读入numpy数组呢?
【问题讨论】:
我发现ImageIO 非常有用。它可以处理许多图像文件格式,包括 .hdr 图像。这是列表:ImageIO Formats
可以使用 easy_install 或 pip 轻松安装。
【讨论】:
ValueError: Could not find a format to read the specified file in mode 'i'。你知道这意味着什么或如何解决它吗?
format='HDR-FI' 作为参数再次运行它。这很可能会告诉你 FreeImage 库没有安装,然后它会告诉你如何安装它。 (剧透警告:您可以通过运行imageio.plugins.freeimage.download() 来安装它)。之后,它应该可以工作了。
由于某种原因,当我尝试使用 format='HDR-FI' 加载 .hdr 格式的 MRI 图像时,它返回了 Could not load bitmap <path to image>: : RGBE read error
但是,如果您输入 imageio.show_formats(),它会返回一个格式列表,包括“ITK - Insight Segmentation and Registration Toolkit”,其中显示它也可以处理 .hdr 图像。
所以我的替代方法是使用:
pip install itk
hdr_path = "<path to image>"
img = imageio.imread(hdr_path, 'ITK') # returns a tuple
img = np.array(img) # transforms to numpy array
【讨论】: