OpenCV-Python系列·第十二集:图像浮雕

设置不同卷积核进行滤波,可得到自己想要的效果。

# -*- coding: utf-8 -*-
"""
Created on Sat Aug 25 15:10:51 2018

@author: Miracle
"""
import cv2
import numpy as np
#加载图像
image = cv2.imread('../data/aaa.jpg')
#自定义卷积核
kernel_emboss_1 = np.array([[0,-1,-1],[1,0,-1],[1,1,0]])
kernel_emboss_2 = np.array([[1,1,0],[-1,0,1],[0,-1,-1]])
kernel_emboss_3 = np.array([[1,0,0],[0,0,0],[0,0,-1]])
#浮凸
output_1 = cv2.filter2D(image,-1,kernel_emboss_1)
output_2 = cv2.filter2D(image,-1,kernel_emboss_2)
output_3 = cv2.filter2D(image,-1,kernel_emboss_3)
#显示浮凸效果
cv2.imshow('Original Image',image)
cv2.imshow('Emboss_1',output_1)
cv2.imshow('Emboss_2',output_2)
cv2.imshow('Emboss_3',output_3)
#停顿
if cv2.waitKey() & 0xFF == 27:
    cv2.destroyAllWindows()

OpenCV-Python系列·第十二集:图像浮雕_第1张图片

你可能感兴趣的:(OpenCV-Python)