I have converted an HDR image in RGB color space to CIE-XYZ color space with "cvtColor" function, and then written the image to a Radiance HDR file using "imwrite" function. However, the header of the Radiance HDR file still says "FORMAT=32-bit_rle_rgbe". What should I pass to "imwrite" to make sure it specifies the color space correctly?
I am following the code as in this example: https://docs.opencv.org/3.4/d3/db7/tutorial_hdr_imaging.html (except the tone mapping part, which is irrelevant to my problem). I need the relative luminance information, so I have tried to convert the HDR image, which is in BGR space by default, to the CIE-XYZ space using the code shown below.
/* Codes to read in images and construct the camera response function
can be found from the link above, though I am happy to post the whole
if needed.*/
//! [Make HDR image]
std::cout << "Now make HDR file" << endl;
Mat hdr;
Ptr<MergeDebevec> merge_debevec = createMergeDebevec();
merge_debevec->process(images, hdr, times, response);
/* The hdr is in BGR color space by default.
Therefore, convert it to XYZ space by the following two lines. */
Mat hdr_xyz;
cv::cvtColor(hdr, hdr_xyz, CV_BGR2XYZ);
//! [Write results]
std::cout << "Now write to files" << endl;
cv::imwrite("hdr.hdr", hdr);
cv::imwrite("hdr_xyz.hdr", hdr_xyz);
Most of the code seems to be working, and the resulting HDR image seems to have been converted correctly (judging from the numbers in matrix "hdr_xyz").
However, the resulting HDR file "hdr_xyz.hdr" still has the following header: "#?RGBE FORMAT=32-bit_rle_rgbe" As a result, the image can't be shown correctly with "imshow" or programs like Photoshop. I have also tried the program "hdrgen" by Greg Ward (http://www.anyhere.com/). The HDR file it created has the header "FORMAT=32-bit_rle_xyze" and is correctly shown in Photoshop. I guess it is an easy fix (but I am new to OpenCV). Any suggestions are greatly appreciated.