Converting an SDR Panoramic image into an HDRi

Deviation Actions

SlickSHWart's avatar

Literature Text

Converting an SDR Panoramic image into an HDRi (and why you're doing it wrong).

Stop it. You're making my brain itch.

So, the reason I am writing this tutorial/rant is because I have seen a whole lot of well intentioned people out there on the interwebs pushing some very bad information on how to get illumination from SDR images. These people usually advocate for one of two approaches; either A) Open the SDR image in Photoshop/GIMP, change the bit depth to 32, and re-save as an .hdr or .exr file. B) Open the SDR image in Photoshop/GIMP, then use exposure filters to save out several "faked" exposures as SDR JPEGs or PNGs, and then import them into so-called "HDR"(<-note the quotes; more on that later) creation software like Nik Tools.

Let me be clear: both of these methods are wrong. Dead wrong. This is not an opinion, it's empirical truth. So, please stop. You're making my brain itch.

The only effect that option A will have is to make your file size bigger. Nothing more. Seriously, don't do it. Packing SDR data into an HDR format will not make it HDR.

As for option B, that won't work either, and if you want to know why....

"HDR" vs. HDR

The first thing you need to understand is that there are two completely different types of images that are called an "HDR image", and they both are created by merging SDR images of different exposures into a single image. However, these two methods have a different purpose, and a different output. If you google "creating HDR images" or something similar, you will get lots of info on how to use Nik tools, Luminance HDR, or other similar tools to create an "HDR"(again, with the quotes) image. This is also the same method that your smart phone uses when you have "HDR" enabled in your camera application. Despite what the name would imply, this does not create an image with High Dynamic Range; the output of this method is still an SDR image. The purpose of this method is not to create and HDR image, but instead to use multiple exposures to pack as much color and contrast into a single SDR image. This method has no positive effect on the image's ability to light a scene. Unless, of course, you want your background to look over-saturated, hyper-contrasty, and unrealistic.

Bottom Line: This does not produce an HDR image, and it should not be called and HDR image. All this does is use several exposures to create a tone-mapped SDR image.

So what is a "real" HDR?

Technically speaking, any image that is saved in a 16 or 32 bit format, and has a contrast level beyond the 0-255 range available in SDR format is a High Dynamic Range image. So, lets say you take an SDR image, open it an an editor and change the bit depth to 32-float, select just the pixels at the center of a light source and then adjust the exposure of those pixels with a high value, like +15, and then save it as an .hdr or .exr. Shazam! you've just created a real HDR image! Congrats! You could then take that image into any 3D software and use it as the environment light. It would look like garbage, but you would definitely see that those pixels that you adjusted the exposure on are producing light. 

However, if we want realistic lighting, it's not enough to just have a dynamic range beyond what SDR allows, we really need the full dynamic range of the real-world scene. This means that if we were to create an HDRi using a DSLR camera, we have to take several images at different exposures, where the brightest exposure shows the darkest areas clearly, and the dimmest exposure shows the light sources as only pin-pricks. These would then be merged into a single 32-bit image file using specialized software. 

If you want more info I highly recommend

Still Confused?

If you're still confused, that's not entirely your fault. One of the most annoying things about working with High Dynamic Range is that, well, you can't actually see that expanded range. You see, just because you have an HDR image, that does not mean that your monitor will be able to display the expanded range of that image. Your video card and monitor are going to clip the output into the SDR range. Even if you have an HDR monitor, yes, you'll see more contrast than you would if it were an SDR monitor, but it is still nowhere close to being able to display the full dynamic range available in a 32-bit image format. And that's a good thing. Let's think about it: If you actually had a hypothetical monitor that could display the full range of a 32-bit image, and if you used that monitor to display a proper HDR image of the sun, at best you would be blind, and at worst, you might burst into flames.  

Say Waaaht?

OK, last chance to get your head wrapped around this. Let's do an experiment. The below image shows a cropped sun from this HDRi… . The one on the left is the original sun, but the one on the right, I reduced to 8-bits per channel before pasting it in.

Can you tell the difference?
Test1 by SlickSHWart

You can't? Well, let's reduce the exposure on both of them by -5. What about now?
Test2 by SlickSHWart

And this is the crux of what I'm getting at. To be able to see the full dynamic range of an HDR image on a monitor, you have to view it under several different exposure settings, which, in effect, is the reverse of the process that was used to create the HDRi in the first place. When you change the exposure on a true HDRi, it should look exactly like it would if you were adjusting the exposure on a camera.

Hopefully, at this point, a light bulb has come on and you've got a better idea of what a real HDR image is. If not, sorry, I'm spent, I can't help you.

OK, Smartypants, so how do I convert an SDR image into HDR?

Well, you can't. Not really. That data is gone or was never there in the first place. The best you can do is fake it.

As far faking it goes, there's more than one way to skin that particular cat. But I'll show you my method.

We'll be using:
GIMP 2.10 or higher
Banty's Toolkit…

And you'll need an SDR panorama. I'll be using this one for this tutorial

Go ahead and get these tools installed. The exe files from Banty's Toolkit should be placed in PicturenautInstallLocation\plug-ins\hdrshop. 

Side Note 1: All of the settings I will use should be considered as baseline suggestions. Different scenarios will require different settings, but knowing how and which settings to change is just going to take experimentation and practice.
Side Note 2: There is a resolution limit of 10000x5000 in Picturenaut.
Side Note 3: We're going to be creating some really large uncompressed files which can be cleaned up when we are done, but make sure you have plenty of storage space.

Let's get into it.

First, we need to do is some gamma correction on our pano and save it as a 32-bit file. Regular SDR images have gamma correction applied to them, but an HDRi should be linear. It's not important to fully understand gamma correction, but it is important that you not skip this step, otherwise your result will look washed out. So, open up your pano in GIMP and change the bit depth to 32-float (Image->Precision->32 bit floating point), at the prompt, select Linear light. Then, bring up level adjustment (Colors->Levels). At the prompt, change it to adjust in Linear light, and in the box to the right of Clamp input, change it to 0.81 and click OK.
GammaCorrection by SlickSHWart
Now save this image as Base.pfm . And yes, PFM is a real format and it is what you should use, otherwise it might get clipped.

Next, desaturate your image by bringing up the saturation adjustment(Colors->Saturation). Set the scale to 0 and click OK. Save this image as luma.pfm. You can now close GIMP, we'll come back to it later.


Open Base.pfm in Picturenaut. Go into the Filter menu and select FakeHDRI SSE. Change Range min to 0.125, Remove Gamma to 0, and Value max to 8.
FakeHDRI by SlickSHWart
Click OK and let that percolate. It can take a while, depending on the image resolution and how fast your computer is.
Once it finishes(it will say Success! in the console window), save the output as Fake.pfm.
Now, I will not claim to know exactly what this filter does, but from what I can tell, it changes the exposure and contrast while trying not to wash out the color. Again, it's not really important that you understand it, but it's not a step you can skip. 
We now have an image that has more light info in it. The bright areas have been brightened, but so have the dark areas. So, we need to mask out the dark areas so that we get realistic contrast.

Bring out the GIMP.

Open luma.pfm in GIMP, and then duplicate the layer. Select the top layer and open up the Curves level adjustment(Colors->Curves). Again, change it to adjust in linear light and set the curve as shown:
LumaTop by SlickSHWart
Click OK. Then set the blend mode of the layer to Lighten only, hide the layer, then select the bottom layer. Do another curves adjustment as shown(make sure it's Linear!):
LumaBottom by SlickSHWart
Click OK. Un-hide the top layer and merge it down.
Hooray! we now have our mask.

Finish Him!

Finally, bring in Fake.pfm and Base.pfm as layers. Arrange it so that Fake.pfm is on top, Base.pfm is in the middle and Luma is at the bottom. Right click on Fake.pfm layer, select Add Layer Mask and click OK. Select the Luma layer and copy it (Ctrl+A, Ctrl+C), then paste it into the Mask of Fake.pfm (Select the mask, Ctrl+V, Ctrl+H). Right click on Fake.pfm layer and select apply layer mask. You can now delete the Luma.pfm layer if you want, we are done with it.

Now for some trial and error. Export this as a .hdr file and bring it into your preferred rendering app as an environment map. Put something in your scene that the environment map can illuminate. If things are too dark, go back into GIMP and bump up the exposure of the top, Fake.pfm layer by one step. Save it, and test the new file in your rendering app again. Keep doing this until things start to look right. In the case of the image that I used, the magic exposure number was +4. If you have have to change the exposure beyond 5-6 stops, you probably want to start over and set the Value Max to something higher than 8 in the the Picturenaut FakeHDRI filter.

Pics, or it didn't happen!

Proof by SlickSHWart
These two images were rendered with the exact same settings in Daz. The one on the left has the original SDR image as the environment map. The one on the right uses my newly created, "Fake" HDRi. There are no other light sources in the scene.
Hopefully, at this point, you've figured out that I'm not talking out of my ass here.

One last thing.

The above instructions work fine for indoor scenes, night scenes and overcast scenes. If your image has an extremely bright light source, like the Sun(duh!) or a bright spotlight, you will need to do one more step. 
Let's take, for instance, a scene with a visible sun. Your scene may have multiple light sources, but the sun should be exponentially brighter than anything else. Once you've gone through all the above steps, the sun in your scene will be brighter, but not brighter enough, relative to the rest of the scene, to produce realistic results. To get over this, you've got 2 options.
1) if you have decent compositing skills, you could composite a sun from a real HDRi into your fake HDRi.
2) You could select a small, feathered selection at the center of the sun, and then through trial and error, keep bumping up the exposure of that selection until it looks right in your rendering app. Keep in mind though, as you bump up the exposure of the selection, it will start to wash out the color. So once you've got to where it is displaying the right amount of light, you then need to adjust it to have the correct color of light. You can do this by adjusting the color temperature of your selection.

That's all folks

Have fun.

Join the community to add your comment. Already a deviant? Log In

Banty's Toolkit is gone. What do I do?