Ask Your Question

Revision history [back]

You could use OpenCV's inrange function that will threshold based on color channel ranges. https://docs.opencv.org/3.4/da/d97/tutorial_threshold_inRange.html

image description

In this screen capture, the 2nd image from the left is the result of inrange on the background color. The 3rd image is the result of inrange on one of the yellow colors. The 4th image is the result of inrange on one of the blue colors. You would need a loop to find a foreground region, get its color, use inrange to find contours/blobs of this color, then remove those foreground regions. Continue the loop until there are no more foreground regions. You can try this tool for yourself at pixelprocessing.com