I'm doing some amateur image analysis using Python, specifically Numpy, PIL and OpenCV. However, I'm not too pleased with the performance of PIL, so I would like to port those parts of the code to OpenCV. This will also make it easier to port the code to C/C++ later on, if needed.

Anyways, I'm having some trouble with porting parts of my code, and would love some help here. Specifically, the parts I need changed is:

Function: Find the red, green and blue (R,G,B) intensity with the most pixels in the image. Currently done through the histogram. Input image is in the form of a Python PIL image.

Function: Serves as a simultaneous threshold of the RGB channals. If a certain RGB pixel is within a certain range (independent for R,G and B), it is coloured white. If not, it is discarded and coloured black. Input image is a Python PIL image.