import cv2
import numpy as np
from matplotlib import pyplot as plt
from PIL import Image
import os
import argparse


def ParseArguments():
    parser = argparse.ArgumentParser(description="Sample usage of argparse     (read image, display color and bw, save bw) ")
    parser.add_argument('--input', required=True, help='Input image (default: %(default)s)')  
    parser.add_argument('--output', default=None, required=False, help='Output image (default: %(default)s)')
    parser.add_argument('--text',  default="Sample text", required=False, help='Sample text (default: %(default)s)')  
    args = parser.parse_args()
	
    return args.input, args.output, args.text
    
	 
input_file , output_file, sample_text=  ParseArguments()
     
print("Text: ", sample_text)
     
print("Input file   =", input_file)

#Wczytanie i wyswietlenie obrazka

img = cv2.imread(input_file)


#Na figure 1 wyswietlim
plt.figure(1)
plt.imshow(cv2.cvtColor(img, cv2.COLOR_BGR2RGB))


#Robimy obrazek czarno-bialy - po prostu odczytujemy jeden kanal, wysw. go na figure 2


img_gray=img[:,:,0]
plt.figure(2)
plt.imshow(img_gray, cmap=plt.get_cmap('gray'))


#Pokazujemy wszystko:

plt.show()


#Jesli output_file podany - zapisujemy czarnobialy obrazek
if(output_file!=None):
    print("out  =", output_file)
    cv2.imwrite(output_file,img_gray)
 
