import numpy as np
import cv2

ls

file_adr = 'Me1.png'

img = cv2.imread(file_adr,cv2.IMREAD_GRAYSCALE) # Alternate- 0 cv2.IMREAD_GRAYSCALE - 0 
cv2.imwrite('Me1_gray.jpg', img) # 
img2 = cv2.imread('Me1_gray.jpg', cv2.IMREAD_COLOR)

"""
Explanation: Getting Started with Images
cv2.imread, cv2.imshow, cv2.imwrite
Reading an image - cv2.imread()
cv2.imread() has two arguments, one address of the image
and the other as following arguments: (specifies the way image should
be read)
cv2.IMREAD_COLOR : loads a color image. Transparency of image is 
neglected, it is default flag. [Alternate : 1]
cv2.IMREAD_GRAYSCALE : Loads image in grayscale mode. [Alternate : 0]
cv2.IMREAD_UNCHANGED : Loads image such as including alpha channel.
[Alternate : -1]
End of explanation
"""


cv2.imshow('Image', img)
cv2.waitKey(0)
cv2.destroyAllWindows()

"""
Explanation: Showing an image - cv2.imshow()
To display an image in window, use cv2.imshow() 
Window automatically fits to image size.Two Arguments: 
1. Window name (string)

Our image
End of explanation
"""


cv2.namedWindow('image', cv2.WINDOW_AUTOSIZE)
cv2.imshow('Image', img)
cv2.waitKey(5)
cv2.destroyWindow('Image')

cv2.waitKey?

help(cv2.namedWindow)

"""
Explanation: About cv2.waitKey() function:
Keyboard binding function   Argument in milliseconds
If zero is passed, it waits indefinitely for a key stroke.
About cv2.destroyAllWindows():
Destroy all windows we created
To destroy any specific window,
use cv2.destroyWindow(), pass argument with window's name.
End of explanation
"""


cv2.imwrite('Me1.jpg', img)

import numpy as np
import cv2

img2 = cv2.imread('Me1.png', -1)
cv2.imshow('IMAGE', img2)
k = cv2.waitKey(0) & 0xFF
if k == 27:
    cv2.destroyAllWindows()
elif k == ord('s'):
    cv2.imwrite('Oh.png', img2)
    cv2.destroyAllWindows()

"""
Explanation: Writing an Image
Use the function cv2.imwrite() to save an image.
2 Arguments:

First argument is file name
Image you want to save
End of explanation
"""


import numpy as np
import cv2
from matplotlib import pyplot as plt
import seaborn; seaborn.set()
img = cv2.imread('Me1.png',0)
plt.imshow(img, cmap = 'gray', interpolation='bicubic')
# plt.xticks([]), plt.yticks([]) # To hide tick values on x & y -axis
plt.show()
# 255, 255, 0 -  R G B

"""
Explanation: Using matplotlib
End of explanation
"""


