Identification of colors in a transparent bottle under different lighting conditions - opencv

I am trying to identify set of colors in bottles which are kept serially using OpenCV. I have tried the following procedures but most of them fail in different colors of ambient light.
Image segmentation using Histogram but fails for ambient light condition
Image segmentation using K-means but that also fails for ambient light colors.
Tried the color masking technique by defining the colors I am looking for but that isn't too great too.
White balancing the image and then applying the above techniques. But that technique gives problematic colors normal white color background.
Any recommendation on this would be much appreciated. A reference image is attached.
I am looking for the following result. I would like to detect light yellow, light yellow, peach, peach, orange, orange, orange, orange, ivory, pink.

Related

Blend design to T Shirt without losing design color

I am just learning to use Photoshop CS2 and trying to blend my designs on my t shirt mockups.
I am able to blend the design successfully but I loose the original color (white) of my design after blending and setting opacity to normal and 50%. The design color becomes like the shirt color.
How do I successfully blend designs on t shirt mockup without losing my design color? What are the correct settings to keep my original design color intact after blending?
I successfully blended my artwork to my base but lost the color of my artwork (white) after blending. I expected to see my blended artwork on t shirt mockup in its original color (white). The blending is fine, just the loss of artwork color.
Many thanks for help with this.

Segmenting dark spots from a light background?

I need to perform automatic segmentation of dark blue spots on light yellow paper. Here's a very simple example:
In this case, a simple threshold based on hue or brightness works well. But here are some more challenging real-world examples:
Clearly a simple hue/brightness threshold will fail when dealing with shadows, exposure issues, and small stains where the color is blurred from the background.
I've tried Otsu's method for adaptive thresholding, but it also fails to account for shadows - and produces erratic results when analyzing "blank" cards.
Is there a form of localized thresholding that might work better? I've also considered edge detection, but am unsure how to transform the results into the needed binary image. Any suggestions are appreciated.

Best background substraction technique

In my latest project I am required to train a deep convolutional neural network to detect football players. The problem is that all my positive exapmles are extracted from 3-4 videos and the grass is almost the same colour in each one. I am looking for a background substraction method which will isolate the human figure from the green background. Then, I can change the colour of the grass to a different hue. Is it a better idea to perform an edge detection or a color segmentation algorith? Any ideas? Thanks
Problem
How can I address that the grass color (background) is all the same in training set for my CNN?
Solutions
Is it a problem?
One way you can test to see if it is a problem is to see if your trained model can handle color changes without having to be retrained. Feed in the test images with the colors reorderd (blue becomes red, red becomes green, green becomes blue) and see how well it does. Try de-colorizing the image so that all color layers are just black and white.
If your CNN preforms just as well (within the uncertainty in your accuracy measurements) then there is no problem.
Maybe color is the problem
Perhaps color is a problem. Try your whole CNN with just b/w instead of 3 colors. If trained using b/w is able to preform just as well, then the b/w model could be the bounds detector and your color CNN could be used for something else like team detection.
Style transfer
Use a style transfer NN to convert you training set images from having green grass to have the "style of" brown grass.
Specifically create a grass detector
Train a CNN to specifically detect grass in each NxN (11x11) patch. Use that to create a bit mask of the same shape as your input image which is a mask of "is this pixel part of grass or not". Multiply the output of that with the input image dot-wise to create a grassless image. Visually verify that it is indeed grasses. Apply the invers of the mask to a new background and add the grassless image and the new background.
A simple solution might be color segmentation i.e. select color range (of grass) and assign it a constant value OR you can change the pixel values in the green channel.

Background subtraction with reflective material

I am using background subtraction method to detect moving objects. Because their type in my experiment is reflective material object, so it causes difficulty for detecting. How could I resolve it?
Thank you!
EDIT: I'm using Background subtraction MOG2 (in OpenCV). OpenCV version is 3.10
EDIT 1: Updated the result when apply to HSV colour space
Step 1: Convert to HSV colour space
Step 2: Apply MoG2
I'm assuming your camera is non-moving, you know the background model and you are using something like MOG detector. The simplest approach is to use color space that separates luminance from hue and saturation - one such example is HSV color space. OpenCV provides cvtColor function to convert i.e. form BGR (default) to HSV color space. Later you can use just hue and saturation channel to avoid influence of value variations (light). This however won't work for extremely shiny objects, like plastic or shiny metal lit by sunlight that appears to be white to the camera.
Another way you can deal with this problem is to use motion tracking - i.e. optical flow. If you are really interested and want to get more into details, I can refer you to some specific papers.

Detect red color in different illumination or background

I can't find the best way to detect red color in different illumination or background.
I found that there's YCbCr color space which is good for red or blue color detection (actually I need to detect blue color too). The problem is that I can't figure out which threshold to use in different lightning. For example in sunny weather this threshold equals 210 (from 255), when in cloudly weather this threshold equals 130.
I use OpenCV library to implement this.
Thanks for any help or advice.
Yes, HSV is usually used for such purpose. In HSV you can tell that whatever is brightness etc, red is what is needed. I also recommend to look into two places. One is simple tutorial http://aishack.in/tutorials/tracking-colored-objects-in-opencv/ and another is to take a book Learning OpenCV and use examples of histograms from there. They do exactly what you need. Using HSV and Histograms makes your solution solid.
HSV color space should be more robust to change of illumination.

Resources