Opencv image manipulation-image blur


Preface


The following is the content of this article, the following cases are available for reference

1. Fuzzy Theory

	模糊理论(Fuzzy Theory)是指用到了模糊集合的基本概念,或连续隶属度函数的理论。它可分类为模
糊数学,模糊系统,不确定性和信息,模糊决策,模糊逻辑与人工智能这五个分支,它们并不是完全独立,
它们之间有紧密的联系。例如,模糊控制就会用到模糊数学和模糊逻辑中的概念。从实际应用的观点来看,
模糊理论的应用大部分集中在模糊系统上,尤其集中在模糊控制上。也有一些模糊专家系统应用于医疗诊
断和决策支持。由于模糊理论从理论和实践的角度看仍然是新生事物,所以我们期望,随着模糊领域的成
熟,将会出现更多可靠的实际应用。

	模糊理论是以模糊集合(fuzzy set)为基础,其基本精神是接受模糊性现象存在的事实,而以处理
概念模糊不确定的事物为其研究目标,并积极的将其严密的量化成计算机可以处理的讯息,不主张用繁
杂的数学分析即模型来解决模型。

2. Fuzzy principle:

Smooth/Blur is one of the simplest and most commonly used operations in image processing. One of the reasons why this operation is used is to reduce noise during image preprocessing. The Smooth/Blur operation is behind the mathematical convolution calculation, which
is usually the convolution operator calculation. All are linear operations, also called linear filtering

Convolution calculation function:
Insert picture description here

Third, the blur in ps

1. Select the sharpening tool in the toolbar

Insert picture description here

2. The processed image

Insert picture description here


Four, Opencv fuzzy API operation

1. The blur() function

Introduction: Use the normalized box filter to blur the image
Definition:

void blur( InputArray src, OutputArray dst,Size ksize, Point anchor = Point(-1,-1),
           int borderType = BORDER_DEFAULT );
/*
src:是输入图像;
dst:是输出图像;
ksize:模糊内核大小
anchor anchor point;默认值point(-1,-1)表示锚点位于内核居中。
borderType border mode:用于推断图像外部的像素
*/

Instructions:

blur(src, dst, Size(3, 3), Point(-1, -1));//均值模糊

2. GaussianBlur() function

Introduction: Blur image using Gaussian filter
Definition:

void GaussianBlur( InputArray src, OutputArray dst, Size ksize,double sigmaX, 
				   double sigmaY = 0,int borderType = BORDER_DEFAULT );
/*
src:是输入图像;
dst:是输出图像;
ksize:模糊内核大小
sigmaX: X方向的sigmaX高斯核标准差。
sigmaY: Y方向高斯核标准差;如果sigmaY为零,则设置为等于sigmaX,如果两个sigma都为零,则根据K尺寸.宽度以及K尺寸高度
borderType: 像素外推方法
*/

Instructions:

GaussianBlur(src, dst, Size(5, 5), 11, 11);//高斯模糊

3. The medianBlur() function

Introduction: Use a median filter to blur the image.
definition:

void medianBlur( InputArray src, OutputArray dst, int ksize );
/*
src:是输入图像;
dst:是输出图像;
ksize aperture linear size;必须是奇数且大于1,例如:3、5、7。。。
*/

Instructions:

medianBlur(src, dst, 3);//中值模糊

4. BilateralFilter() function

Introduction: Blur image using Gaussian filter
Definition:

void bilateralFilter( InputArray src, OutputArray dst, int d,double sigmaColor, 
					  double sigmaSpace, int borderType = BORDER_DEFAULT );
/*
src:是输入图像;
dst:是输出图像;
d: 过滤过程中使用的每个像素邻域的直径。如果是非阳性,是从sigmaSpace计算出来的;
sigmaColor: 参数值越大意味着像素邻域内的其他颜色将混合在一起,从而在较大的半等色区域。
sigmaSpace: 在坐标空间中过滤sigma。参数值越大意味着更远的像素会互相影响,只要它们的颜色足够接近.当d\>0时,它指定邻域大小,而不考虑sigmaSpace。否则,d是与sigmaSpace成比例。
borderType: 像素外推方法
*/

Instructions:

bilateralFilter(src, dst, 15, 100, 3);//高斯双边模糊

5. Filter2D operation

definition:

void filter2D( InputArray src, OutputArray dst, int ddepth, InputArray kernel, Point anchor = 			
				Point(-1,-1), double delta = 0, int borderType = BORDER_DEFAULT );
/*
src:是输入图像;
dst:是输出图像;
ddepth: 目标图像的所需深度
kernel: 内核卷积内核(或者更确切地说是相关内核),单通道浮点如果要将不同的内核应用于不同的通道,请将图像拆分为使用split分离颜色平面并单独处理它们。
anchor表示内核中过滤点的相对位置的锚内核;锚点应该位于内核中;默认值(-1,-1)表示锚点位于内核中心。
delta: 在将过滤后的像素存储到dst之前添加到像素的可选值
borderType: 像素外推方法
*/

Instructions:

Mat kennel = (Mat_<int>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
filter2D(dst, dst, -1, kennel, Point(-1, -1), 0);

V. Demonstration of blurred image code

Code block:

#include <opencv2/opencv.hpp>
#include <iostream>
#include "facedetectcnn.h"

using namespace std;
using namespace cv;
int main() {
    
    
	Mat src, dst;
	src = imread("D:\\Myfile\\素材照片\\opencv素材照片\\4.jpg");
	if (!src.data) {
    
    
		cout << "could not load image..." << endl;
		return 0;
	}
	namedWindow("input_image", WINDOW_AUTOSIZE);
	imshow("input_image", src);

	char output_title[] = "blur_image";
	//blur(src, dst, Size(3, 3), Point(-1, -1));//均值模糊fliter2D
	//GaussianBlur(src, dst, Size(5, 5), 11, 11);//高斯模糊
	//medianBlur(src, dst, 3);//中值模糊
	bilateralFilter(src, dst, 15, 100, 3);//高斯双边模糊
	Mat kennel = (Mat_<int>(3, 3) << 0, -1, 0, -1, 5, -1, 0, -1, 0);
	filter2D(dst, dst, -1, kennel, Point(-1, -1), 0);

	namedWindow(output_title, WINDOW_AUTOSIZE);
	imshow(output_title, dst);

	waitKey(0);
	return 0;
}

Insert picture description here

operation result:

to sum up

If you have any questions, please leave a message!
Please correct me if there are any errors!

Guess you like

Origin blog.csdn.net/ivan_9/article/details/113809389