Python 6.给图片添加边框(重复,复制,纯色等) OpenCV

Python 6.给图片添加边框(重复,复制,纯色等) OpenCV

import cv2
import numpy as np
from matplotlib import pyplot as plt

BLUE = [255, 0, 0]

img1 = cv2.imread('pic1.png', 1)

# change the value of bgr
b, g, r = cv2.split(img1)
img2 = cv2.merge([r, g, b])
img3 = cv2.merge([r, g, b])
img4 = cv2.merge([r, g, b])
img5 = cv2.merge([r, g, b])

# make one of bgr become 0
img3[:, :, 0] = 0
img4[:, :, 1] = 0
img5[:, :, 2] = 0

# make all kind of border
replicate = cv2.copyMakeBorder(img1, 10, 10, 10, 10, cv2.BORDER_REPLICATE)
reflect = cv2.copyMakeBorder(img1, 10, 10, 10, 10, cv2.BORDER_REFLECT)
reflect101 = cv2.copyMakeBorder(img1, 10, 10, 10, 10, cv2.BORDER_REFLECT_101)
wrap = cv2.copyMakeBorder(img1, 10, 10, 10, 10, cv2.BORDER_WRAP)
constant = cv2.copyMakeBorder(img1, 10, 10, 10, 10, cv2.BORDER_CONSTANT, value=BLUE)

# plot figure
plt.subplot(331), plt.imshow(img2), plt.title('origin')
plt.subplot(332), plt.imshow(replicate, 'gray'), plt.title('replicate')
plt.subplot(333), plt.imshow(reflect, 'gray'), plt.title('reflect')
plt.subplot(334), plt.imshow(reflect101, 'gray'), plt.title('reflect101')
plt.subplot(335), plt.imshow(wrap, 'gray'), plt.title('wrap')
plt.subplot(336), plt.imshow(constant, 'gray'), plt.title('constant')
plt.subplot(337), plt.imshow(img3), plt.title('img3')
plt.subplot(338), plt.imshow(img4), plt.title('img4')
plt.subplot(339), plt.imshow(img5), plt.title('img5')

plt.show()
 

Python 6.给图片添加边框(重复,复制,纯色等) OpenCVPython 6.给图片添加边框(重复,复制,纯色等) OpenCV qq_36071362 发布了28 篇原创文章 · 获赞 39 · 访问量 6744 私信 关注
上一篇:python-在倾斜的网格中排列matplotlib子图


下一篇:MATLAB实现图像的代数运算