20.Canny edge detection

1. The main contents

  • Canny algorithm introduced
  • API cv :: Canny ()
    the difference between the clone and copyto, see the link, note FIG copyto mask
    inverted image

2.Canny algorithm introduced

  • Canny edge detection algorithm is proposed in 1986
  • It is a good edge detector
  • It is a common and very useful image processing method
    which algorithm the steps of:
高斯模糊——GaussianBlur()              //降噪声
灰度转换——cvtColor
计算梯度——sobel/Schar                  
非最大信号抑制
高低阈值输出二值图像
  • Non-maximum inhibition signal
    when the signal is very strong edge, the system is considered a large edge, but only one edge, this time we're going to be a non-edge pixel suppression. ---- inhibition of the maximum signal in this direction, not the maximum value, put its value is removed,
    after the sobel operator, we get a Gx and Gy, their calculated, we obtain an angle, by this angle we get a trend gradient, e.g., we obtain a greater variation in the + x-axis direction, then we find + y (vertical) direction, now left, right intermediate value as compared with it, if the ratio it's a small value, then the left and right are deleted, intermediate retention.
    Here Insert Picture Description

  • High and low threshold output binary image
    interpretation : At this point of the image due to the non-maximum signal suppression before, we now have the edges of the image are more prominent, but for some reason some of the edge may not yet connected, then we need to be this way connecting edges.
    Specific operations : T1, T2 to the threshold value, usually higher than T2 are retained, who is less than T1 discarded, from the pixel is higher than T2, T1 and greater than all interconnected, are preserved, a binary image is finally obtained.
    Recommended high and low threshold ratio T2: T1 = 3: 1/2: 1 which is the high threshold T2, T1 is the low threshold
    Here Insert Picture Description
    Here Insert Picture Description

Detailed 3.API

(Canny function helps us a good package of the following five steps, Gaussian blur, grayscale conversion, sobel operator, non-maximum suppression signal, the maximum output level of the threshold value)

Canny(
    InputArray  src,     //8-bit的输入图像
    OutputArray  edges,  //输出边缘图像,一般都是二值图像,背景是黑色
    double threshold1,   //低阈值,常取高阈值的1/2或者1/3
    double threshold2,   //高阈值
    int aptertureSize,   //Sobel算子,常取3x3,取值3
    bool  L2gradient     //选择true表示是L2来归一化,默认用L1(false)归一化 
)

4.image.copyTo (image2) supplementary explanation Function

This function has two definitions copyTo ways, namely

void  copyTo (OutputArray m)  const;

with

void  copyTo(OutputArray m ,InputArray mask)  const;

That is, the parameter can be an output image or an output image and a mask map
then
image.copyTo (imageROI);
that is, the image of this image copy (copy to) to imageROI
image.copyTo (imageROI, mask) ;
then this is not only the image of FIG copy (copy to) to the mageROI, and the image pixels corresponding to mask pixels with value 0 are not affixed to the imageROI.

Extra extensions:
OpenCV3 of --copyTo () function using the method of
Canny edge detection analysis

Published 56 original articles · won praise 51 · views 6507

Guess you like

Origin blog.csdn.net/qq_43367829/article/details/105423652