import argparse
import cv2
import numpy as np

arg = argparse.ArgumentParser()
arg.add_argument("-i", "--image", required=True, help="Path to the image")
args = vars(arg.parse_args())

#cv2.imread loads the image and converst into numpy
image = cv2.imread(args["image"])


# SLPITTING
(B, G, R) = cv2.split(image)
cv2.imshow("Red", R)
cv2.imshow("Green", G)
cv2.imshow("Blue", B)
cv2.waitKey(0)

# MERGING
merged = cv2.merge([B, G, R])
cv2.imshow("Merged", merged)
cv2.waitKey(0) 
cv2.destroyAllWindows()

# Alterantive Method to show color channels
# We need to split the original image with split
# re-construct the image the image
zeros = np.zeros(image.shape[:2], dtype='uint8')
cv2.imshow("Red", cv2.merge([zeros, zeros, R]))
cv2.imshow("Green", cv2.merge([zeros, G, zeros]))
cv2.imshow("Blue", cv2.merge([B, zeros, zeros]))
cv2.waitKey(0)