After I posted my previous update, I went and tryed the new code on a new image, which immediately failed miserably.
The problem was detection of the end of sky. The new image was much noisier, so the old algorithm was badly fooled by a pixel with a high error due to noise.
The solution was a completely new approach -- the new algorithm builds a 2d model of a small region of the sky -- actually 3 models, one each for R,G,B. The model also tracks errors of pixels in the sample used for the model, then examines the next pixel "down" (i.e. a larger y value), and tests to see if the next pixel, and the one following both fall outside a reasonable margin of error. There are nuances beyond that but that's the basic idea. The new algorithm is much more robust, and probably more precise too.
I have also replaced the Nelder-Meade optimization with Levenberg-Marquardt.
I have also vectorized all the colorspace type of calls.
It now runs a zillion times faster.
I have modified models that predict the Hue, Saturation and Value for a given pixel in the sky. I looked at lots of plots of actual HSV, and predicted HSV.
A good solid month of work on this, many dead ends, and I hope it is functional in most cases now.
At this point, I'm going to call it alpha code, and move on to documentation.
Current, best branch is at:
I would greatly appreciate reports on compilation problems. I have NOT worked with the CMake files, I've only updated my local Makefile.