Using Open CV to detect greenhouse crop detection & infestation

It looks like you have made progress with the color detection part. Fine tuning that part will be up to you, after you determine the color spectrum in your final images.

Here is some OpenCV Python code that may be useful:
https://docs.opencv.org/master/df/d9d/tutorial_py_colorspaces.html

That is similar to the process that I was going to suggest, but you need to make sure you know the color ranges first. HSV is probably the way to address this. I notice that you have already figured this out.

The next step is to change the non-black pixels to pure white (255, 255, 255) so your image is now just black and white. That will serve later as a mask.

Check the three images at the link above. The second shows artifacts. You would use morphological operators (erode, dilate, open, close, etc) to eliminate isolated small groups of pixels. That will fill in any small artifacts with white pixels.

Then finally, you use that as a ‘mask’ over the original image. That is done in the sample code by ‘bitwise and’. This will give you an image with just the pixels that you need to work with. All background should now be filtered out, so any subsequent operations (GLCM, neural nets, etc) will not be mis-triggering on background objects.

This in itself does not address the larger groups of pixels like the white ‘mealybugs’ above. I don’t think those were even in your original posts, were they? In fact, those may appear very different if your cameras are mounted up high. Any optimization that you attempt on close-ups may not work on distance photos. There are a number of ways to address specific cases like that after you have the main part of your code fine-tuned, and have the mask system working. I suggest that you move to actual representative images to do this.

PS: Get some ladybird beetles for the mealybugs.