【opencv】高频低频滤波

from email.mime import image
import imghdr
from turtle import title
import cv2
import matplotlib.pyplot as plt
import numpy as np

def cv_show(img,name):
    cv2.imshow(name,img)
    cv2.waitKey(0)
    cv2.destroyAllWindows()

#高频滤波 细节增强
def high_pass_filter(img):
    #模板
    kernel=np.array([[-1,-1,-1],[-1,9,-1],[-1,-1,-1]])
    dst=cv2.filter2D(img,-1,kernel)
    return dst

#低频滤波 图像模糊
def low_pass_filter(img):
    #模板
    kernel=np.array([[1,1,1],[1,1,1],[1,1,1]])
    dst=cv2.filter2D(img,-1,kernel)
    return dst

img=cv2.imread('lena.jpg')
cv_show(img,'origin')
high_pass_filter_img=high_pass_filter(img)
cv_show(high_pass_filter_img,'high_pass_filter')
#保存
cv2.imwrite('lena_high_pass_filter.jpg',high_pass_filter_img)
low_pass_filter_img=low_pass_filter(img)
cv_show(low_pass_filter_img,'low_pass_filter')
#保存
cv2.imwrite('lena_low_pass_filter.jpg',low_pass_filter_img)

【opencv】高频低频滤波_第1张图片

【opencv】高频低频滤波_第2张图片 高频滤波

 

【opencv】高频低频滤波_第3张图片 低频滤波

 

 

你可能感兴趣的:(opencv,opencv,计算机视觉,python)