A recurrent problem in OpenCV is how to apply single-channel functions to multi-channel images (e.g. color depth reduction with cv::LUT). The general case is simple enough:
- Split image across channels;
- Apply function to separate channels;
- Assemble result image from channel outputs.
But it's sort of silly that I have to code this same algorithm over and over, when the only thing that changes is the function applied to the channels (and the odd extra parameters).
Does OpenCV provide a generic implementation of the algorithm above – some mechanism for applying single-channel functions to each channel of multi-channel images?
If not, how do you suggest solving this problem in C++? A macro could do the trick, but it would be a somewhat complicated macro, large and ugly. I'd prefer a more elegant solution if available.