<图像处理> 空间滤波基础二

空间滤波基础二:锐化

锐化的作用的突出灰度中的过渡。图像锐化通过空间微分来实现,微分将增强边缘和其他不连续(噪声),不强化灰度变化缓慢的区域。图像锐化也叫做高通滤波,通过高频,抑制低频。

1、二阶导数锐化

f ( x ) f(x) f(x)的二阶导数定义为差分
∂ 2 f ∂ x 2 = f ( x + 1 ) + f ( x − 1 ) − 2 f ( x ) \frac{\partial^2f}{\partial x^2}=f(x+1)+f(x-1)-2f(x) x22f=f(x+1)+f(x1)2f(x)

拉普拉斯滤波器

最简单的各向同性二阶导数核是拉普拉斯核,对于图像 f ( x , y ) f(x,y) f(x,y),其定义如下:
∇ 2 f = ∂ 2 f ∂ x 2 + ∂ 2 f ∂ y 2 \nabla^2 f=\frac{\partial^2f}{\partial x^2}+\frac{\partial^2f}{\partial y^2} 2f=x22f+y22f
由于任意阶的导数都是线性算子,所以拉普拉斯也是线性算子。如下是对上式的 x 、 y x、y xy两个方向的离散化:
x x x方向:
∂ 2 f ∂ x 2 = f ( x + 1 , y ) + f ( x − 1 , y ) − 2 f ( x , y ) \frac{\partial^2f}{\partial x^2}=f(x+1,y)+f(x-1,y)-2f(x,y) x22f=f(x+1,y)+f(x1,y)2f(x,y)
y y y方向:
∂ 2 f ∂ y 2 = f ( x , y + 1 ) + f ( x , y − 1 ) − 2 f ( x , y ) \frac{\partial^2f}{\partial y^2}=f(x,y+1)+f(x,y-1)-2f(x,y) y22f=f(x,y+1)+f(x,y1)2f(x,y)
由上面三个公式可得,
∇ 2 f = f ( x + 1 , y ) + f ( x − 1 , y ) + f ( x , y + 1 ) + f ( x , y − 1 ) − 4 f ( x , y ) \nabla^2 f=f(x+1,y)+f(x-1,y)+f(x,y+1)+f(x,y-1)-4f(x,y) 2f=f(x+1,y)+f(x1,y)+f(x,y+1)+f(x,y1)4f(x,y)
由上式可得其卷积核如下:
[ 0 1 0 1 − 4 1 0 1 0 ] \begin{bmatrix} 0 & 1&0\\ 1 & -4&1 \\0 &1&0\\ \end{bmatrix} 010141010
更多变体:
(1) [ 1 1 1 1 − 8 1 1 1 1 ] \begin{bmatrix} 1 & 1&1\\ 1 & -8&1 \\1 &1&1\\ \end{bmatrix} 111181111 ,(2) [ 0 − 1 0 − 1 4 − 1 0 − 1 0 ] \begin{bmatrix} 0 & -1&0\\ -1 & 4&-1 \\0 &-1&0\\ \end{bmatrix} 010141010 ,(3) [ − 1 − 1 − 1 − 1 8 − 1 − 1 − 1 − 1 ] \begin{bmatrix} -1 & -1&-1\\ -1 & 8&-1 \\-1 &-1&-1\\ \end{bmatrix} 111181111

综上,卷积核(1)增加了±45°方向,(2)&(3)仅为符号的差异,产生的效果相同,但是需要注意当拉普拉斯滤波过后的图像与原图进行加减操作时的符号差异

OpenCV函数:


void cv::Laplacian(InputArray src, OutputArray dst, int ddepth, int ksize = 1, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT)	Parameters
src				Source image.
dst				Destination image of the same size and the same number of channels as src .
ddepth			Desired depth of the destination image, see combinations.
ksize			Aperture size used to compute the second-derivative filters. See getDerivKernels for details. The size must be positive and odd.
scale			Optional scale factor for the computed Laplacian values. By default, no scaling is applied. See getDerivKernels for details.
delta			Optional delta value that is added to the results prior to storing them in dst .
borderType		Pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.

2、 一阶导数锐化

f ( x ) f(x) f(x)的一阶导数定义为差分
∂ f ∂ x = f ( x + 1 ) − f ( x ) \frac{\partial f}{\partial x}=f(x+1)-f(x) xf=f(x+1)f(x)
在图像处理中,一阶导数是用梯度幅度实现的。图像f在(x,y)处的梯度定位为二维列向量
∇ f = g r a d ( f ) = [ g x g y ] = [ ∂ f ∂ x ∂ f ∂ y ] \nabla f=grad(f)=\begin{bmatrix}g_x\\ g_y \end{bmatrix}=\begin{bmatrix} \frac {\partial f}{\partial x} \\ \\\frac {\partial f} {\partial y} \end{bmatrix} f=grad(f)=[gxgy]= xfyf
向量 ∇ f \nabla f f的幅度表示为 M ( x , y ) M(x,y) M(x,y),其中
M ( x , y ) = ∥ f ∥ = m a g ( ∇ f ) = g x 2 + g y 2 M(x,y)=\parallel f \parallel=mag(\nabla f)=\sqrt{g_x^2+g_y^2} M(x,y)=∥f∥=mag(f)=gx2+gy2
在某些实现中,使用绝对值来近似平方运算和平方根的运算,
M ( x , y ) ≈ ∣ g x ∣ + ∣ g y ∣ M(x,y)\approx |g_x|+|g_y| M(x,y)gx+gy
M ( x , y ) M(x,y) M(x,y)图像与原图尺寸大小相同,对应原图所有像素位置上的变化,该图像又叫做梯度图像

离散的一阶导数卷积核有如下:

1、Roberts滤波器
Roberts算子的原理是通过计算对角方向相邻两个像素之差来计算图像的梯度大小和方向。梯度大小表示边缘的强度,梯度方向与边缘的走向垂直。
Roberts算法在边缘定位方面较为准确,但对噪声比较敏感,无法有效抑制噪声的影响。因此,它常被用于检测边缘明显、亮度差异较大的低噪声图像。

计算方式:
计算45°方向: g x ( x , y ) = f ( x + 1 , y ) − f ( x , y + 1 ) g_x(x,y)=f(x+1,y)-f(x,y+1) gx(x,y)=f(x+1,y)f(x,y+1),滤波核如下:
M x = [ 0 1 − 1 0 ] M_x=\begin{bmatrix} 0 & 1\\ -1 & 0 \\ \end{bmatrix} Mx=[0110]
计算135°方向, g y ( x , y ) = f ( x , y ) − f ( x + 1 , y + 1 ) g_y(x,y)=f(x,y)-f(x+1,y+1) gy(x,y)=f(x,y)f(x+1,y+1),滤波核如下:
M y = [ 1 0 0 − 1 ] M_y=\begin{bmatrix} 1 & 0\\ 0 & -1 \\ \end{bmatrix} My=[1001]

2、Prewitt滤波器
Prewitt算子利用像素点上下左右邻点的灰度差,在边缘处达到极值来检测边缘,对噪声具有平滑的作用。Prewitt算子同样也是一种基于局部差分计算的算法,由两个 3 ∗ 3 3*3 33的模板组成,一个模板用于计算水平方向的梯度,另一个用于计算垂直方向的梯度。与Roberts算子相比,Prewitt算子的检测效果更加准确,仅稍微增加一些计算量就可以抑制噪音的影响。但是相较于Sobel算子和Laplacian算子,Prewitt算子的边缘检测效果较差。
M x = [ − 1 0 1 − 1 0 1 − 1 0 1 ] M_x=\begin{bmatrix} -1 & 0&1\\ -1 & 0&1 \\-1&0&1\\ \end{bmatrix} Mx= 111000111
M y = [ 1 1 1 0 0 0 − 1 − 1 1 ] M_y=\begin{bmatrix} 1 & 1&1\\ 0 & 0&0 \\-1&-1&1\\ \end{bmatrix} My= 101101101

3、Sobel滤波器
Sobel算子可以在边缘检测时可以提供较为精确的边缘方向信息,对于噪声也具有一定的平滑作用。Sobel算子可以通过像素点上下、左右邻点灰度加权差,在边缘处达到极值这一现象检测边缘,是高斯平滑和微分求导的联合运算,抗噪声能力强。考虑了距离对权值的影响,距离越远的像素的影响越小。可以通过快速卷积实现,简单有效,应用广泛。
M x = [ − 1 0 1 − 2 0 2 − 1 0 1 ] M_x=\begin{bmatrix} -1 & 0&1\\ -2 & 0&2 \\-1&0&1\\ \end{bmatrix} Mx= 121000121
M y = [ 1 2 1 0 0 0 − 1 − 2 1 ] M_y=\begin{bmatrix} 1 & 2&1\\ 0 & 0&0 \\-1 &-2&1\\ \end{bmatrix} My= 101202101

void cv::Sobel(InputArray src, OutputArray dst, int ddepth, int dx, int dy, int ksize = 3, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT)	Parameters
src				input image.
dst				output image of the same size and the same number of channels as src .
ddepth			output image depth, see combinations; in the case of 8-bit input images it will result in truncated derivatives.
dx				order of the derivative x.
dy				order of the derivative y.
ksize			size of the extended Sobel kernel; it must be 1, 3, 5, or 7.
scale			optional scale factor for the computed derivative values; by default, no scaling is applied (see getDerivKernels for details).
delta			optional delta value that is added to the results prior to storing them in dst.
borderType		pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.

4、Scharr滤波器
Scharr算子是对Sobel算法的改进和增强。Scharr算子和Sobel算子在边缘检测原理和使用方式上基本相同。Scharr算子使用 3 ∗ 3 3*3 33的滤波器,通过增大像素值间的差异来检测图像的边缘。它在X方向和Y方向上都有对应的边缘检测算子。

相比于Sobel算子,Scharr算子在权重系数上有所调整,使得其在图像梯度的计算中更为敏感。具体来说,Scharr算子使用的权重系数相对Sobel算子更大,以增强梯度的响应。这使得Scharr算子在对边缘进行检测时具有更好的精度和效果。

M x = [ − 3 0 3 − 10 0 10 − 3 0 3 ] M_x=\begin{bmatrix} -3 & 0&3\\ -10 & 0&10 \\-3&0&3\\ \end{bmatrix} Mx= 31030003103
M y = [ 3 10 3 0 0 0 − 3 − 10 3 ] M_y=\begin{bmatrix} 3 & 10&3\\ 0 & 0&0 \\-3 &-10&3\\ \end{bmatrix} My= 30310010303

void cv::Scharr	(InputArray src, OutputArray dst, int ddepth, int dx, int dy, double scale = 1, double delta = 0, int borderType = BORDER_DEFAULT)	Parameters
src				input image.
dst				output image of the same size and the same number of channels as src.
ddepth			output image depth, see combinations
dx				order of the derivative x.
dy				order of the derivative y.
scale			optional scale factor for the computed derivative values; by default, no scaling is applied (see getDerivKernels for details).
delta			optional delta value that is added to the results prior to storing them in dst.
borderType		pixel extrapolation method, see BorderTypes. BORDER_WRAP is not supported.

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/76931.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

无涯教程-JavaScript - DB函数

描述 DB函数使用固定余额递减法返回指定期间内资产的折旧。 语法 DB (cost, salvage, life, period, [month])争论 Argument描述Required/OptionalCostThe initial cost of the asset.RequiredSalvageThe value at the end of the depreciation (sometimes called the salv…

基于SSM的助学贷款管理系统

末尾获取源码 开发语言:Java Java开发工具:JDK1.8 后端框架:SSM 前端:采用JSP技术开发 数据库:MySQL5.7和Navicat管理工具结合 服务器:Tomcat8.5 开发软件:IDEA / Eclipse 是否Maven项目&#x…

手撕代码是程序员的基本功吗?

前言: 现在众多企业都要求在面试中用“手撕代码”来考验应聘者的代码能力,你觉得手敲代码是否可以体现真实的基础实力? 本期话题: 1、你觉得手撕代码是程序员的基本功吗? 2、为什么会用“手撕代码”来考验程序员能力&a…

vue学习之属性绑定

内容渲染 采用 &#xff1a;进行属性渲染创建 demo3.html,内容如下 <!DOCTYPE html> <html lang"en"><head><meta charset"UTF-8"><meta name"viewport" content"widthdevice-width, initial-scale1.0"&…

c++day4

仿照string类&#xff0c;完成myString 类 #include <iostream> #include<cstring>using namespace std; class myString {private:char *str; //记录c风格的字符串int size; //记录字符串的实际长度public://无参构造myString():size(10){str…

Datax 数据同步-使用总结(二)

一、前言 这部分主要记录 datax 实现增量同步的方案。 二、核心思路 结合datax 提供的preSql、 postSql以及占位符&#xff0c;外加另外一张表同步日志表来记录相关同步信息。 三、版本迭代 3.1 初版本 where tbq.opera_date > cast(date_format(DATE_SUB(NOW(), inte…

SpringMVC之文件上传下载

SpringMVC之文件上传下载 一、文件上传二、文件下载三、多文件上传 一、文件上传 配置多功能视图解析器&#xff08;spring-mvc.xml&#xff09;&#xff1a;在Spring MVC的配置文件&#xff08;spring-mvc.xml&#xff09;中配置多功能视图解析器&#xff0c;以支持文件上传。…

C++11 新特性 ⑤ | 仿函数与 lambda 表达式

目录 1、引言 2、仿函数 3、lambda表达式 3.1、lambda表达式的一般形式 3.2、返回类型说明 3.3、捕获列表的规则 3.4、可以捕获哪些变量 3.5、lambda表达式给编程带来的便利 VC常用功能开发汇总&#xff08;专栏文章列表&#xff0c;欢迎订阅&#xff0c;持续更新...&a…

PyTorch实现注意力机制及使用方法汇总,附30篇attention论文

还记得鼎鼎大名的《Attention is All You Need》吗&#xff1f;不过我们今天要聊的重点不是transformer&#xff0c;而是注意力机制。 注意力机制最早应用于计算机视觉领域&#xff0c;后来也逐渐在NLP领域广泛应用&#xff0c;它克服了传统的神经网络的的一些局限&#xff0c…

JAVAEE初阶相关内容第十一弹--多线程(进阶)

目录 一、常见的锁策略 1乐观锁VS悲观锁 1.1乐观锁 1.2悲观锁 2.轻量级锁VS重量级锁 2.1轻量级锁 2.2重量级锁 3.自旋锁VS挂起等待锁 3.1自旋锁 3.2挂起等待锁 4.互斥锁VS读写锁 4.1互斥锁 4.2读写锁 5.公平锁VS非公平锁 5.1公平锁 5.2非公平锁 6.可重入锁VS不…

Codeforces Round 592 (Div 2)(A - G)

Codeforces Round 592 (Div. 2)&#xff08;A - G&#xff09; Dashboard - Codeforces Round 592 (Div. 2) - Codeforces A. Pens and Pencils(思维) 思路&#xff1a;比较完成 绘画课 和 讲座 所需的 最小笔数 和 k 的关系即可。 时间复杂度 O ( 1 ) 时间复杂度O(1) 时间复…

MemJam: A false Dependency attack against constant-time crypto implementations

作者&#xff1a;A. Moghimi, J. Wichelmann, T. Eisenbarth, and B. Sunar. 发布&#xff1a;International Journal of Parallel Programming 时间&#xff1a;Aug 2019. 笔记&#xff1a; 缓存定时攻击 1、攻击原理 共享缓存存在定时侧信道的风险&#xff08;例如在处理…

设计模式课件

设计模式 创建型设计模式的分类&#xff0c;定义结构型设计模式的分类&#xff0c;定义行为型设计模式的分类&#xff0c;定义 设计模式的分类&#xff0c;在23种设计模式中&#xff0c;每一种属于哪一种的设计模式设计模式的应用场景设计模式的图形&#xff08;考察较少&#…

函数式编程:一等对象、作用域和高阶函数的综合指南

函数介绍 函数式编程一等对象的特点作用域&#xff08;scope&#xff09;全局作用域函数作用域 命名空间&#xff08;namespace&#xff09;练习实操求阶乘递归函数幂运算函数测试代码 高阶函数接收函数作为参数&#xff0c;或者将函数作为返回值的函数是高阶函数将函数作为返回…

Gin-swaggo为gin框架提供Swagger 文档

官方: https://github.com/swaggo/gin-swagger 开始使用 为API方法增加注释,加在controller(api)层, See Declarative Comments Format.运行下面命令下载swgo: go get -u github.com/swaggo/swag/cmd/swag Go 1.17后的版本, 使用 go get 安装可执行文件已被废弃. 用go ins…

华为云云耀云服务器L实例评测|带宽,磁盘,CPU,内存以及控制台监控测试

&#x1f3c6;作者简介&#xff0c;黑夜开发者&#xff0c;CSDN领军人物&#xff0c;全栈领域优质创作者✌&#xff0c;CSDN博客专家&#xff0c;阿里云社区专家博主&#xff0c;2023年6月CSDN上海赛道top4。 &#x1f3c6;数年电商行业从业经验&#xff0c;AWS/阿里云资深使用…

Python从零到一构建项目

随着互联网的发展&#xff0c;网络上的信息量急剧增长&#xff0c;而获取、整理和分析这些信息对于很多人来说是一项艰巨的任务。而Python作为一种功能强大的编程语言&#xff0c;它的爬虫能力使得我们能够自动化地从网页中获取数据&#xff0c;大大提高了效率。本文将分享如何…

LeetCode 449. Serialize and Deserialize BST【树,BFS,DFS,栈】困难

本文属于「征服LeetCode」系列文章之一&#xff0c;这一系列正式开始于2021/08/12。由于LeetCode上部分题目有锁&#xff0c;本系列将至少持续到刷完所有无锁题之日为止&#xff1b;由于LeetCode还在不断地创建新题&#xff0c;本系列的终止日期可能是永远。在这一系列刷题文章…

【技术分享】RK Android11系统SD卡启动方法

本文基于Purple Pi OH 3566主板&#xff0c;介绍Android11源码的修改&#xff0c;获得可从SD卡启动的Android11系统镜像。 Purple Pi OH作为一款兼容树莓派的开源主板&#xff0c;采用瑞芯微RK3566 (Cortex-A55) 四核64位超强CPU,主频最高达1.8 GHz,算力高达1Tops&#xff0c;…

R Removing package报错(as ‘lib’ is unspecified)

remove.packages(ggpubr) Removing package from ‘/Library/Frameworks/R.framework/Versions/4.0/Resources/library’ (as ‘lib’ is unspecified) 解决办法&#xff1a; > .libPaths() [1] "/Library/Frameworks/R.framework/Versions/4.0/Resources/library&qu…