Opencv [study notes] Laplance operator of 019

table of Contents

I. Introduction

Second, the operator review

1, Sanko

2, Sobel operator

Three, Laplance operator

1, to explain

2、API

3, code shows


I. Introduction

Continue to fill the pit.

If you want to see other content related to learning about OpenCV presentation, learning tutorials, code practical, common error and solutions, you can directly see my OpenCV Category:

【OpenCV系列】:https://blog.csdn.net/shuiyixin/article/category/7581855

If you want to learn more about computer vision, OpenCV, machine learning, deep learning and other related technologies, to communicate with more chiefs, then scan the next Fanger Wei code to join us now!

 

Second, the operator review

1, Sanko

Last time we talked operator, this lesson we look back at the concept Operator:

Narrow operator actually refers to a mapping function from one space to another space function (or itself) .

Broadly defined as long as the operator is extended to the space above the space in general, it may be a vector space, normed vector space, the inner product space, or further, Banach space, Hilbert space can. Operators may also be divided into a bounded and unbounded, linear and nonlinear like category.

 

2, Sobel operator

Sobel operator, which is derived from a basic fact, i.e., at an edge portion, the pixel value "skip" or a large change occurs. If part of the strike in the first derivative of this edge, you will see the occurrence of extremes. N is shown below:

Operators corresponding gradient was as follows:

 

Three, Laplance operator

1, to explain

Next, we get to a new operator Laplance operator .

Or above the image, and then we find the first derivative, also seeking its second derivative. This time, had the greatest change in position on the image, the second derivative is zero.

First we look at the first order derivative calculation method of discrete:

The second derivative is a derivative of the first derivative:

Since the image has two row directions, the two directions to the derivative:

Laplace operator :: Laplacian implemented by OpenCV function cv. In fact, since the Laplacian images using a gradient, so it calls inside the Sobel operator to perform its calculation.

 

2、API

Next we talk about API

void Laplacian( 
    InputArray src, 
    OutputArray dst, 
    int ddepth,  
    int ksize = 3,
    double scale = 1,                       
    double delta = 0, 
    int borderType = BORDER_DEFAULT 
);

Function parameters are as follows:

(1) InputArray type src, the input image.

(2)OutputArray类型的dst ,输出图像,图像的大小、通道数和输入图像相同。

(3)int类型的ddepth,目标图像的所需深度。

(4)int类型的ksize,用于计算二阶导数滤波器的孔径大小。大小必须是正数和奇数。

(5)double类型的scale,计算拉普拉斯值的可选比例因子。默认情况下,不应用缩放。

(6)double类型的delta,在将筛选的像素存储到dst中之前添加到这些像素的可选值。说的有点专业了其实就是给所选的像素值添加一个值delta。

(7)int类型的borderType,用于推断图像外部像素的某种边界模式。有默认值BORDER_DEFAULT。

 

3、代码展示

我们这个函数只需要设置前两个参数,这个函数可以计算图像src的像素绝对值,输出到图像dst。

#include<iostream>
#include<opencv2/opencv.hpp>

using namespace std;
using namespace cv;

int main()
{
	Mat img, gx, gy, src;

	img = imread("E:/image/girl2.png");
	if (!img.data)
	{
		cout << "could not load image !";
		return -1;
	}
	imshow("【输入图像】", img);

	Sobel(img, gx, CV_16S, 1, 0);
	Sobel(img, gy, CV_16S, 0, 1);

	convertScaleAbs(gx, gx);
	convertScaleAbs(gy, gy);
	addWeighted(gx, 0.5, gy, 0.5, 0, src);
	imshow("【输出图像】", src);

	waitKey(0);
	return 0;
}

4、执行结果

原图
Laplacian算子操作后

我们也把上节课的两个算子执行结果拿过来,进行对比:

Sobel算子操作后
Scharr算子

 

大家也可以自己尝试一下呀,一定要多做练习!

 

发布了266 篇原创文章 · 获赞 525 · 访问量 53万+

Guess you like

Origin blog.csdn.net/shuiyixin/article/details/104510390