标签:
#encoding:utf-8
#
#laplacian边缘检测
#
import numpy as np
import cv2
image = cv2.imread("H:\\img\\lena.jpg")
image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)#将图像转化为灰度图像
cv2.imshow("Original",image)
cv2.waitKey()
#拉普拉斯边缘检测
lap = cv2.Laplacian(image,cv2.CV_64F)#拉普拉斯边缘检测
lap = np.uint8(np.absolute(lap))##对lap去绝对值
cv2.imshow("Laplacian",lap)
cv2.waitKey()
#encoding:utf-8
#
#Sobel边缘检测
#
import numpy as np
import cv2
image = cv2.imread("H:\\img\\lena.jpg")
image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)#将图像转化为灰度图像
cv2.imshow("Original",image)
cv2.waitKey()
#Sobel边缘检测
sobelX = cv2.Sobel(image,cv2.CV_64F,1,0)#x方向的梯度
sobelY = cv2.Sobel(image,cv2.CV_64F,0,1)#y方向的梯度
sobelX = np.uint8(np.absolute(sobelX))#x方向梯度的绝对值
sobelY = np.uint8(np.absolute(sobelY))#y方向梯度的绝对值
sobelCombined = cv2.bitwise_or(sobelX,sobelY)#
cv2.imshow("Sobel X", sobelX)
cv2.waitKey()
cv2.imshow("Sobel Y", sobelY)
cv2.waitKey()
cv2.imshow("Sobel Combined", sobelCombined)
cv2.waitKey()
#encoding:utf-8
#
#Canny边缘检测
#
import numpy as np
import cv2
image = cv2.imread("H:\\img\\lena.jpg")#读入图像
image = cv2.cvtColor(image,cv2.COLOR_BGR2GRAY)#将图像转化为灰度图像
cv2.imshow("Image",image)#显示图像
cv2.waitKey()
#Canny边缘检测
canny = cv2.Canny(image,30,150)
cv2.imshow("Canny",canny)
cv2.waitKey()
版权声明:本文为博主原创文章,未经博主允许不得转载。
标签:
原文地址:http://blog.csdn.net/jnulzl/article/details/47755071