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. JavaScript中var与let的异同点

    var是JavaScript刚出现时就存在的变量声明关键字,而let作为ES6才出现的变量声明关键字,无疑两者之间存在着很大的区别.那么具体有哪些区别呢? 1.作用域表现形式不同,var是函数作用域, ...

  2. windows下 apache 二级域名相关配置 【转】

    转至: http://www.th7.cn/Program/php/201306/141305.shtml 今天给大家总结下 windows 下 apache的二级域名的相关配置 下面就利用本地127 ...

  3. myatoi

    atoi (表示 ascii to integer)是把字符串转换成整型数的一个函数,应用在计算机程序和办公软件中.int atoi(const char *nptr) 函数会扫描参数 nptr字符串 ...

  4. 【STM8】外挂存储器W25Q16

    好像有几张图片被强制缩小了?看到这篇博客的人先对你们说声抱歉,我不知道怎么设置 文字就可以很长(文章宽度的全部),图片就只有文章宽度的2/3宽度 开新分页应该就是原始尺寸了,这点还是和大家说抱歉... ...

  5. C++ 之杂记

    今天做了一个题,代码不难,但是编译的时候就恼火,老是报错,也不告诉我错哪了.... 之前的代码是这样的,在main函数中调用这个类的构造函数,就一直报错,但是不知道原因,后来加上了const 就好了. ...

  6. Spring DM 2.0 环境配置 解决Log4j问题

    搭建 spring dm 2.0 环境出的问题 log4j 的问题解决办法是 一.引入SpringDM2.0的Bundle,最后完成如下图所示:注意:要引入slf4j.api.slf4j.log4j. ...

  7. 【Linux】【Services】【SaaS】Docker+kubernetes(11. 构建复杂的高可用网络)

    1. 简介 flannel在实战阶段貌似不能胜任在灾难恢复时候异地的网络,打算用openvswith试试

  8. 【Office】【Excel】将多个工作表合为一个工作表

    在工作表中按下alt+F11打开vba编辑窗口,在菜单栏中选择[插入]=>[模板],将下面的代码粘贴过去,然后运行即可 点击查看代码 Sub 合并当前工作簿下的所有工作表() On Error ...

  9. Apifox(2)快速上手apifox

    快速上手 使用场景 Apifox 是接口管理.开发.测试全流程集成工具,使用受众为整个研发技术团队,主要使用者为前端开发.后端开发和测试人员. 前端开发 接口文档管理 接口数据 Mock 接口调试 前 ...

  10. C#和.NET 框架

    C#和.NET框架 在.NET之前 20世纪90年代,微软平台多数程序员使用VB.C或C++.他们使用的技术都有问题. 技术 问题 纯Win32 API 不是面向对象,工作量比MFC大 MFC(Mic ...