Created
October 20, 2022 16:48
-
-
Save victormurcia/b8e4351cd7952175ff02e54e90b412a9 to your computer and use it in GitHub Desktop.
masking colors
This file contains hidden or 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
| #Remove green background/field from image prior to clustering | |
| green = np.array([60,255,255]) #This is green in HSV | |
| loGreen = np.array([30,25,25]) #low green threshold | |
| hiGreen = np.array([90,255,255]) #Upper green threshold | |
| loBlue = np.array([0,25,25]) #low red threshold | |
| hiBlue = np.array([30,255,255]) #Upper red threshold | |
| loRed = np.array([120,25,25]) #low blue threshold | |
| hiRed = np.array([180,255,255]) #Upper blue threshold | |
| #Convert image to HSV | |
| hsv = cv2.cvtColor(rgb_img, cv2.COLOR_BGR2HSV) | |
| gmask = cv2.inRange(hsv, loGreen, hiGreen) | |
| rmask = cv2.inRange(hsv, loRed , hiRed) | |
| bmask = cv2.inRange(hsv, loBlue , hiBlue) | |
| gresult = rgb_img.copy() | |
| bresult = rgb_img.copy() | |
| rresult = rgb_img.copy() | |
| gresult[gmask==255] = (255,255,255) | |
| bresult[bmask==255] = (255,255,255) | |
| rresult[rmask==255] = (255,255,255) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment