- Python Pillow 教程
- Python Pillow - 首页
- Python Pillow - 概述
- Python Pillow - 环境配置
- 基本图像操作
- Python Pillow - 图像处理
- Python Pillow - 调整图像大小
- Python Pillow - 翻转和旋转图像
- Python Pillow - 裁剪图像
- Python Pillow - 为图像添加边框
- Python Pillow - 识别图像文件
- Python Pillow - 合并图像
- Python Pillow - 剪切和粘贴图像
- Python Pillow - 图像滚动
- Python Pillow - 在图像上写入文本
- Python Pillow - ImageDraw 模块
- Python Pillow - 合并两张图像
- Python Pillow - 创建缩略图
- Python Pillow - 创建水印
- Python Pillow - 图像序列
- Python Pillow 颜色转换
- Python Pillow - 图像颜色
- Python Pillow - 创建彩色图像
- Python Pillow - 将颜色字符串转换为 RGB 颜色值
- Python Pillow - 将颜色字符串转换为灰度值
- Python Pillow - 通过更改像素值来更改颜色
- 图像处理
- Python Pillow - 降噪
- Python Pillow - 更改图像模式
- Python Pillow - 图像合成
- Python Pillow - 使用 Alpha 通道
- Python Pillow - 应用透视变换
- 图像滤镜
- Python Pillow - 为图像添加滤镜
- Python Pillow - 卷积滤镜
- Python Pillow - 模糊图像
- Python Pillow - 边缘检测
- Python Pillow - 浮雕图像
- Python Pillow - 增强边缘
- Python Pillow - 非锐化掩膜滤镜
- 图像增强和校正
- Python Pillow - 增强对比度
- Python Pillow - 增强锐度
- Python Pillow - 增强颜色
- Python Pillow - 校正色彩平衡
- Python Pillow - 降噪
- 图像分析
- Python Pillow - 提取图像元数据
- Python Pillow - 识别颜色
- 高级主题
- Python Pillow - 创建动画 GIF
- Python Pillow - 批量处理图像
- Python Pillow - 转换图像文件格式
- Python Pillow - 为图像添加填充
- Python Pillow - 颜色反转
- Python Pillow 与 NumPy 的机器学习
- Python Pillow 与 Tkinter 的 BitmapImage 和 PhotoImage 对象
- Image 模块
- Python Pillow - 图像混合
- Python Pillow 有用资源
- Python Pillow - 快速指南
- Python Pillow - 函数参考
- Python Pillow - 有用资源
- Python Pillow - 讨论
Python Pillow - 降噪
在 Pillow 中降噪是指应用各种技术和滤镜来去除或减少图像中不希望出现的伪影或不规则性,这些伪影或不规则性会降低图像质量。图像噪声是图像中亮度或颜色的随机变化,通常是由低光照条件、电子干扰或图像传感器缺陷等因素造成的。降噪是图像处理中提高图像整体质量的重要步骤。
Pillow (PIL) 提供了几个内置滤镜和方法来减少图像噪声。Pillow 中一些常见的降噪技术和滤镜包括:
- 高斯模糊:应用高斯模糊滤镜可以帮助平滑减少噪声,方法是平均每个像素周围像素的值。这会产生更平滑的外观,并可以减少噪声的影响。模糊程度可以调整以控制降噪的程度。
- 中值滤波器:中值滤波器用相邻像素的中值替换每个像素的值。中值滤波器对于去除椒盐噪声(孤立像素具有极值)非常有效。它用相邻像素的中值替换每个像素的值。
- 双边滤波器:双边滤波器在平滑图像的同时保留边缘。它可以有效地减少噪声,同时保持图像细节。
- 降噪算法:Pillow 支持各种降噪算法,例如双边滤波器、全变差 (TV) 降噪算法或非局部均值 (NLMeans) 滤波器,这些算法可以在保留图像细节的同时减少噪声。
- 阈值化:我们可以对图像应用阈值来去除噪声,方法是将低于某个阈值的像素值转换为黑色,将高于阈值的像素值转换为白色,从而有效地将图像二值化。
Python Pillow - Image.filter() 方法
Image.filter() 是 Python 图像库 (PIL) 或其分支 Pillow 中用于将各种图像滤镜和增强功能应用于图像的方法。滤镜是图像处理操作,可用于以不同方式修改图像,例如模糊、锐化或增强某些特征。此方法允许我们将各种预定义滤镜应用于图像。
Pillow 提供了各种预定义滤镜,我们可以与 Image.filter() 一起使用,包括:
ImageFilter.BLUR - 对图像应用简单的模糊效果。
ImageFilter.CONTOUR - 增强图像中对象的轮廓。
ImageFilter.DETAIL - 增强图像的细节。
ImageFilter.EDGE_ENHANCE - 强调图像中的边缘。
ImageFilter.EMBOSS - 为图像添加 3D 浮雕效果。
ImageFilter.SHARPEN - 锐化图像。
语法
使用 Image.filter() 的语法和参数如下:
output_image = input_image.filter(filter_name, filter_parameters)
其中,
input_image - 这是我们要应用滤镜的源图像。
filter_name - 这是一个字符串,指定我们要应用的滤镜的名称。Pillow 提供了各种内置滤镜,我们可以使用这些滤镜名称之一作为字符串。例如,“GaussianBlur”、“MedianFilter”、“Sharpen”等。我们也可以通过提供内核(一系列值)作为滤镜来定义自定义滤镜。
filter_parameters (可选) - 一些滤镜可能接受控制滤镜行为的附加参数。这些参数特定于正在使用的特定滤镜。如果我们正在应用的滤镜需要参数,我们将把它们作为参数传递给 filter_parameters 部分。
示例
在这个示例中,我们尝试通过将 ImageFilter.BLUR 作为输入参数传递给 Image.filter() 方法来模糊图像。
from PIL import Image, ImageFilter
#Open an image
input_image = Image.open("Images/flowers.jpg")
#Apply Gaussian blur to the image
output_image = input_image.filter(ImageFilter.BLUR())
#Save the resulting image
output_image.save("output Image/blur.jpg")
output_image.show()
待处理图像
输出
示例
在这个例子中,我们使用 ImageFilter.BoxBlur() 方法模糊图像的特定部分。
from PIL import Image, ImageFilter
#Open an image
input_image = Image.open("Images/rose.jpg")
#Apply Gaussian blur to the image
output_image = input_image.filter(ImageFilter.BoxBlur(20))
#Save the resulting image
output_image.save("output Image/blur.jpg")
output_image.show()
待处理图像
输出