#! usr/bin/python
# coding=utf-8
import numpy as np
import cv2
from scipy import ndimage
# opencv 滤波器
image = cv2.imread('test.jpg', 0)
# kernel_3x3 = np.array([[-1, -1, -1], [-1, 8, -1], [-1, -1, -1]])
# kernel_5x5 = np.array([[-1, -1, -1, -1, -1],
# [-1, 1, 2, 1, -1],
# [-1, 2, 4, 2, -1],
# [-1, 1, 2, 1, -1],
# [-1, -1, -1, -1, -1]])
# k3 = ndimage.convolve(image, kernel_3x3)
# k5 = ndimage.convolve(image, kernel_5x5)
# sigma = 0
# blurred = cv2.GaussianBlur(image, (11, 11), sigma)
# cv2.imshow('3*3', k3)
# cv2.imshow('5*5', k5)
# cv2.imshow('blurred', blurred)
lap = cv2.Laplacian(image, cv2.CV_8U)
sobel_x = cv2.Sobel(image, cv2.CV_16S, 1, 0)
sobel_y = cv2.Sobel(image, cv2.CV_16S, 0, 1)
abs_x = cv2.convertScaleAbs(sobel_x)
abs_y = cv2.convertScaleAbs(sobel_y)
sobel = cv2.addWeighted(abs_x, 0.5, abs_y, 0.5, 0)
canny = cv2.Canny(image, 10, 150)
cv2.imshow('lap', lap)
# cv2.imshow('sobel_x', sobel_x)
# cv2.imshow('sobel_y', sobel_y)
cv2.imshow('sobel', sobel)
cv2.imshow('canny', canny)
cv2.waitKey()
cv2.destroyAllWindow()
网友评论