Reinhard05 turned to to be one of the best tone mapping algorithms... but not with the default parameters.
My simple intention was to just expose all params, including these that ware hardcoded.
After doing so however, some problems surfaced. This patch fixes those, and addes some more touch-ups.
Here is the list of changes:
Exposed color correction and ligt adaptation parameters for the algorithm.
Fix crash when "complete algorithm" is actually used.
Fix the way log-average and average luminance are computed, both of which ware wrong.
( the log-av error had little visual impact, and the lum av was not used because of the hardcoded params. Ones however other values are used the problem is pronounced. For instance, setting adaptation to 0 and varying the color correction 'c' param changes not only the colors, but also the brightnes of the image!
This is ecause the incorrect lum av computation. )
Added some common sense optimizations.
(basically skipping big chunks of code if it is not needed for particular params values.
NOTE that a farther optimization is possible if all of the algorithm prerequisites (lum, lum av, ch av - all needing all-pixels loop), none of which changes when user params are modified, are not invalidated every time the tone mapping is run. This can drop the time by at least 1/3 if not more. I will look into it also. )
Attached are are the modified cpp files. The appropriate changes to the headers are as follows:
freeimage.h : 952
FreeImage_TmoReinhard05(FIBITMAP *src, double intensity FI_DEFAULT(0), double contrast FI_DEFAULT(0), float light_adapt FI_DEFAULT(1), float color_adapt FI_DEFAULT(0) );
ToneMapping.h : 34
LuminanceFromY(FIBITMAP *dib, float *maxLum, float *minLum, float *worldLumL, float *worldLum);
These changes, because of the default params, dont break the API, binary compatibility is however compromised and, for instance, freeimageplus needs to be recompiled.
Anonymous
Reinhard05 all params exposed and working
Hi Mihail,
Thanks for the patch. I've added your suggestions to the CVS.
Using 4 parameters for FreeImage_TmoReinhard05 would break the FreeImage binary compatibility, so I've added a new function named FreeImage_TmoReinhard05Ex.
There was a bug with the complete algorithm (pointer initialization and calculation of Lav).
However, I'm not sure the formula for the key, using Llav is wrong. The reinhard paper and the various implementations differ on this point.
Using the 'world adaptation luminance' for Llav is perfect for some academic images such as 'memorial.hdr', but it no longer work with most images as k is often < 0. So I've re-added my initial fix for this, together with explicit comments.
You says 'Reinhard05 turned to be one of the best tone mapping algorithms': when the paper appeared in january 2005, I wrote immediatly to Reinhard in order to have his paper, as I was also thinking it could be a very good algorithm. I was a little disappointed after doing many tests, but it's true that I didn't test a lot with the a and c parameters. To my mind, an algorithm with more than 2 parameters is unusable by the public (too much complexity).
Now after doing more tests with 4 parameters, what I could see is that you can effectively obtain very good results. The problem is however that each image has its own set of parameters: you cannot use a generic set of parameters, as in Drago03, that work with almost any kind of image. So this is not what I would call 'the best tone mapping algorithm'.
I will update FreeImagePlus very soon in order to use these 4 parameters easily.
Hervé
Thanks for the interest.
I just wanted to add that if we pay the prize of adding a new function (Ex)
we should make it possible to cache/pass-as-params the algo. prerequisites (Llav and Cav), because, as I said, they are expensive and do not change.
Hi,
I don't understand how you can cache Llav and Cav : can you explain ?
Hervé
I have not thought of any concrete implementation, just, if they change only when the image changes, they should not be computed if its not changed...seams to be The Right Thing.
The easiest way to do this, is, of course, to let the user pass them as parameters to the tone mapping func. (side by side with the image itself). This however burdens the user with additional management, and can also be suboptimal because the user will have these computed even if not needed (not to mention there no public functions to do that :).
I will look for some better way to do that, when I have time.
Since release 3.13.0 is now out with a new function named FreeImage_TmoReinhard05Ex, I will close this bug.
I don't see any useful implementation of a cache mechanism here.
However, if such a cache is made available, please open another tracker.
Hervé