#!/usr/bin/env python

######################
#   Analog video degradation simulator - BW display script
#   Version 1.1
#   polprog 2019
#   http://polprog.net/
#   3 clause BSD licensed
######################


import imageio
import matplotlib.pyplot as plt
import matplotlib.image as mpimg
import matplotlib.gridspec as gspc
import numpy as np
import os
import sys

# Rec.709 Luma calculation coefficients
COEF_R = 0.2126
COEF_G = 0.7152
COEF_B = 0.0722


if(len(sys.argv) != 2):
    print("Usage: " + sys.argv[0] + " <file> ")
    exit(1)

impath = sys.argv[1]

print("Loading ", impath)

imag = imageio.imread(impath)

print("Image shape is " + str(imag.shape))

# Create a B/W version of the image
luma = imag[:, :, 0] * COEF_R + imag[:, :, 1] * COEF_G + imag[:, :, 2] * COEF_B

print("Luma shape is " + str(luma.shape))

fig, plots = plt.subplots(1, 2, squeeze=True,
                          gridspec_kw={"hspace": 0.5, "wspace":0.7},
                          constrained_layout=True,
                          figsize= (20, 20),)

plotin = plots[0].imshow(imag, cmap="Greys_r")
plots[0].set_title("Input")

plotout = plots[1].imshow(luma, cmap="Greys_r")
plots[1].set_title("Output")

plt.show()
