Gonzalez R. C. and Woods R. E. Digital Image Processing (Forth Edition).

import cv2
import matplotlib.pyplot as plt
import numpy as np

FILTERS

filters实际上就是通过一些特殊的kernel \(w\) 对图片进行如下操作:

\[g(x, y) = \sum_{s=-a}^a \sum_{t=-b}^b w(s, t) f(x+s, y+t), \: x = 1,2,\cdots, M, \: y = 1, 2,\cdots N.
\]

其中\(w(s, t) \in \mathbb{R}^{m \times n}, m=2a+1, n = 2b+1\).

注: 注意到上面会出现\(f(-1, -1)\)之类的未定义情况, 常见的处理方式是在图片周围加padding(分别为pad a, b), 比如补0或者镜像补.

用卷积的目的是其特别的性质:

  1. \(f * g = g * f\);
  2. \(f * (g * h) = (f * g) * h\);
  3. \(f * (g + h) = (f * g) + (g * h)\).

注: \(f, g, h\)应当形状一致 (或者每次卷积完同样进行padding).

特别的, 如果

\[w = uv^T,
\]

\[w * f = u * (v^T * f).
\]

可以显著降低计算量.

Box Filter Kernels

\[w_{ij} = \frac{1}{mn}, \quad i=1,2,\cdots, m, \: j=1,2,\cdots, n.
\]
img = cv2.imread("./pics/alphabeta.png")
img.shape
img = cv2.cvtColor(img, cv2.COLOR_BGR2GRAY) # 由于是截图, 先转成灰度图
plt.imshow(img, cmap='gray')

# 或者等价地用 cv2.blur(img, (m, n))
kernels = [np.ones((i, i)) / (i * i) for i in [3, 11, 21]]
imgs_smoothed = [cv2.filter2D(img, -1, kernel) for kernel in kernels]
fig, axes = plt.subplots(2, 2)
axes[0, 0].imshow(img, cmap='gray')
axes[0, 0].set_title("raw")
axes[0, 1].imshow(imgs_smoothed[0], cmap="gray")
axes[0, 1].set_title("3x3")
axes[1, 0].imshow(imgs_smoothed[1], cmap="gray")
axes[1, 0].set_title("11x11")
axes[1, 1].imshow(imgs_smoothed[2], cmap="gray")
axes[1, 1].set_title("21x21")
plt.tight_layout()
plt.show()

Lowpass Gaussian Filter Kernels

\[w(s, t) = G(s, t) = K e^{-\frac{s^2+t^2}{2\sigma^2}},
\]

高斯分布的特点是绝大部分集中于\((-3\sigma, +3\sigma)\)之间, 故一般\(w\)的大小选择为\((-6\sigma, +6\sigma)\), 需要注意的是, \(\sigma\)的选择和图片的大小息息相关.

imgs_smoothed = [cv2.GaussianBlur(img, ksize=ksize, sigmaX=sigma) for (ksize, sigma) in [((5, 5), 1), ((21, 21), 3.5), ((43, 43), 7)]]
fig, axes = plt.subplots(1, 4)
axes[0].imshow(img, cmap='gray')
axes[0].set_title("raw")
axes[1].imshow(imgs_smoothed[0], cmap="gray")
axes[1].set_title("5x5, 1")
axes[2].imshow(imgs_smoothed[1], cmap="gray")
axes[2].set_title("21x21, 3.5")
axes[3].imshow(imgs_smoothed[2], cmap="gray")
axes[3].set_title("43x43, 7")
plt.tight_layout()
plt.show()

Order-Statistic (Nonlinear) Filters

即\(g(x, y)\)由\((x, y)\)周围的点的一个某个顺序的值代替, 比如median.

imgs_smoothed = [cv2.medianBlur(img, ksize=ksize) for ksize in [3, 7, 15]]
fig, axes = plt.subplots(1, 4)
axes[0].imshow(img, cmap='gray')
axes[0].set_title("raw")
axes[1].imshow(imgs_smoothed[0], cmap="gray")
axes[1].set_title("3x3")
axes[2].imshow(imgs_smoothed[1], cmap="gray")
axes[2].set_title("7x7")
axes[3].imshow(imgs_smoothed[2], cmap="gray")
axes[3].set_title("15x15")
plt.tight_layout()
plt.show()

SMOOTHING (LOWPASS) SPATIAL FILTERS的更多相关文章

  1. SHARPENING (HIGHPASS) SPATIAL FILTERS

    目录 Laplacian UNSHARP MASKING AND HIGHBOOST FILTERING First-Order Derivatives Roberts cross-gradient ...

  2. 【Duke-Image】Week_3 Spatial processing

    Chapter_3 Intensity Transsformations and Spatial Filtering 灰度变换与空间滤波 Intensity transformation functi ...

  3. Image Processing and Analysis_8_Edge Detection:The Design and Use of Steerable Filters——1991

    此主要讨论图像处理与分析.虽然计算机视觉部分的有些内容比如特 征提取等也可以归结到图像分析中来,但鉴于它们与计算机视觉的紧密联系,以 及它们的出处,没有把它们纳入到图像处理与分析中来.同样,这里面也有 ...

  4. EAC3 enhanced channel coupling

    Enhanced channel coupling是一种spatial coding 技术,在传统的channel coupling的基础上添加了phase compensation, de-corr ...

  5. A simple test

        博士生课程报告       视觉信息检索技术                 博 士 生:施 智 平 指导老师:史忠植 研究员       中国科学院计算技术研究所   2005年1月   目 ...

  6. IIR filter design from analog filter

    Analog filter和digital filter的联系: z变换与Laplace从数学上的关系为: 但这种关系在实际应用上不好实现,因此通常使用biliner transform(https: ...

  7. fMRI: spatial smoothing

    Source: Brain voyager support Theoretical Background Spatial smoothing means that data points are av ...

  8. 【DIP, OpenCV】Some Kinds Of Image Smoothing Methodologies

    In digital image processing(DIP), many methods are used in smoothing images in order to suppress noi ...

  9. Smoothing in fMRI analysis (FAQ)

    Source: http://mindhive.mit.edu/node/112 1. What is smoothing? "Smoothing" is generally us ...

随机推荐

  1. css系列,选择器权重计算方式

    CSS选择器分基本选择器(元素选择器,类选择器,通配符选择器,ID选择器,关系选择器), 属性选择器,伪类选择器,伪元素选择器,以及一些特殊选择器,如has,not等. 在CSS中,权重决定了哪些CS ...

  2. jQuery无限载入瀑布流 【转载】

    转载至 http://wuyuans.com/2013/08/jquery-masonry-infinite-scroll/ jQuery无限载入瀑布流 好久没更新日志了,一来我比较懒,二来最近也比较 ...

  3. HongYun项目启动

    一个前后端分离项目的启动顺序: 数据库启动, stams 后台springboot启动 中间路由启动,比如nginx,如果有的话:有这一层,后台可以设置负载均衡,可以动态部署 前端启动

  4. static JAVA

    static 关键字:使用static修饰的变量是类变量,属于该类本身,没有使用static修饰符的成员变量是实例变量,属于该类的实例.由于同一个JVM内只对应一个Class对象,因此同一个JVM内的 ...

  5. Spring支持5种类型的增强

    Spring支持5种类型的增强:1.前置增强:org.springframework.aop.BeforeAdvice代表前置增强,因为Spring只支持方法级的增强,所以MethodBeforeAd ...

  6. springboot+vue脚手架使用nginx前后端分离

    1.vue配置 /** * * 相对于该配置的nginx服务器请参考nginx配置文件 * */ module.exports = { // 基本路径 publicPath: '/', // 输出文件 ...

  7. java通过jdbc连接数据库并更新数据(包括java.util.Date类型数据的更新)

    一.步骤 1.获取Date实例,并通过getTime()方法获得毫秒数: 2.将获取的毫秒数存储到数据库中,注意存储类型为nvarchar(20): 3.读取数据库的毫秒数,作为Date构造方法的参数 ...

  8. 【C/C++】01背包问题/动态规划

    按小蓝书上写的大数据情况下没过,按解答区一个大佬的修改了过了 #include <bits/stdc++.h> using namespace std; class Solution { ...

  9. 什么是JMS规范?

    一.简介 JMS是什么:JMS是Java提供的一套技术规范和关于消息中间件的协议 JMS干什么用:通过生产者Producer,消息服务器,以及消费者通力合作,使异构系统能进行集成通信,缓解系统瓶颈,提 ...

  10. CPU的中断

    目录 一.简介 二.具体 方式 硬中断 软中断 中断切换 网卡中断 三.中断查看 一.简介 中断其实就是由硬件或软件所发送的一种称为IRQ(中断请求)的信号.中断允许让设备,如键盘,串口卡,并口等设备 ...