PS: -AFTER- you get everything above working and fine-tuned, here’s how you address the mealybugs, and maybe other problems:
Do a separate pass, with all the steps above, but this time you would just use the color characteristics of the white mealybug pixels. You can then use GLCM to detect their texture. It will be very different from the smoother white pipes in your earlier photos.
The GLCM output matrix shows transitions between various gray levels. Transitions to/from black should be on the outer edge, so you can ignore them. That’s another advantage of turning all the background pixels solid black.
The point of all this is to extract as many useful features as possible. Then you can use a non-CNN neural net (‘fully connected nn’) or support vector machine to sort out the decisions.