0

I want to perform arithmetic operations on an existing HDR image using OpenCV and then write the HDR file in the .hdr format. The arithmetic operation is not important to the question, so let's just say I want to read a .hdr file and then write it into the same format.

I tried doing it the usual way, by first reading the hdr file as

img = cv2.imread('original.hdr', -1).astype(np.float32)

and then write it as

cv2.imwrite('new_original.hdr', img)

I use Mac's Finder and the OpenHDRViewer to view HDR images. When I run the above code, the Mac finder is properly able to show the new_original.hdr file. But when I try to see the same hdr image using the OpenHDRViewer, it gives an error saying -

This file type is not supported! This site does not currently support tone-mapped or LDR images yet. Check back later for updates.

Is new_original.hdr not a valid HDR image?

Is there some format based information that is lost when I use a conventional cv2.imwrite() to write HDR images. What is the right way to do this ?

  • Do you have a link to a suitable HDR file please? And could you be more specific about which actual HDR format you are referring to? – Mark Setchell Apr 06 '19 at 16:13
  • @MarkSetchell You can use any sample file from here-http://pfstools.sourceforge.net/hdr_gallery.html I am referring to the .hdr format, which I believe is the radiance map/format. – Mukul Khanna Apr 06 '19 at 16:51

2 Answers2

0

@MukulKhanna I faced the same problem. However, by changing the extension to .exr from .hdr in imwrite() did the trick and I could view the image on OpenHDRViewer.

-1

It seems like that you wrote

img = cv2.imread('original.hdr', -1).astype(np.float32)

and this will result in a float32 data type image, ranging in 0~255.

I guess the intensity of a float32 hdr image should be limited in around 0~1. (anyway even if for hdr image, the 255x dynamic range is too high to display)

刘永彬
  • 64
  • 2