图像处理作业(2):Edge Detection Algorithms

Prewitt Operator

Source Code (Matlab)

1
2
3
4
5
6
7
I2 = imread('img1.jpg');
I = rgb2gray(I2);
subplot(1,2,1), imshow(I2);
title('Original');
BW1 = edge(I, 'prewitt');
subplot(1,2,2), imshow(BW3);
title('Prewitt');

Running Results

Image 1

Image 2

Image 3

Image 4

Image 5

Sobel Operator

Source Code (OpenCV)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main() {
Mat grad_x, grad_y;
Mat abs_grad_x, abs_grad_y, dst;
Mat src = imread("img1.jpg");
imshow("Original", src);
//X-direction gradient
Sobel( src, grad_x, CV_16S, 1, 0, 3, 1, 1, BORDER_DEFAULT );
convertScaleAbs( grad_x, abs_grad_x );
imshow("X-direction Sobel", abs_grad_x);
imwrite("img1-1.jpg",abs_grad_x);
//Y-direction gradient
Sobel( src, grad_y, CV_16S, 0, 1, 3, 1, 1, BORDER_DEFAULT );
convertScaleAbs( grad_y, abs_grad_y );
imshow("Y-direction Sobel", abs_grad_y);
imwrite("img1-2.jpg",abs_grad_y);
addWeighted( abs_grad_x, 0.5, abs_grad_y, 0.5, 0, dst );
imshow("Sobel", dst);
imwrite("img1-3.jpg",dst);
waitKey(0);
return 0;
}

Running Results

Image 1

Image 2

Image 3

Image 4

Image 5

Canny Operator

Source Code (OpenCV)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace std;
using namespace cv;
int main() {
Mat src = imread("img1.jpg");
Mat src1=src.clone();
imshow("Canny", src);
Canny( src, src, 150, 100,3 );
imshow("Canny", src);
imwrite("img1-1.jpg",src);
waitKey(0);
return 0;
}

Running Results

Image 1

Image 2

Image 3

Image 4

Image 5

Laplacian

Source Code (OpenCV)

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
#include <iostream>
#include <opencv2/opencv.hpp>
#include <opencv2/highgui/highgui.hpp>
#include <opencv2/imgproc/imgproc.hpp>
using namespace cv;
int main() {
Mat src,src_gray,dst, abs_dst;
src = imread("img1.jpg");
imshow("Original", src);
GaussianBlur( src, src, Size(3,3), 0, 0, BORDER_DEFAULT );
cvtColor( src, src_gray, CV_RGB2GRAY );
Laplacian( src_gray, dst, CV_16S, 3, 1, 0, BORDER_DEFAULT );
convertScaleAbs( dst, abs_dst );
imshow( "Laplace", abs_dst );
waitKey(0);
return 0;
}

Running Results

Image 1

Image 2

Image 3

Image 4

Image 5

FDoG

Source Code

点击此处下载源代码和对应的VS工程项目。

Running Results

Image 1

Image 2

Image 3

Image 4

Image 5

Analysis and Comparison

Comparison

Prewitt

  The edge detection of Prewitt operator can be accuracy. However, Prewitt operator is not isotropic, so the edge is not fully connected and there is a certain degree of disconnection. As the result, there are many broken lines on the acquired images, which will lose some information. So it has better performance in simple images.

Sobel

  Sobel operator is similar with the Prewitt operator. But its effect is more smooth and the width of edge detecting is usually wider. However, Prewitt operator is better than Sobel operator in anti-noise.

Canny

  Canny operator has a relatively good effect on the accuracy of pixel edge location and anti-noise interference. However, as the price, it may misguide some information of the original image and it is more cumbersome to implement.

Laplacian

  Laplacian is a second-order differential operator which is sensitive to noise. As the result, there are some scattered broken edge pixels in some pixels of the segmentation results. It can be proved that it is isotropic. That is to say, the gradient results will not be changed after the rotation of the axis. This is called as the independence of direction of the coordinate axis. Therefore, its positioning on the edge is relatively accurate.

FDoG

  FDoG is the best one in edge detection for which it performs more smooth, connective and accurate. For anti-noise, FDoG may be the worst one. Because it is sensitive with all noise. But it is better than Canny operator in the images of main of single color blocks.

Line width of FDoG

Generate lines of different widths

  The core of FDoG operator is DoG and ETF. We know that DoG is same to LoG, so the Gaussian σ can influence the discrete kernel of LoG and as the result, it also can influence DoG.So the problem is how σ influence the discrete kernel and what connection between the discrete kernel and line width.
  Firstly, the Gaussian σ is a parameter of Gaussian σ of Gaussian distribution. There is a feature that the most of Gaussian distribution’s energy is in (3σ,3σ) area, which is named 3σ principle. As the result, σ can influence the Gaussian function’s energy and its discrete kernel. When σ = 1, it can construct a discrete kernel of size 7x7.
  Secondly, discrete kernel can detect the edge when there exists one edge in discrete kernel’s area. So for the discrete kernel of size 7x7, it can detect one edge six times with different center pixel in one direction. And after DoG operator, there is ‘edge’ of six pixels width. But there are three pixels are positive (lower Gray-level value side) and the three pixels left are negative (high Gray-level value side).
  Then according to the method called binary thresholding, as suggested in [Winnem¨oller et al.2006]:

Produce edges of width 1

  To change the line width to 1, we just need to construct a 3x3 discrete kernel. For this, we need to set σ_c=1.0/3. And for the sake of keeping accuracy, we also need to change the parameter σ_m=1.0 to keep the scale.

  As you can see, the line width of image (a) is 1 pixel while the line width of image (b) is 3 pixels. Meanwhile, (a)’s discrete kernel is 3x3 while (b)’ discrete kernel is 7x7.

坚持原创技术分享,您的支持将鼓励我继续创作!

热评文章