In [56]:
%matplotlib inline
import cv2
import matplotlib.pyplot as plt
In [57]:
bgr = cv2.imread("image077.png")
rgb = cv2.cvtColor(bgr, cv2.COLOR_BGR2RGB)
plt.imshow(rgb)
Out[57]:
In [58]:
r = rgb[:, :, 0]
g = rgb[:, :, 1]
b = rgb[:, :, 2]
In [59]:
field = (g > 50) & (r < 50) & (b < 100)
plt.imshow(field, cmap='gray')
Out[59]:
In [60]:
hsv = cv2.cvtColor(bgr, cv2.COLOR_BGR2HSV)
In [62]:
# define range of blue color in HSV
lower_green = np.array([50,50,50])
upper_green = np.array([100,255,255])
In [63]:
# Threshold the HSV image to get only green colors
mask = cv2.inRange(hsv, lower_green, upper_green)
In [64]:
# Bitwise-AND mask and original image
res = cv2.bitwise_and(rgb, rgb, mask=mask)
In [65]:
plt.imshow(res)
Out[65]:
In [ ]: