In [19]:
import cv2
%matplotlib inline
from matplotlib import pyplot as plt
import math

In [6]:
IMAGE_PATH = './208.jpg'
input_image = cv2.imread(IMAGE_PATH)

In [7]:
def print_image(image):
    cv_rgb = cv2.cvtColor(image, cv2.COLOR_BGR2RGB)
    plt.imshow(cv_rgb)
    plt.show()
    
print_image(input_image)



In [8]:
result = cv2.resize(input_image, (200, 200), interpolation = cv2.INTER_AREA)

In [10]:
print_image(result)



In [15]:
height, width, channels = input_image.shape

In [22]:
if height > width:
    result = cv2.resize(input_image, (math.floor(200/height * width), 200), interpolation = cv2.INTER_AREA) 
    padding = 200 - math.floor(200/height * width)
else:
    result = cv2.resize(input_image, (200, math.floor(200/width * height)), interpolation = cv2.INTER_AREA) 
    padding = 200 - math.floor(200/width * height)

In [23]:
print_image(result)



In [31]:
top = math.floor(padding/2)
bottom = padding - top
final_result = cv2.copyMakeBorder(result,top,bottom,0,0,cv2.BORDER_CONSTANT,value=[0,0,0])
print_image(final_result)



In [ ]: