-2

I am currently working on a python program that records a part of my screen (800x600 pixels) at about 20 frames per second with openCV. After some processing the result is displayed in a different window, but I struggle with the processing part:

I would like to eliminate all kinds of greyish colors. That means I would like to turn all pixels black where the three RGB values are equal (or similar). It seems like looping through every pixel is quite slow and won't handle the target of 20fps. This topic helped a lot for reducing the color of my input by using masks but won't work for eliminating grey.

Is there a good way to accomplish that?

Pyrole
  • 1
  • Use HSV. This can remove any color in a range (inRange) you want. Also, post the image you are working on.. – lucians Apr 27 '18 at 14:55
  • Using HSV is a very nice idea. That didnt come to my mind but is the perfect solution for me, thanks. Unfortunately I can't post an image, because it is video footage I am working with – Pyrole Apr 27 '18 at 16:08

1 Answers1

0

You can use diff function of numpy to find the difference between RGB elements and set a threshold to make grayish pixels black.

# a: nxnx3 numpy array
thresh = 2
indices = np.where(np.sum(np.abs(np.diff(a, axis=2)), axis=2) < 1)
a[indices[0], indices[1]] = [0, 0, 0]
galmeriol
  • 461
  • 4
  • 14