title: What is the right way to write an HDR image using OpenCV in Python?
body: <p>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.</p>
  
  <p>I tried doing it the usual way, by first reading the hdr file as </p>
  
  <pre><code>img = cv2.imread('original.hdr', -1).astype(np.float32)
  </code></pre>
  
  <p>and then write it as </p>
  
  <pre><code>cv2.imwrite('new_original.hdr', img)
  </code></pre>
  
  <p>I use Mac's Finder and the <a href="https://viewer.openhdr.org/" rel="nofollow noreferrer">OpenHDRViewer</a> to view HDR images. When I run the above code, the Mac finder is properly able to show the <code>new_original.hdr</code> file. But when I try to see the same hdr image using the OpenHDRViewer, it gives an error saying - </p>
  
  <blockquote>
    <p>This file type is not supported!
    This site does not currently support tone-mapped or LDR images yet. Check back later for updates.</p>
  </blockquote>
  
  <p>Is <code>new_original.hdr</code> not a valid HDR image?</p>
  
  <p>Is there some format based information that is lost when I use a conventional <code>cv2.imwrite()</code> to write HDR images. What is the right way to do this ?</p>