So I am analyzing camera images and want to retrieve black letters from them. First I defined thresholds for all channels and applied them to the image, e.g.
low = [0, 0, 0]
up = [0.42, 0.42, 0.42]
Then, I retrieved a mask for further use from this by just thresholding my image with
mask = cv2.inRange(image, low, up)
Now this worked until I found that different light conditions made me run into problems. E.g., if the image is brighter, I could adapt the upper thresholds to 0.65
which would be good enough for a differentiation between black and white in all cases I analysed. BUT: Now other colors make problems, as many more lie within this interval. I figured that a second condition restricting all possible values to greyish colors would work, i.e. a condition only allowing for a certain variance between the values of the three channels for every pixel.
The question now is, how could I implement this second condition in a smooth way, so that a pixel with [0.4, 0.6, 0.4]
would be kicked out and one with [0.6, 0.62, 0.57]
would stay in (random examples, I'd adapt the parameters myself)? What is the smoothest way of combining these two that does not need timely iteration over the whole image?
Thanks a ton, this would help a lot!