For some bizarre reason I needed to transfer the histogram profile from one image to another image. Turning to Gimp, I decided to script it. I used script-fu, as I am still trying to learn python. The basic premise is to sample the histogram of both images, then convert them into an incremental function. Following that, you determine the transfer function to convert back from the one to the other. I realize that sounds complicated, but it isn't that bad. Here is a diagram:
So all I had to do was write a gimp script to do this. No Problem!
My initial test was with the simplest case, having a source histogram that is completely flat. This equates to an perfectly linear incremental histogram. It also happens to be the same as the Gimp command Colour->Auto->Equalize. Or so I though. Initially I was only using the value, but I couldn't match the results of the Equalize function. It was after examining the resultant histograms that I determined that Equalize works independently on each of the RGB channels, so I modified the script to also allow that. Knowing the algorithm worked, I added the option to take the histogram from another image layer, rather than the flat histogram case.
Lastly, I found the gimp histogram function to be quite slow (as every call analyzes the entire image). The solution was to offer a (default) option to re-sample the images first.
On the left are a photo of a city street in Toronto, and one of a hillside in Israel, along with their histograms. On the right is the result of remapping each of them with the other's histogram, also showing the resultant histogram. The hill was mapped using value, and the city street was mapped using independent RGB.
Running the script using the independent RGB options takes the longest, as it has to process each channel independently. Also there is still the occasional full crash of gimp 2.6.4 when running the precompiled windows binary. Running my on compile of 2.6.6 I have not experienced this crash.
EDIT: I forgot to mention the script shows up as Colours->Map->Histogram Match... in the menus!
You can download the an updated version of the script here.
Tracked: May 08, 19:04
Tracked: May 21, 02:11