####################################################  
#
# 	@ Authors : SEKHRI Aymen
# 				MOHAMMED HACENE Tarek
#	
# 	@ Hint: you have to install all requirements
# 			from requirements.txt                    
#
####################################################  

import numpy as np
import cv2 as cv
import matplotlib.pyplot as plt


# load the image
onion_img = cv.imread("onion.png")

# Store height and width and channels of the image
row, col, chs = onion_img.shape

# Store the spectral resolution
dtype_img = onion_img.dtype # This will give you: uint8

def translation(img, trans):

	"""
	args: 
		- img: absolute path to the image
		- trans: must be a tuple (row_trans, col_trans)
	"""
	# read the image
	image = cv.imread(img)
	# retrieve the height and the width
	height, width = image.shape[:2]
	# retrieve the params of translation
	row_trans, col_trans = trans
	# Create the translation matrix
	T = np.float32([[1, 0, col_trans], [0, 1, row_trans]])
	# Apply the T matrix: T*M 
	img_translation = cv.warpAffine(image, T, (width, height))
	# show the images
	cv.imshow("Original Image", image)
	cv.imshow('Translation Image', img_translation)

	# Don't destroy the images until the user do
	cv.waitKey()
	cv.destroyAllWindows()


# translation 20 pixel to the right
translation("onion.png", (0, 20))
# translation 50 lines and 100 cols to the right
translation("onion.png", (50, 100))
# remove the peper from the image using translations
translation("onion.png", (40, 40))




[((17, 12, 17, 34), 'cv2.imread', 'cv.imread', ({(17, 22, 17, 33): '"""onion.png"""'}, {}), "('onion.png')", True, 'import cv2 as cv\n'), ((33, 9, 33, 23), 'cv2.imread', 'cv.imread', ({(33, 19, 33, 22): 'img'}, {}), '(img)', True, 'import cv2 as cv\n'), ((39, 5, 39, 55), 'numpy.float32', 'np.float32', ({(39, 16, 39, 54): '[[1, 0, col_trans], [0, 1, row_trans]]'}, {}), '([[1, 0, col_trans], [0, 1, row_trans]])', True, 'import numpy as np\n'), ((41, 19, 41, 59), 'cv2.warpAffine', 'cv.warpAffine', ({(41, 33, 41, 38): 'image', (41, 40, 41, 41): 'T', (41, 43, 41, 58): '(width, height)'}, {}), '(image, T, (width, height))', True, 'import cv2 as cv\n'), ((43, 1, 43, 35), 'cv2.imshow', 'cv.imshow', ({(43, 11, 43, 27): '"""Original Image"""', (43, 29, 43, 34): 'image'}, {}), "('Original Image', image)", True, 'import cv2 as cv\n'), ((44, 1, 44, 48), 'cv2.imshow', 'cv.imshow', ({(44, 11, 44, 30): '"""Translation Image"""', (44, 32, 44, 47): 'img_translation'}, {}), "('Translation Image', img_translation)", True, 'import cv2 as cv\n'), ((47, 1, 47, 13), 'cv2.waitKey', 'cv.waitKey', ({}, {}), '()', True, 'import cv2 as cv\n'), ((48, 1, 48, 23), 'cv2.destroyAllWindows', 'cv.destroyAllWindows', ({}, {}), '()', True, 'import cv2 as cv\n')]