Zero Crossing、Marr-Hildreth、DoG 如何使用
时间: 2023-07-04 18:19:46 浏览: 101
ste-zcr-preprocessing.rar_energy+zcr_short_zero crossing
1. Zero Crossing算子
Zero Crossing算子可以通过cv2.Laplacian函数实现,具体代码如下:
```
import cv2
import numpy as np
# 读取图像
img = cv2.imread('image.jpg', 0)
# 检测边缘
laplacian = cv2.Laplacian(img,cv2.CV_64F)
laplacian = np.uint8(np.absolute(laplacian))
zcr = np.zeros(laplacian.shape)
zcr[laplacian == 0] = 255
zcr[laplacian < 0] = 128
# 显示图像
cv2.imshow('image', img)
cv2.imshow('Zero Crossing', zcr)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
2. Marr-Hildreth算子
Marr-Hildreth算子可以通过cv2.Laplacian和cv2.GaussianBlur函数实现,具体代码如下:
```
import cv2
import numpy as np
# 读取图像
img = cv2.imread('image.jpg', 0)
# 高斯滤波
img = cv2.GaussianBlur(img, (3, 3), 0)
# 检测边缘
laplacian = cv2.Laplacian(img,cv2.CV_64F)
laplacian = np.uint8(np.absolute(laplacian))
marr_hildreth = np.zeros(laplacian.shape)
marr_hildreth[laplacian > 0] = 255
# 显示图像
cv2.imshow('image', img)
cv2.imshow('Marr-Hildreth', marr_hildreth)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
3. DoG算子
DoG算子可以通过cv2.GaussianBlur和cv2.absdiff函数实现,具体代码如下:
```
import cv2
import numpy as np
# 读取图像
img = cv2.imread('image.jpg', 0)
# 高斯滤波
gaussian1 = cv2.GaussianBlur(img, (3, 3), 0)
gaussian2 = cv2.GaussianBlur(img, (5, 5), 0)
# 检测边缘
dog = cv2.absdiff(gaussian1, gaussian2)
dog = np.uint8(np.absolute(dog))
dog[dog < 50] = 0
dog[dog >= 50] = 255
# 显示图像
cv2.imshow('image', img)
cv2.imshow('DoG', dog)
cv2.waitKey(0)
cv2.destroyAllWindows()
```
以上代码中的'image.jpg'是输入图像的路径,请根据实际情况修改。
阅读全文