Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR PYTHON

opencv convert black pixels to white

import cv2

img = cv2.imread("path/to/image")

th = 20 # defines the value below which a pixel is considered "black"
black_pixels = np.where(
    (img[:, :, 0] < th) & 
    (img[:, :, 1] < th) & 
    (img[:, :, 2]  th)
)

# set those pixels to white
img[black_pixels] = [255, 255, 255]
 
PREVIOUS NEXT
Tagged: #opencv #convert #black #pixels #white
ADD COMMENT
Topic
Name
4+2 =