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. MapReduce06 MapReduce工作机制

    目录 5 MapReduce工作机制(重点) 5.1 MapTask工作机制 5.2 ReduceTask工作机制 5.3 ReduceTask并行度决定机制 手动设置ReduceTask数量 测试R ...

  2. day10设置文件权限

    day10设置文件权限 yum复习 1.修改IP [root@localhost ~]# sed -i 's#.200#.50#g' /etc/sysconfig/network-scripts/if ...

  3. C语言大小端判定

    要判定大小端?需要弄清以下几个问题: 1.当一个变量占多个字节时,变量的指针指向的是低地址 2.什么是大小端? 大端模式:是指数据的高字节保存在内存的低地址中,而数据的低字节保存在内存的高地址中. 小 ...

  4. Flink(一)【基础入门,Yarn、Local模式】

    目录 一.介绍 Spark | Flink 二.快速入门:WC案例 pom依赖 批处理 流处理 有界流 无界流(重要) 三.Yarn模式部署 安装 打包测试,命令行(无界流) Flink on Yar ...

  5. Oracle之DBMS_LOCK包用法详解

    概述与背景 某些并发程序,在高并发的情况下,必须控制好并发请求的运行时间和次序,来保证处理数据的正确性和完整性.对于并发请求的并发控制,EBS系统可以通过Concurrent Program定义界面的 ...

  6. soapui pro 5.1.2 的破解方法

    Protection-4.6,和scz.key这两个文件能破解5.1.2的SoapUI 的Pro版本,mac 和 windows均可.1.拷贝Protection-4.6.jar到soapui安装的l ...

  7. activiti工作流引擎

    参考文章 Activiti-5.18.0与springMvc项目集成和activiti-explorer单独部署Web项目并与业务数据库关联方法(AutoEE_V2实现方式) https://blog ...

  8. Linux:cp -rp

    cp -rp[原文件或目录] [目标文件或目录] -r   复制目录 - p   保留文件属性 范例: cp -r /yy/k /yy/u /mm 复制目录u和目录k到目录mm中 cp -r /yy/ ...

  9. 将图片打印到word中

    1.生成模板文件 工具类: package com.sfec.snmgr.track.utils;import com.alibam.core.wechat.util.QRCodeUtil;impor ...

  10. Springboot集成SpringSecurity

    一.Spring security 是什么? Spring Security是一个能够为基于Spring的企业应用系统提供声明式的安全访问控制解决方案的安全框架. 它提供了一组可以在Spring应用上 ...