OpenCVSharp入门教程 基础篇⑤——GaussianBlur高斯模糊算法
文章目录
- 一、前文
- 二、GaussianBlur高斯模糊算法流程
- 三、界面布局
- 四、功能实现
- 4.1 打开图片
- 4.2 GaussianBlur高斯模糊—源码
- 4.3 GaussianBlur高斯模糊—参数讲解
- 五、运行效果图
一、前文
Gaussian Blur,高斯模糊
减少图像噪声以及降低细节层次
高斯平滑也用于计算机视觉算法中的预先处理阶段,以增强图像在不同比例大小下的图像效果(参见尺度空间表示以及尺度空间实现)。 从数学的角度来看,图像的高斯模糊过程就是图像与正态分布做卷积。由于正态分布又叫作高斯分布,所以这项技术就叫作高斯模糊。
二、GaussianBlur高斯模糊算法流程
其中r
是模糊半径
,σ
是正态分布的标准偏差
。
在二维空间中,这个公式生成的曲面的等高线是从中心开始呈正态分布的同心圆。
分布不为零的像素组成的卷积矩阵与原始图像做变换。每个像素的值都是周围相邻像素值的加权平均。
原始像素的值有最大的高斯分布值,所以有最大的权重,相邻像素随着距离原始像素越来越远,其权重也越来越小。
三、界面布局
- 一个
Label
- N个
Button
- 三个
Picture
四、功能实现
4.1 打开图片
private void openFileBtn_Click(object sender, EventArgs e){OpenFileDialog openfiledialog = new OpenFileDialog();openfiledialog.Filter = "PNG Files (*.png)|*.png|JPG Files (*.jpg)|*.jpg|GIF Files (*.gif)|*.gif";openfiledialog.RestoreDirectory = true;if (openfiledialog.ShowDialog() == DialogResult.OK){Console.WriteLine(openfiledialog.FileName);fileName = openfiledialog.FileName;//Mat src = new Mat("foo.png", LoadMode.Color);Mat src = new Mat(fileName);//Mat src = new Mat(fileName, ImreadModes.Color);var frameBitmap = BitmapConverter.ToBitmap(src);pictureBox1.Image?.Dispose();pictureBox1.Image = frameBitmap;}}
4.2 GaussianBlur高斯模糊—源码
private void GaussianBlurBtn_Click(object sender, EventArgs e)
{mInput = new Mat(fileName);blur = new Mat(mInput.Rows, mInput.Cols, MatType.CV_8UC4);Size ksize = new OpenCvSharp.Size(5, 5);Point anchor = new Point(3, 3);BorderTypes borderType = BorderTypes.Constant;//Cv2.Blur(mInput, blur, ksize, anchor, borderType); //模糊Cv2.GaussianBlur(mInput, blur, ksize, 0); //高斯模糊srcPictureBox.Image = BitmapConverter.ToBitmap(mInput);grayPictureBox.Image = BitmapConverter.ToBitmap(blur);
}
4.3 GaussianBlur高斯模糊—参数讲解
//
// 摘要:
// Blurs an image using a Gaussian filter.
//
// 参数:
// src:
// input image; the image can have any number of channels, which are processed independently,
// but the depth should be CV_8U, CV_16U, CV_16S, CV_32F or CV_64F.
//
// dst:
// output image of the same size and type as src.
//
// ksize:
// Gaussian kernel size. ksize.width and ksize.height can differ but they both must
// be positive and odd. Or, they can be zero’s and then they are computed from sigma*
// .
//
// sigmaX:
// Gaussian kernel standard deviation in X direction.
//
// sigmaY:
// Gaussian kernel standard deviation in Y direction; if sigmaY is zero, it is set
// to be equal to sigmaX, if both sigmas are zeros, they are computed from ksize.width
// and ksize.height, respectively (see getGaussianKernel() for details); to fully
// control the result regardless of possible future modifications of all this semantics,
// it is recommended to specify all of ksize, sigmaX, and sigmaY.
//
// borderType:
// pixel extrapolation method
public static void GaussianBlur(InputArray src, OutputArray dst, Size ksize, double sigmaX, double sigmaY = 0, BorderTypes borderType = BorderTypes.Reflect101);
ksize
,高斯内核大小,ksize.width和ksize.height必须是正奇数,两者可以不相同,值越大越模糊sigmaX
,Y轴方向的标准差,值越大越模糊sigmaY
,X轴方向的标准差,值越大越模糊
五、运行效果图
- 从左到右
- 第一张是原图
- 第二张是GaussianBlur高斯模糊结果图
Size ksize = new OpenCvSharp.Size(3, 3);
Size ksize = new OpenCvSharp.Size(5, 5);
Size ksize = new OpenCvSharp.Size(15, 15);
觉得好,就一键三连呗(点赞+收藏+关注)
OpenCVSharp入门教程 基础篇⑤——GaussianBlur高斯模糊算法相关推荐
- ESP32-C3入门教程 基础篇⑪——Non-Volatile Storage (NVS) 非易失性存储参数的读写
文章目录 一.前言 二.NVS介绍 三.操作流程 3.1 读操作流程 3.2 写操作流程 四.关键函数 五.随机整数 读写示例 六.对象/数组 读写示例 七.总结 八.参考 一.前言 本文基于VS C ...
- ESP32-C3入门教程 基础篇②——GPIO口输入,按键的长按和短按
文章目录 一.前言 二.硬件准备 三.知识要点 3.1 GPIO使用 3.2 时钟节拍 四.参考例程 五.功能简述 六.源码实现 6.1 中断方式 6.2 定时扫描 七.源码详解 一.前言 本文基于V ...
- ESP32-C3入门教程 基础篇(八、NVS — 非易失性存储库的使用)
前面的7节课把开发板上基本的外设都测试过一边,接下来马上就要进入wifi和蓝牙应用的测试了 在此之前,还需要把掉电数据保存的功能给实现,在STM32中,可以使用内部的flash或者有些自带的EEPRO ...
- ESP32-C3入门教程 基础篇(四、I2C总线 — 与SHT21温湿度传感器通讯)
测试第四课,了解ESP32-C3的 I2C 总线使用,与SHT21 温湿度传感器通讯 这一课把基础介绍放在前面,先看基本流程,再去修改代码 目录 前言 1. ESP32-C3 I2C基础介绍 1.1 ...
- ESP32-C3入门教程 基础篇(六、TIMG 硬件定时器 与 软件定时器)
到了测试第6课,还没有玩过ESP32-C3的基本定时器,虽然FreeRTOS,可以使用软件定时器 但是软件定时器毕竟也有不适用的时候,这个在我FreeRTOS博文中有单独说明. 所以硬件定时器也得熟悉 ...
- 泰凌微8258入门教程 基础篇④——sig_mesh_sdk架构介绍
文章目录 一.前言 二.SDK文件架构 三.SDK Demo Project 四.vendor文件架构 4.1 common 4.2 Demo Project目录 五.产品类型定义 一.前言 本系列的 ...
- ESP32-C3入门教程 基础篇(三、UART模块 — 与Enocean无线模块串口通信)
测试第三课,ESP32-C3的串口通信测试 老样子,使用Enocean无线模块和ESP32-C3进行串口通信. 目录 前言 1.UART示例测试 1.1 UART 基础测试 1.2 与Enocean无 ...
- 泰凌微8258入门教程 基础篇⑤——发送数据流程
文章目录 一.Sig Mesh协议 二.Sig SDK 流程图 三.mesh_tx_cmd 四.增加Log 五.调试 一.Sig Mesh协议 二.Sig SDK 流程图 Created with R ...
- 【SQL Server】入门教程-基础篇(三)
目录
最新文章
- LeetCode Surrounded Regions(floodfill算法)
- 系统相机裁剪比例_《零基础轻松学会PS》二章第3节:裁剪工具的使用方法
- linux 的功能,Linux的主要功能
- python获取列表中指定元素的下标
- Leetcode周赛5827. 检查操作是否合法
- ECCV 2018 | 美图云联合中科院提出基于交互感知注意力机制神经网络的行为分类技术...
- 除醛重要性美博士环保为您解答!!
- Spring MVC之表单标签
- Pandas Timestamp 和 python 中 datetime 的互相转换
- sap.ca.scfld.md.ComponentBase.extend
- vue调用数组_vue数组的运用
- python sizeof_python 变量作用域 v.__sizeof__() python 深复制 一切皆对象 尽量减少内存消耗 赋值语句的原理...
- 红皮书--With语句及布尔型
- [转]使用SCOM 2012监控网络
- python 条件语句且_python 条件语句
- 王晶:华为云OCR文字识别服务技术实践、底层框架及应用场景 | AI ProCon 2019
- Linux ubuntu 串口调试工具
- freeswitch与eyebeam
- 对抗样本(五)DeepFool
- 储存卡数据怎么恢复?恢复靠它