Improve recomposite color correct by fitting (s*v, v) instead of (s, v) #863
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This is an update to the change to implement #597. It attempts to improve the original "Linear" method by fitting to (s*v, v) instead of (s, v).
When correcting, S is unstable when V is very low (small changes in RGB yield big changes in S for very dark pixels). The linear method ends up doing poor color correction when there are very dark pixels in the region outside the mask that is used to sample for color correction. By fitting to S*V, those perturbations don't influence the fit as much.
My testing indicates that this improves some pathological cases with dark regions, and isn't noticeable one way or the other on other cases. Will add some examples in #597 .
Added this as an additional color correction method "Linear2", could also just replace the original Linear method depending how much you weigh backwards compatibility versus code proliferation. It would also be more efficient to map (r,g,b) <-> (h,s*v,v) directly in the rgb2hsv utility methods instead of computing (r,g,b) <-> (h,s,v) and multiply/divide, but I thought that might be less readable.