self_example/TensorFlow_eaxmple/OpenCV_try/卷积核与图像特征提取.py

22 lines
836 B
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import numpy as np
import cv2
from scipy import ndimage
#一个3*3的卷积核如果一个像素比他周围的像素更加突出就会提升其本身的亮度
kernel133=np.array([[-1,-1,-1],
[-1,-8,-1],
[-1,-1,-1]])
#一个3*3的卷积核如果一个像素比他周围的像素更加昏暗就会更进一步减少其本身的亮度
kernel133_D=np.array([[1,1,1],
[1,-8,1],
[1,1,1]])
img=cv2.imread("lana.jpg",0)
#ndimage是一个处理多维图像的函数库他可以用于图像滤波器傅里叶变换图像的旋转拉伸以及测量和形态学处理
linghtImg=ndimage.convolve(img,kernel133_D)
blurred=cv2.GaussianBlur(img,(11,11),0)
gaussImg=img-blurred
cv2.imshow("img",linghtImg)
cv2.imshow("img1",gaussImg)
cv2.waitKey(0)