Created
May 4, 2016 14:57
-
-
Save ksoda/06efa6c1749747ba9b8343e3584c444c to your computer and use it in GitHub Desktop.
OpenCV
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 cv2, matplotlib | |
import numpy as np | |
import matplotlib.pyplot as plt | |
bgr_img = cv2.imread('images/landscape.jpg') | |
img = cv2.cvtColor(bgr_img, cv2.COLOR_BGR2HSV) | |
blue_min = np.array([100, 0, 0], np.uint8) | |
blue_max = np.array([140, 255, 255], np.uint8) | |
wh_min = np.array([0, 0, 180], np.uint8) | |
wh_max = np.array([180, 60, 255], np.uint8) | |
blue = cv2.inRange(img, blue_min, blue_max) | |
white = cv2.inRange(img, wh_min, wh_max) | |
inv_mask = cv2.bitwise_or(white, blue) | |
mask = cv2.bitwise_not(inv_mask) | |
plt.imshow(mask, cmap=plt.get_cmap('gray')) | |
mask_rgb = cv2.cvtColor(mask, cv2.COLOR_GRAY2RGB) | |
masked_rgb = cv2.bitwise_and(cv2.cvtColor(bgr_img, cv2.COLOR_BGR2RGB), mask_rgb) | |
plt.imshow(masked_rgb) |
Author
ksoda
commented
May 4, 2016
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment