zhiqingstudy

Be a young person with knowledge and content

There must be many edge lines in an image. The main function of high pass filtering is to detect edges. Opencv provides us with several high pass filters.
Sobel is characterized by good anti noise effect
Schar is an unchangeable filtering method with convolution kernel. For 3 * 3 convolution kernel, Sobel filtering is not as effective as Schar filtering.

Laplacian is sensitive to noise

Sobel operator:
一般情况下我们先向x方向求导,然后在y方向求导,最终结果是:|G|=|Gx|+|Gy|。
Sobel api:
Sobel(src,ddepth,dx,dy,ksize=3)
Src: picture of specific operation
Ddepth: output bit depth
Dx, dy: for whom to derive
Ksize: The convolution core is 3 by default

import cv2
import numpy as np


# 导入一张图
img=cv2.imread('C:\\Users\\mk\\Desktop\\1.jpg')
# 索贝尔x方向上的边缘
dst_x=cv2.Sobel(img,cv2.CV_64F,2,0,ksize=5)
# 索贝尔y方向上的边缘
dst_y=cv2.Sobel(img,cv2.CV_64F,0,2,ksize=5)
# 合并图片
dst=dst_x+dst_y

# 显示图片
cv2.imshow('img',img)
cv2.imshow('dst_x',dst_x)
cv2.imshow('dst_y',dst_y)
cv2.imshow('dst',dst)
cv2.waitKey(0)
Scharr Scharr operator
The Shale operator is very similar to the Sobel operator. The biggest difference is that the convolution kernel has different values. Shale can only find the edge in the x or y direction.
Scharr api:
Scharr(src,ddepth,dx,dy)
Src: picture of specific operation
Ddepth: output bit depth
Dx, dy: which direction to take the derivative
import cv2
import numpy as np


# 导入一张图
img=cv2.imread('C:\\Users\\mk\\Desktop\\1.jpg')
# 沙尔x方向上的边缘
dst_x=cv2.Scharr(img,cv2.CV_64F,1,0)
# 沙尔y方向上的边缘
dst_y=cv2.Scharr(img,cv2.CV_64F,0,1)
# 合并图片
dst=dst_x+dst_y

# 显示图片
cv2.imshow('img',img)
cv2.imshow('dst_x',dst_x)
cv2.imshow('dst_y',dst_y)
cv2.imshow('dst',dst)
cv2.waitKey(0)
Laplacian operator
Laplacian can calculate the edges in both directions at the same time, but the disadvantage is that multiple noises are sensitive, and it is generally necessary to denoise before using Laplacian.
Laplacian api:
Laplacian(img,ddepth,ksize=1,scale=1)
Img: picture of specific operation
Ddepth: output bit depth
Ksize: size of convolution core, not set to 1 by default
Scale: scale value, not set to 1 by default
import cv2
import numpy as np


# 导入一张图
img=cv2.imread('C:\\Users\\mk\\Desktop\\1.jpg')
# 拉普拉斯
dst=cv2.Laplacian(img,cv2.CV_64F,ksize=5)

# 显示图片
cv2.imshow('img',img)
cv2.imshow('dst',dst)
cv2.waitKey(0)
comment
head sculpture
Code:
Related

Why you shouldn't stay at a job for more than 2 years?

3 harsh facts long-distance relationships

how to keep your girlfriend interested in a long-distance relationship




Unless otherwise specified, all content on this website is original. If the reprinted content infringes on your rights, please contact the administrator to delete it
Contact Email:2380712278@qq.com

Filing number:皖ICP备19012824号