# The algorithm of HDR



## dum (Mar 17, 2008)

Hi!
Can anyone explain/share information with me about how HDR processing works from algorithmic point of view. I have several ideas and want to write a program, which will do a thing like this, that is why I'm asking. Most of all I'm interesting in making HDR-like picture from the SINGLE image (not different shots with different exposures). As I understand this should be done using digital reexposure and then - standard combination of images as is "traditional" HDR. So, if you please I'll outline three main areas of my interest now:

1) The approach to digital reexposure. How this could be done. Formulas or verbal description will be great.
2) The approach to tone mapping. I have implemented tone compression, but the main question is how to determine the degree of compression and colors to compress (I do not think I should compress all the colors constantly).
3) The general idea of combing image for HDR. What I do now is trying to get more details for dark areas from darker image and more details for light areas from lighter image. As a result I'm getting a bit smoke-coloured picture, so, I can imagine, I'm doing something wrong 

I'll be very thankful of any: several recommendations, brief description, detailed explanation or a reference to paper/resource, which discusses, what I need. Sure, someone have experimented with the thing like this. Help me please. I hope, the game is worth candles


----------



## Garbz (Mar 17, 2008)

Are you approaching the problem from the right angle? You mentioned HDR from a single picture, and by the pure definition of HDR being "high dynamic range" you can't do this. You cannot create what didn't exist in the first place. 

The so called single exposure HDR images you see floating around the net are nothing more than a tonemapping algorithm to compress the image, and then a contrast curve to expand it again. I conclude often that this is why the results typically look like crap.

1. Digital re-exposure? Wouldn't make a difference. You do not get added dynamic range, you only push the existing dynamic range around a bit.

2. There are a multitude of different options for tone mapping including thresholds, pixel radius for luminance approximation, the dynamic range values over which the tonemapping is applied (selected via sliders in photomatix, and via the curves tool in photoshop). The key is you don't know in advance how much compression to apply which is why each image is different and why all the options are given.

3. Smoke coloured picture? What is the final result of your HDR? Remember a HDR image is not what you see on the net. All the images you see on the net have been original HDRs compressed via tonemapping to display in a normal dynamic range type of way. You should after combining 3 images end up with a 32bit image with wider dynamic range than you can display and by selecting an appropriate brightness get back any of the 3 original exposures taken. It sounds to me like you may be trying to map 3 images to a HDR in an 8 or 16bit domain. That won't work.


I suggest if you want to play with this yourself have a look at some existing open source HDR programs http://qtpfsgui.sourceforge.net/, or http://sourceforge.net/projects/pfstools/


----------



## dum (Mar 18, 2008)

Garbz said:
			
		

> Are you approaching the problem from the right angle?



You mean feating one shot to another, when doing HDR? In any case - now. What I'm doing is more similar to HDR for video.



			
				Garbz said:
			
		

> You mentioned HDR from a single picture, and by the pure definition of HDR being "high dynamic range" you can't do this. You cannot create what didn't exist in the first place.



Of course, it is a kind of imitation, but I have seen and done several successful examples from a SINGLE picture. But for video you have no chance to make several shots with different exposure.



			
				Garbz said:
			
		

> The so called single exposure HDR images you see floating around the net are nothing more than a tonemapping algorithm to compress the image, and then a contrast curve to expand it again. I conclude often that this is why the results typically look like crap.



Great! Can you give me some references to "tonemapping algorithm" and, may be contrast increase algorithm.

They do not always look like crap. I have tried two approaches: first - tried to do "HDR" from single photo, using Photomatix and with some settings it can be satisfactory. Second - I tried to reexpose picture with ACDSee of Photoshot and then feed to Photomatix. This approach is even better.



			
				Garbz said:
			
		

> 1. Digital re-exposure? Wouldn't make a difference. You do not get added dynamic range, you only push the existing dynamic range around a bit.



Definitely, but because of non-liniarity it can result in good (for me) HDR-like picture. In any case, with typical monitor you cannot see real HDR. Even dealing with "honestly done" HDR picture you are looking at the result very close to what is POSSIBLE (but not easy) to get from a single photo. Of course this is correct is there are no over-, under-exposed areas.



			
				Garbz said:
			
		

> 2. There are a multitude of different options for tone mapping including thresholds, pixel radius for luminance approximation, the dynamic range values over which the tonemapping is applied (selected via sliders in photomatix, and via the curves tool in photoshop). The key is you don't know in advance how much compression to apply which is why each image is different and why all the options are given.



Exactly. Don't you have any algorithmic descriptions?



			
				Garbz said:
			
		

> 3. Smoke coloured picture? What is the final result of your HDR? Remember a HDR image is not what you see on the net. All the images you see on the net have been original HDRs compressed via tonemapping to display in a normal dynamic range type of way. You should after combining 3 images end up with a 32bit image with wider dynamic range than you can display and by selecting an appropriate brightness get back any of the 3 original exposures taken. It sounds to me like you may be trying to map 3 images to a HDR in an 8 or 16bit domain. That won't work.



Ok, I used incorrect terminology, sorry. I don't need real HDR representation of the image, but only the compressed for ordinary monitors.



			
				Garbz said:
			
		

> I suggest if you want to play with this yourself have a look at some existing open source HDR programs http://qtpfsgui.sourceforge.net/, or http://sourceforge.net/projects/pfstools/



Thanks. And do you know the tool wich will help me in following: I have the image A. I have applied lot of color-mappings to it, contrast fixing etc. So I get the image B. Objects on both images are situated identically, but colors are different. I need a tool wich will build come graphs or other representations of the color change from A to B. Do you know such a thing?

All three questions are still open, can someone help me?


----------



## Helen B (Mar 18, 2008)

dum said:


> Of course, it is a kind of imitation, but I have seen and done several successful examples from a SINGLE picture. But for video you have no chance to make several shots with different exposure.



Could you shoot on film? Kodak Vision2 HD Scan Film has about 15 stops of dynamic range.

Best,
Helen


----------



## dum (Mar 18, 2008)

Helen said:
			
		

> Could you shoot on film? Kodak Vision2 HD Scan Film has about 15 stops of dynamic range.



No, I cannot and in the discussed case I'm working on the software tool. So, I'm interested in digital processing.


----------



## Helen B (Mar 18, 2008)

I was thinking about digital post-processing of film originated images. What video format are you working on?

Best,
helen


----------



## dum (Mar 18, 2008)

DV, HDV


----------



## intheQ (Mar 19, 2008)

You might try the reverse engineering route. Download the source code for an open source app such as _Qtpfsgui _and take a look at the algorithms they used. 

"Qtpfsgui 1.8.5 offers seven: Ashikhmin, Drago, Durand, Fattal, Pattanaik, Reinhard '02, and Reinhard '04. The names of these algorithms come from academic papers in which they were described." - Linux.com

You could also download Raanan Fattal's paper on _Gradient Domain High Dynamic Range Compression._ The cached pdf worked for me at this site, http://citeseer.ist.psu.edu/534533.html


----------



## dum (Mar 19, 2008)

Thats great information, intheQ. Thanks a lot. Can someone add something?

And especially (but not only) about reexposure.


----------

