In [49]:
import cv2
import numpy as np
import matplotlib.pyplot as plt

%matplotlib inline

In [50]:
# do RGB thresholding

org_img = cv2.imread('img/rgb_test.png')  # read sample image

min = np.array([0,0,0],np.uint8)
max = np.array([0,0,255],np.uint8)        # threshold min and max limits (BGR)

mask    = cv2.inRange(org_img,min,max)    # create a mask
thr_img = cv2.bitwise_and(org_img,org_img # apply mask
                          ,mask = mask)

In [51]:
print ("Image Shape",org_img.shape)

img1 = cv2.cvtColor(org_img, cv2.COLOR_BGR2RGB) #convert BGR to RGB for Matplotlib use.
img2 = cv2.cvtColor(thr_img, cv2.COLOR_BGR2RGB) #convert BGR to RGB for Matplotlib use.

f, ax = plt.subplots(1, 2, figsize=(24,12))
ax[0].imshow(img1)
ax[0].set_title('Original Image', fontsize=20)

ax[1].imshow(img2)
ax[1].set_title('Thresholded Image', fontsize=20)
       
plt.show()


Image Shape (480, 480, 3)

In [ ]: