How to load *.hdr files using python
Asked Answered
L

2

7

I would like to read an environment map in *.hdr file format. It seems that very popular libraries doesn't support .hdr file reading, for example, OpenCV, PIL etc.. So how to read a .hdr file into a numpy array?

Loosejointed answered 25/9, 2015 at 15:12 Comment(0)
L
6

I found ImageIO very useful. It can handle many image file formats including .hdr images. Here is the list: ImageIO Formats

It can be easily installed using easy_install or pip.

Loosejointed answered 25/9, 2015 at 18:29 Comment(3)
When I try to load an hrd-image using the imageio module in Python 3 I get the error message ValueError: Could not find a format to read the specified file in mode 'i'. Do you know what that means or how to solve it?Goosegog
It means that you did not specify the format imageIO should use when reading the file and the auto format detection is coming up with empty. Try running it again with format='HDR-FI' as an argument. This will most likely tell you that the FreeImage library is not installed and then it will tell you how to install it. (Spoiler alert: you install it by running imageio.plugins.freeimage.download()). After that, it should work.Ingroup
I get that prompt, but am unable to download the library because the SSL certificate fails to verifyIsar
O
0

For some reason when I was trying to load a MRI image in .hdr format using format='HDR-FI' it was returning Could not load bitmap <path to image>: : RGBE read error

But if you type imageio.show_formats() it returns a list of formats including "ITK - Insight Segmentation and Registration Toolkit", where it shows that it can handle .hdr images as well.

So my alternative was to use:

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
Ordonez answered 25/10, 2021 at 15:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.