Last active
October 10, 2017 08:14
-
-
Save dimaxano/fef827446d6419ea55b8fbdfbca25bfd to your computer and use it in GitHub Desktop.
Code snippet for changing exact color in the image
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import numpy as np | |
import cv2 | |
data = cv2.imread(path) | |
r1, g1, b1 = 255, 0,0 # Original value | |
r2, g2, b2 = 255, 255, 255 # Value that we want to replace it with | |
blue, green, red = data[:,:,0], data[:,:,1], data[:,:,2] | |
mask = (red == r1) & (green == g1) & (blue == b1) | |
data[:,:,:3][mask] = [r2, g2, b2] | |
data = cv2.cvtColor(data, cv2.COLOR_BGR2GRAY) | |
cv2.imwrite("~/changed.tiff", data) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment