1. Image gradient-Sobel operator
dst = cv2.Sobel(src, ddepth, dx, dy, ksize)
- ddepth: The depth of the image. The depth of the output image (can be understood as a data type), -1 means the same depth as the original image.
- dx and dy represent the horizontal and vertical directions, respectively. When the combination is dx=1, dy=0, find the first derivative in the x direction, and when the combination is dx=0, dy=1, find the first derivative in the y direction (if it is 1 at the same time, you usually can’t get what you want result)
- ksize is the size of the Sobel operator. Optional parameter) The size of the Sobel operator, must be 1, 3, 5 or 7, the default is 3. When calculating the first-order derivatives in the X direction and Y direction, the convolution kernels are:
- scale: (optional parameter) the scale factor to enlarge the value obtained by gradient calculation, the effect usually makes the gradient map brighter, the default is 1
- delta: (optional parameter) before storing the target image into a multidimensional array, you can increase the value of each pixel by delta, the default is 0
- borderType: (optional parameter) determines how the edge pixels are processed when the image is filtered (convoluted), the default is BORDER_DEFAULT
2. Image gradient-Scharr operator (Scharr operator)
The scharr operator is an improvement of the sobel operator.
3. Image gradient-laplacian operator
It can be understood that the operator is used to find the edge
4. Canny edge detection
Canny edge detection
-
-
使用高斯滤波器,以平滑图像,滤除噪声。
-
-
-
计算图像中每个像素点的梯度强度和方向。
-
-
-
应用非极大值(Non-Maximum Suppression)抑制,以消除边缘检测带来的杂散响应。
-
-
-
应用双阈值(Double-Threshold)检测来确定真实的和潜在的边缘。
-
-
-
通过抑制孤立的弱边缘最终完成边缘检测。
-
img=cv2.imread("lena.jpg",cv2.IMREAD_GRAYSCALE)
v1=cv2.Canny(img,80,150)
v2=cv2.Canny(img,50,100)
res = np.hstack((v1,v2))
cv_show(res,'res')
5. Image Pyramid
5.1 Gaussian Pyramid
Upsampling is to enlarge the graph, and downsampling is to shrink the graph.
up=cv2.pyrUp(img)
up_down=cv2.pyrDown(up)
cv_show(img-up_down,'img-up_down')
5.2 Laplacian Pyramid
down=cv2.pyrDown(img)
down_up=cv2.pyrUp(down)
l_1=img-down_up
cv_show(l_1,'l_1')
6. Image Outline
cv2.findContours(img,mode,method)
mode: contour retrieval mode
- RETR_EXTERNAL : retrieve only the outermost contours;
- RETR_LIST: Retrieve all contours and save them in a linked list;
- RETR_CCOMP: Retrieve all contours and organize them into two layers: the top layer is the outer boundary of each part, the second layer is the boundary of the cavity;
- RETR_TREE: retrieve all contours, and reconstruct the entire hierarchy of nested contours;
method: contour approximation method
- CHAIN_APPROX_NONE: Outlines are output as Freeman chaincodes, all other methods output polygons (sequences of vertices).
- CHAIN_APPROX_SIMPLE: Compresses horizontal, vertical and oblique parts, that is, the function keeps only their end parts.