#!/usr/bin/env python

import numpy as np
import argparse
import cv2

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

image = cv2.imread(args["image"])
cv2.imshow("Original", image)

gray = image.copy()
gray = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)
blurred = cv2.GaussianBlur(gray, (5, 5), 0)
cv2.imshow("Image Processing", np.hstack([gray, blurred]))

(Tbin, threshBin) = cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY)
(TbinInv, threshbinInv) = cv2.threshold(blurred, 200, 255, cv2.THRESH_BINARY_INV)
cv2.imshow("Threshold Binary", np.hstack([threshBin, threshbinInv]))

coins = cv2.bitwise_and(image, image, mask=threshbinInv)
cv2.imshow("Coins", coins)

cv2.waitKey(0)
