I have this image in OpenCV imgColorPanel = imread("newGUI.png", CV_LOAD_IMAGE_COLOR);
:
When I load it in with grey scale imgColorPanel = imread("newGUI.png", CV_LOAD_IMAGE_GRAYSCALE);
it looks like this:
However I want to remove the white background or make it transparent (only it's white pixels), to be looking like this:
How to do it in C++ OpenCV ?
You can convert the input image to BGRA channel (color image with alpha channel) and then modify each pixel that is white to set the alpha value to zero.
See this code:
This will save your image with transparency. The result image opened with GIMP looks like:
As you can see, some "white regions" are not transparent, this means your those pixel weren't perfectly white in the input image. Instead you can try