import cv2
import matplotlib.pyplot as plt
import numpy as np
#flower=cv2.imread(‘flower.jpg‘,cv2.IMREAD_GRAYSCALE)
flower = cv2.imread(‘flower.jpg‘)
#边界填充
top_size,bottom_size,left_size,right_sie = 50,50,50,50
replicate = cv2.copyMakeBorder(flower,top_size,bottom_size,left_size,right_sie,borderType=cv2.BORDER_REPLICATE)
reflect = cv2.copyMakeBorder(flower,top_size,bottom_size,left_size,right_sie,borderType=cv2.BORDER_REFLECT)
reflect101 = cv2.copyMakeBorder(flower,top_size,bottom_size,left_size,right_sie,borderType=cv2.BORDER_REFLECT_101)
wrap = cv2.copyMakeBorder(flower,top_size,bottom_size,left_size,right_sie,borderType=cv2.BORDER_WRAP)
constant = cv2.copyMakeBorder(flower,top_size,bottom_size,left_size,right_sie,borderType=cv2.BORDER_CONSTANT)
plt.subplot(231)
plt.imshow(flower,‘gray‘),plt.title(‘flower‘)
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()
BORDER_REPLICATE:复制法,也就是复制边缘像素
BORDER_REFLECT:反射法,对感兴趣的图像中的像素在两边进行复制,fedcba|abcdefgh|hgfedcb
BORDER_REFLECT_101:反射法。以最边缘像素为轴,对称,gfedcb|abcdefgh|gfedcba
BORDER_WRAP:外包装法 cdefgh|abcdefgh|abcdefg
BORDER_CONSTANT:常量法,常数值填充