import cv2
from matplotlib import pyplot as plt
replicate = cv2.copyMakeBorder(img_h,to_size,bottom_size,left_size,right_size,
borderType=cv2.BORDER_REPLICATE)
reflect = cv2.copyMakeBorder(img_h,to_size,bottom_size,left_size,right_size,
borderType=cv2.BORDER_REFLECT)
reflect101 = cv2.copyMakeBorder(img_h,to_size,bottom_size,left_size,right_size,
borderType=cv2.BORDER_REFLECT_101)
wrap = cv2.copyMakeBorder(img_h,to_size,bottom_size,left_size,right_size,
borderType=cv2.BORDER_WRAP)
constant = cv2.copyMakeBorder(img_h,to_size,bottom_size,left_size,right_size,
borderType=cv2.BORDER_CONSTANT,value=0)
plt.subplot(231), plt.imshow(img_h, 'gray'), plt.title("ORIGINAL")
plt.subplot(232), plt.imshow(replicate, 'gray'), plt.title("replicate")
plt.subplot(233), plt.imshow(reflect, 'gray'), plt.title("reflect")
plt.subplot(234), plt.imshow(reflect101, 'gray'), plt.title("reflect101")
plt.subplot(235), plt.imshow(wrap, 'gray'), plt.title("wrap")
plt.subplot(236), plt.imshow(constant, 'gray'), plt.title("constant")
plt.show()
效果如下