1

I am attempting to extract the color features of tennis ball in an image. To make it easier, I thought that transferring the tennis ball to a white canvas and then extracting the features would be better. I am extracting the color features via a histogram.

I have used a mean shift image segmentation algorithm on a frame from a video where the tennis ball is falling (https://i.stack.imgur.com/etG2n.jpg). Originally, I converted an the frame to gray scale and made an histogram from the updated frame, but I realized that it was ineffective because I am trying to extract the color features. Therefore, I am now trying to transfer the the tennis ball to a white canvas and so its easier to extract the color features from the tennis ball into a histogram.

dvargasp
  • 61
  • 1
  • 5
  • Share what you've tried so far and ask about specific problems with that; just asking people here to create a solution or open "how to" questions is not what StackOverflow is for. – Grismar Aug 05 '19 at 01:42
  • What do you have currently? Is the tennis ball in the image already segmented? If so, have you considered using the segmented binary image as a mask for histogram calculation? – Joel Filho Aug 05 '19 at 02:14
  • I have used a mean shift image segmentation algorithm on a frame from a video where the tennis ball is falling. Originally, I converted an the frame to gray scale and made an histogram from the updated frame, but I realized that it was ineffective because I am trying to extract the color features. Therefore, I am now trying to transfer the the tennis ball to a white canvas and so its easier to extract the color features from the tennis ball into a histogram. I have not considered using the segmented binary image as a mask for histogram calculation, though. I will now. – dvargasp Aug 05 '19 at 02:34
  • Post images of your input and processed image to some free hosting service and put the URL here. – fmw42 Aug 05 '19 at 02:34
  • https://imgur.com/a/lbqOx6S – dvargasp Aug 05 '19 at 02:39

1 Answers1

3

From your segmented image:

We can notice that the color difference is very obvious. In such cases, we can simply convert to a color space that can separate these colors better for us, such as HSV. In HSV, the hue channel contains the color variation data. In this image, this is the hue channel:

From this, all you need is to analyze the image histogram and determine a simple threshold value. By applying the threshold, you reach this:

Here's a tutorial from the OpenCV documentation on how you can do this in Python. If you can't select this threshold manually, you can use Otsu's binarization method (OpenCV tutorial) on the H channel (splitting from the HSV image).

Then you can then use this binary image as a mask to extract more features. You don't need to transfer the image to a white/black background, but, if you want to, you can just apply this mask. See OpenCV - Apply mask to a color image.

Joel Filho
  • 1,300
  • 1
  • 5
  • 7