Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

You can simply use numpy to do this.

image = np.zeros((400,400,3), dtype="uint8")
image[np.where((image==[0,0,0]).all(axis=2))] = [255,255,255]

This will change all pixels in image that have a value of [0,0,0] to [255,255,255].

Best regards

You can simply use numpy to do this.

image = np.zeros((400,400,3), dtype="uint8")
image[np.where((image==[0,0,0]).all(axis=2))] = [255,255,255]

This will change all pixels in image that have a value of [0,0,0] to [255,255,255].

After your inRange() operation you get an image in black and white, so you have just one color channel. In that case you have to use:

image[np.where((image==[0]).all(axis=1))] = [255]

This will change all rows in your image that are completely black to white. To change not only the rows that are completely black omit the call to numpy.all(). Use:

image[np.where(image == [0])] = [255]

Best regards