博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Comparing Edge Detection Methods
阅读量:2439 次
发布时间:2019-05-10

本文共 4655 字,大约阅读时间需要 15 分钟。

Refer to 

 

There are many different edge detection methods out there and if you ever wondered how they compare with each other then you came to the right place, so let’s compare them.

We will be implementing some of the most commonly used methods and also using methods from OpenCV and PIL

We will be comparing the following methods:

  • Sobel edge detector
  • Prewitt edge detector
  • Laplacian edge detector
  • Canny edge detector

Sobel Operator

The sobel is one of the most commonly used edge detectors. It is based on convolving the image with a small, separable, and integer valued filter in horizontal and vertical direction and is therefore relatively inexpensive in terms of computations. The Sobel edge enhancement filter has the advantage of providing differentiating (which gives the edge response) and smoothing (which reduces noise) concurrently.

 

 

Sobel Mask

Here is a python implementation of Sobel operator

 

In the code above we first apply gray scale to the image, then we define our masks for horizontal and vertical pass then we loop over the image and calculate the gradients.

Results:

 

 

 

 

In this example we apply the mask on the gray-scale image, however we can produce a better result by applying the mask on each RGB channel.

 

Results: One channel(left), RGB channel(right).

 

 

 

 

You can see a slight improvement but note that it’s computationally more costly.


Prewitt’s Operator

Prewitt operator is similar to the Sobel operator and is used for detecting vertical and horizontal edges in images. However, unlike the Sobel, this operator does not place any emphasis on the pixels that are closer to the center of the mask.

 

 

Prewitt Mask

In this code the only difference is the mask

 

Result:

 

 


Laplacian Operator

Laplacian is somewhat different from the methods we have discussed so far. Unlike the Sobel and Prewitt’s edge detectors, the Laplacian edge detector uses only one kernel. It calculates second order derivatives in a single pass. Two commonly used small kernels are:

 

 

Because these masks are approximating a second derivative measurement on the image, they are very sensitive to noise. To correct this, the image is often Gaussian smoothed before applying the Laplacian filter.

We can also convolve gaussian mask with the Laplacian mask and apply to the image in one pass. I will explain how to convolve one kernel with another in a separate tutorial. However, we will be applying them separately in the following example. To make things easier we will be using OpenCV.

 

Results:

 

 


Canny Operator

Canny edge detector is probably the most commonly used and most effective method, it can have it’s own tutorial, because it’s much more complex edge detecting method then the ones described above. However, I will try to make it short and easy to understand.

  1. Smooth the image with a Gaussian filter to reduce noise.
  2. Compute gradient of using any of the gradient operators Sobel or Prewitt.
  3. Extract edge points: Non-maximum suppression.
  4. Linking and thresholding: Hysteresis

First two steps are very straight forward, note that in the second step we are also computing the orientation of gradients “theta = arctan(Gy / Gx)” Gy and Gx are gradient x direction and y direction respectively.

Now let’s talk about Non-maximum suppression and what it does. In this step we are trying to relate the edge direction to a direction that can be traced along the edges based on the previously calculated gradient strengths and edge directions. At each pixel location we have four possible directions. We check all directions if the gradient is maximum at this point. Perpendicular pixel values are compared with the value in the edge direction. If their value is lower than the pixel on the edge then they are suppressed. After this step we will get broken thin edges that needs to be fixed, so let’s move on to the next step.

Hysteresis is a way of linking the broken lines produced in the previous step. This is done by iterating over the pixels and checking if the current pixel is an edge. If it’s an edge then check surrounding area for edges. If they have the same direction then we mark them as an edge pixel. We also use 2 thresholds, a high and low. If the pixels is greater than lower threshold it is marked as an edge. Then pixels that are greater than the lower threshold and also are greater than high threshold, are also selected as strong edge pixels. When there are no more changes to the image we stop.

Now let’s looked the code:

 

Results:

 

 


Comparison

Now let’s put all of them side by side and see how they stack up.

 

 

 

 

 

 

 

 

 

 

 

 

Top left: (Original). Top middle: (Sobel). Top right: (Sobel RGB). Bottom right: (Prewitt). Bottom middle: (Laplacian). Bottom left: (Canny)

转载地址:http://aqwqb.baihongyu.com/

你可能感兴趣的文章
JSR227:J2EE数据绑定及数据访问标准 (转)
查看>>
Sun ONE Studio 4 Mobile Edition开发MIDlet入门 (转)
查看>>
Jbuilder8开发J2ee学习笔记(2) (转)
查看>>
Makefile编写小说(一) (转)
查看>>
NeHe的opengl教程delphi版(3)----着色 (转)
查看>>
ORACLE SQL性能优化系列 (二) (转)
查看>>
控件treeview的使用 (转)
查看>>
运用VC或Java对Office进行编程操作 (转)
查看>>
Linux Shell 裡一些很少用到卻很有用的指令 (转)
查看>>
一套日本软件开发的详细设计说明书格式(一) (转)
查看>>
第10章 模型管理视图 (转)
查看>>
第7章 活 动 视 图 (转)
查看>>
“管家婆”软件用于维修管理 (转)
查看>>
第13章 术 语 大 全 (8) (转)
查看>>
第13章 术 语 大 全 (9) (转)
查看>>
人月神话读书笔记(二) (转)
查看>>
附录 UML元模 (转)
查看>>
初学者看过来:简单谈谈 C/C++ 递归的思想,实现,以及和循环的关系。 (转)
查看>>
菜鸟初学Java的备忘录(九) (转)
查看>>
非常cool的class library (转)
查看>>