-1

I'm working with OpenCV on this kind of an image:

enter image description here

I have a numpy array which contains different colors, let's say I consider this color written in BGR: [65 71 72] I want to get rid of this color from my image leaving it with black spaces after this color. As far as I know I have to convert my image into gray scale and then apply a mask BUT in mask I say what are lower and upper boundaries of a color, while idk what are the boundaries for this or any color, as well as what is the gray scale representation of this color. I read about many different techniques for thresholding but all examples deal with colors like (255 0 0).

Nimantha
  • 6,405
  • 6
  • 28
  • 69
szymill00
  • 21
  • 1
  • 7

1 Answers1

6

You can apply inRange from OpenCV directly on the BGR color-space to subtract the desired color:

import numpy as np
import cv2

img = np.array([ 
    [[1, 2, 3], [2, 3, 1], [3, 1, 2]], 
    [[4, 5, 6], [65 71 72], [6, 4, 5]], 
    [[7, 8, 9], [8, 9, 7], [9, 7, 8]]], dtype=np.uint8)

lower = np.array([65 71 72])
upper = np.array([65 71 72])

mask = cv2.inRange(img, lower, upper)

masked = cv2.bitwise_and(img,img, mask=mask)

result = img - masked
Bilal
  • 3,191
  • 4
  • 21
  • 49