模糊图像处理 去除模糊

定义 (Definition)

Roughly speaking, blurring an image is make the image less sharp. This can be done by smoothing the color transition between the pixels.

粗略地说,模糊图像会使图像清晰度降低。 这可以通过平滑像素之间的颜色过渡来完成。

To accomplish this target, we need to apply a convolution operation of a specialized matrix, called kernel, to the image’s matrix.

为了实现这个目标,我们需要对图像的矩阵应用称为内核的专用矩阵的卷积运算。

What is convolution?

什么是卷积?

Mathematically speaking, a convolution of two matrix, A with size m x n, and B with size p x q, is a (m + p -1) x (n+q-1) matrix C with entries:

从数学上讲,两个矩阵(卷积为mxn的A和卷积为pxq的B)的卷积是一个(m + p -1)x(n + q-1)矩阵C,其条目为:

Convolution in matrices
矩阵卷积

Casually speaking, convolution is just forming a new matrix in which the entries are the sums of product of the entries of one matrix with the corresponding entry of another matrix. All of these products could be calculated along the rows and columns.

随意地说,卷积只是形成一个新矩阵,其中项是一个矩阵的项与另一矩阵的相应项的乘积之和。 所有这些乘积都可以沿着行和列进行计算。

What is kernel?

什么是内核?

Kernel is a matrix that has purpose to transform an image. It is not exclusive to image blurring. It can also be used to detect edges, sharpening edges, and others kind of image transformation. Kernel that used in blurring image is a low-pass filter kernel. It allows low frequency to enter and stop the higher frequency.

内核是旨在转换图像的矩阵。 它并非仅用于图像模糊。 它还可以用于检测边缘,锐化边缘和其他类型的图像转换。 用于模糊图像的内核是低通滤波器内核。 它允许低频进入并停止更高的频率。

应用 (Application)

Why do we even need to blur an image in the first place? After all, doesn’t it make the image become less visible?

为什么我们甚至首先需要模糊图像? 毕竟,这是否会使图像的可见度降低?

It turns out that blurring an image has several purpose.

事实证明,使图像模糊有几个目的。

Firstly, it reduce the noises in the image. A random brightness spot or incorrect color spot, depends on the type of noise, could be reduced by blurring the image with suitable type of blur.

首先,它减少了图像中的噪点。 根据噪声的类型,可以通过使用适当的模糊类型对图像进行模糊处理来减少随机的亮点或不正确的色点。

Blurring an image also reduces the size of image. With appropriate blurring function, we can deblurring the blurred image into the original image. This can be very helpful in transferring a vast size of images.

模糊图像也会缩小图像的尺寸。 使用适当的模糊功能,我们可以将模糊图像去模糊为原始图像。 这对于传输大量图像非常有帮助。

Blurring also used in media. For example, when the news’ picture is not appropriate or explicit. Another use is to hide the face, name, and all private data of people that happens to be included in the image accidentally.

模糊还用于媒体中。 例如,当新闻的图片不合适或不明确时。 另一个用途是隐藏恰好包含在图像中的人的面部,名字和所有私人数据。

Lastly, for entertainment purpose. For instance, in movies and digital artworks. The blurring effect may enhance the feels of lovely citylights scene. Or it may helps movie audience knows this particular scene occurs in past.

最后,出于娱乐目的。 例如,在电影和数字艺术品中。 模糊效果可以增强可爱的城市灯光场景的感觉。 或者它可以帮助电影观众知道这个特定场景过去发生的情况。

模糊类型 (Types of Blurring)

There are a number of blurring filter type that can be used. All has its own characteristics. In this section, I explain two of them: Mean/Box/Average filter and Gaussian filter. In Python, these blur filter is contained in OpenCV package. In all of these section, the module I used is

可以使用多种模糊滤波器类型。 都有自己的特点。 在本节中,我将解释其中的两个:均值/框/平均滤波器和高斯滤波器。 在Python中,这些模糊过滤器包含在OpenCV软件包中。 在所有这些部分中,我使用的模块是

# For blur and convolutionimport cv2# For creating matriximport numpy as np# From showing imagesfrom matplotlib import pyplot as plt

1.均值过滤器(平均过滤器/箱式过滤器) (1. Mean Filter (Average Filter/Box Filter))

This filter takes the average of pixels in kernel and replace the central pixel with this average. This kernel has all of its elements same and sums up to 1. The kernel must be odd-sized. Hence, if the size of the kernel is a x b, the mean filter kernel is

该滤镜获取内核中像素的平均值,然后用该平均值替换中心像素。 该内核的所有元素相同,总和为1。内核必须为奇数大小。 因此,如果内核的大小为axb,则平均滤波器内核为

The general form of mean filter kernel
均值滤波核的一般形式

For example, when a = 3 and b = 3, the kernel is

例如,当a = 3且b = 3时,内核为

The greater value of kernel size, the greater blurring effect because the number of pixels involved is greater and the transition of colors become smoother.

内核大小的值越大,模糊效果越大,这是因为所涉及的像素数更大并且颜色的过渡变得更平滑。

# Import the imageimg = cv2.imread('103057.jpg')# Show the original imageplt.figure()plt.imshow(img) plt.show()# Creating a mean filter kerneldef meankernel(size):    mk = np.ones((size, size), np.float32)/(size ** 2)    return mk# Convolute the kernel with imagefor size in range(3, 14, 2):    blurImg = cv2.filter2D(img, -1, meankernel(size))     plt.figure()    plt.imshow(blurImg)     plt.show()

The OpenCV module has given a function for mean filter: cv2.blur(). Here is the sample code for mean filter with different size of kernel:

OpenCV模块提供了均值过滤器功能:cv2.blur()。 以下是具有不同内核大小的均值过滤器的示例代码:

# Import the imageimg = cv2.imread('103057.jpg')# Show the original imageplt.figure()plt.imshow(img) plt.show()# Show the blurred image with different size of kernelfor size in range(3, 14, 2):    blurImg = cv2.blur(img,(size,size))     plt.figure()    plt.imshow(blurImg)     plt.show()

The original image is:

原始图像是:

Original image.
原始图像。

And the blurred images are

而且模糊的图像是

3 x 3 mean filter kernel — 5 x 5 mean filter kernel
3 x 3平均滤波器内核— 5 x 5平均滤波器内核
7 x 7 mean filter kernel — 9 x 9 mean filter kernel
7 x 7平均过滤器内核— 9 x 9平均过滤器内核
11 x 11 mean filter kernel — 13 x 13 mean filter kernel
11 x 11平均滤波器内核— 13 x 13平均滤波器内核

2.高斯滤波器 (2. Gaussian Filter)

This filter gives different weight to each entries in matrix as entries in kernel. The closer pixel to the selected pixel has greater weight while the further pixel has lower weight. In theory, all pixel in matrix contributes to the value of the entry in final matrix. In fact, the complete (or theoretical) formula for this filter is

该过滤器为矩阵中的每个条目赋予不同的权重,作为内核中的条目。 距所选像素最近的像素具有较大的权重,而另一个像素具有较低的权重。 从理论上讲,矩阵中的所有像素都有助于最终矩阵中条目的值。 实际上,此过滤器的完整(或理论上)公式为

Gaussian function
高斯函数

where x and y is the horizontal and vertical distance. σ stands for the standard deviation. The higher value of σ, the greater blurring effect.

其中x和y是水平和垂直距离。 σ表示标准偏差。 σ值越高,模糊效果越大。

In practice, we estimate the Gaussian function by an odd-sized kernel whose entries are the estimation of the Gaussian function at that pixel. Moreover, this kernel cannot be sufficiently large because the further pixel give smaller contribution to the value of kernel. Often, we ignore the σ and just give it to the program to determine the suitable value for the given size kernel. For example, the approximation of 3 x 3 Gaussian kernel is

在实践中,我们通过一个奇数大小的内核来估计高斯函数,其条目是该像素处的高斯函数的估计。 而且,该内核不能足够大,因为另外的像素对内核的值贡献较小。 通常,我们会忽略σ,而只是将其提供给程序以确定给定大小内核的合适值。 例如,3 x 3高斯核的近似值为

Approximation for 3 x 3 Gaussian kernel. Source: Wikipedia
3 x 3高斯核的近似值。 资料来源:维基百科

To calculate the Gaussian kernel, we can use the OpenCV function of cv2.GaussianBlur(). Here is the sample code for Gaussian filter with different size of kernel:

要计算高斯内核,我们可以使用cv2.GaussianBlur()的OpenCV函数。 以下是具有不同内核大小的高斯滤波器的示例代码:

# Import the imageimg = cv2.imread('103057.jpg')# Show the original imageplt.figure()plt.imshow(img) plt.show()# Show the blurred image with different size of kernelfor size in range(3, 14, 2):    blurImg = cv2.GaussianBlur(img,(size,size), 0)     plt.figure()    plt.imshow(blurImg)     plt.show()

The original image is:

原始图像是:

Original image.
原始图像。

And the blurred images are

而且模糊的图像是

3 x 3 Gaussian kernel — 5 x 5 Gaussian kernel
3 x 3高斯核— 5 x 5高斯核
7 x 7 Gaussian kernel — 9 x 9 Gaussian kernel
7 x 7高斯内核— 9 x 9高斯内核
11 x 11 Gaussian kernel — 13 x 13 Gaussian kernel
11 x 11高斯核— 13 x 13高斯核

比较方式 (Comparison)

The Gaussian kernel gives better result in separating frequencies. But, it is slow because of all the calculation involved. On the other hand, mean kernel works in reducing random noise in image space and it is fast. But, it gives worse performance in separating frequency.

高斯核在分离频率方面给出了更好的结果。 但是,由于涉及所有计算,所以速度很慢。 另一方面,均值内核可以减少图像空间中的随机噪声,而且速度很快。 但是,它在分离频率方面的性能较差。

We can compromise both kernel by apply mean kernel 4 times on the image. The blurred image would look like the Gaussian kernel.

我们可以通过在映像上应用平均4次内核来破坏两个内核。 模糊的图像看起来像是高斯核。

Here is some blurred images with different kernel size

这是一些具有不同内核大小的模糊图像

Original — 3 x 3 mean kernel — 3 x 3 Gaussian kernel
原始— 3 x 3平均内核— 3 x 3高斯内核
Original — 11 x 11 mean kernel — 11 x 11 Gaussian kernel
原始— 11 x 11平均内核— 11 x 11高斯内核
Original — 21 x 21 mean kernel — 21 x 21 Gaussian kernel
原始— 21 x 21平均内核— 21 x 21高斯内核
Original — 51 x 51 mean kernel — 51 x 51 Gaussian kernel
原始— 51 x 51平均内核— 51 x 51高斯内核
11 x 11 Gaussian kernel for σ = 0 (default), 10, and 25
11 x 11高斯核,σ= 0(默认),10和25

翻译自: https://medium.com/@akeylanaufal/how-image-blurring-works-652051aee2d1

模糊图像处理 去除模糊


http://www.taodudu.cc/news/show-863524.html

相关文章:

  • 使用PyTorch进行手写数字识别,在20 k参数中获得99.5%的精度。
  • openai-gpt_您可以使用OpenAI GPT-3语言模型做什么?
  • 梯度下降和随机梯度下降_梯度下降和链链接系统
  • 三行情书代码_用三行代码优化您的交易策略
  • 词嵌入 网络嵌入_词嵌入简介
  • 如何成为数据科学家_成为数据科学家的5大理由
  • 大脑比机器智能_机器大脑的第一步
  • 嵌入式和非嵌入式_我如何向非技术同事解释词嵌入
  • ai与虚拟现实_将AI推向现实世界
  • bert 无标记文本 调优_使用BERT准确标记主观问答内容
  • 机器学习线性回归学习心得_机器学习中的线性回归
  • 安全警报 该站点安全证书_深度学习如何通过实时犯罪警报确保您的安全
  • 现代分层、聚集聚类算法_分层聚类:聚集性和分裂性-解释
  • 特斯拉自动驾驶使用的技术_使用自回归预测特斯拉股价
  • 熊猫分发_实用熊猫指南
  • 救命代码_救命! 如何选择功能?
  • 回归模型评估_评估回归模型的方法
  • gan学到的是什么_GAN推动生物学研究
  • 揭秘机器学习
  • 投影仪投影粉色_DecisionTreeRegressor —停止用于将来的投影!
  • 机器学习中的随机过程_机器学习过程
  • ci/cd heroku_在Heroku上部署Dash或Flask Web应用程序。 简易CI / CD。
  • 图像纹理合成_EnhanceNet:通过自动纹理合成实现单图像超分辨率
  • 变压器耦合和电容耦合_超越变压器和抱抱面的分类
  • 梯度下降法_梯度下降
  • 学习机器学习的项目_辅助项目在机器学习中的重要性
  • 计算机视觉知识基础_我见你:计算机视觉基础知识
  • 配对交易方法_COVID下的自适应配对交易,一种强化学习方法
  • 设计数据密集型应用程序_设计数据密集型应用程序书评
  • pca 主成分分析_超越普通PCA:非线性主成分分析

模糊图像处理 去除模糊_图像模糊如何工作相关推荐

  1. python模糊图像清晰化_视频模糊图像处理

    随着科学技术的不断发展和进步以及人们的安防意识不断加强,人们对于安防技术的要求越来越高.电子监控在许多领域中都得到了广泛的应用,如交通监控.军事侦查.公共场所安全防范等. 清晰的图像能够准确地锁定犯罪 ...

  2. 图像处理-005模糊

    图像处理-005模糊 图像是获取信息的重要来源,但图像存在着噪声(过多的干扰信息),清除噪声有利于后续图像信息获取及特征提取.图像处理中,去噪的过程即模糊的过程. 图像模糊也称图像平滑处理. 在数字图 ...

  3. python图像处理模糊_Python+OpenCV图像处理之模糊操作

    模糊操作是图像处理中最简单和常用的操作之一,该使用的操作之一原因就为了给图像预处理时减低噪声,基于数学的卷积操作 均值模糊,函数 cv2.blur(image,(5,5)),这是一个平滑图片的函数,它 ...

  4. Python+OpenCV图像处理之模糊操作

    模糊操作是图像处理中最简单和常用的操作之一,该使用的操作之一原因就为了给图像预处理时减低噪声,基于数学的卷积操作 均值模糊,函数 cv2.blur(image,(5,5)),这是一个平滑图片的函数,它 ...

  5. 图像运动模糊及其去除

    Introduction 图像去模糊是一个经典的图像复原任务.造成图像模糊的原因有很多,可以主要分为三大类 离焦模糊:场景中的物体处于成像景深范围之外而变得模糊.离焦模糊的去除一般对应着景深的扩展技术 ...

  6. 基于MATLAB的运动模糊图像处理

    基于MATLAB的运动模糊图像处理 研究目的 在交通系统.刑事取证中图像的关键信息至关重要,但是在交通.公安.银行.医学.工业监视.军事侦察和日常生活中常常由于摄像设备的光学系统的失真.调焦不准或相对 ...

  7. 基于matlab的运动模糊图像处理,基于matlab运动模糊图像处理

    基于matlab运动模糊图像处理 基于 MATLAB 的运动模糊图像处 理 提醒: 我参考了文献里的书目和网上的一些代码而完成的,所以误差会比较大,目前 对于从网上下载的模糊图片的处理效果很不好, 这 ...

  8. 模糊图像处理系统的功能

    随着经济的发展和人们生活水平的提高,视频监控在当下的生活中应用范围越来越广,人们对新形势下视频处理技术的应用和发展问题尤为关注. 数字视频和数字图像比传统的图像和视频分辨率要高,处理方便,易于操作和整 ...

  9. 数字图像处理 采样定理_数字图像处理基础知识总结

    第 1 页 第一章 数字图像处理概论 * 图像 是对客观存在对象的一种相似性的.生动性的描述或写真. * 模拟图像 空间坐标和明暗程度都是连续变化的.计算机无法直接处理的图像 * 数字图像 空间坐标和 ...

最新文章

  1. Linux抓包工具tcpdump详解
  2. SpringBoot 集成 thumbnailator (图片缩放,区域裁剪,水印,旋转,保持比例)保姆级教程(含代码)
  3. Android安装apk
  4. 使用一下SQL Server 2008中的新日期函数
  5. 多个ai文件合并成pdf_如何将多个文档合并成PDF?
  6. 数据科学 IPython 笔记本 7.8 分层索引
  7. 显卡风扇不转电脑黑屏_笔记本电脑开不了机是什么原因及常见解决办法
  8. python随机猜数字游戏_Python小游戏——猜数字教程(random库教程)
  9. logback+slf4j作为日志系统
  10. 《Java8实战》-第十章笔记(用Optional取代null)
  11. 随机微分方程学习笔记01 相对布朗运动的Ito积分
  12. w ndows10专业版连接不上网,Win10电脑连不上网怎么回事?Win10电脑连不上网解决办法...
  13. 一款很好用的软还原卡
  14. 从零搭建Hexo博客并部署腾讯云服务器(宝宝级教学)
  15. 大数据项目实战——电信业务大数据分析系统
  16. Python+opencv学习记录3:色彩空间
  17. OpenCv初学者学习笔记(一):图像视频的加载与显示
  18. xls和 xlsx的区别 xlsx Excel文件怎么转换成 xls文件
  19. 输电线路防外力破坏图像数据集(1500张图像,VOC标签,5类目标)
  20. 在Linux下运行你的第一个汇编程序

热门文章

  1. curl -O 下载文件
  2. [LeetCode]: 100: Same Tree
  3. 网页制作技术革新:《HTML5 网站大观》系列文章导航
  4. ASP.NET 服务器控件授权
  5. 高手请进关于RAID和热备
  6. 微信小程序获取openid
  7. W ndows95安装,Windows 95的安装
  8. iis php5.4配置_IIS 8+PHP5.4+SQL server2012配置
  9. java linux 字体设置_Linux操作系统JDK中文字体设置方法介绍
  10. fraction在java_Fraction.java