图像去抖动(高斯滤波、均值滤波、中值滤波)

采用高斯滤波、均值滤波、中值滤波进行组合去抖动操作 

from PIL import Image, ImageFilter
import os

def remove_strong_shake(input_path, output_path, filter_type='gaussian', radius=5):
    # 打开图像
    img = Image.open(input_path)

    # 选择滤波器类型
    if filter_type == 'gaussian':
        # 使用更大半径的高斯模糊
        img_sharp = img.filter(ImageFilter.UnsharpMask(radius=radius, percent=200, threshold=1))
    elif filter_type == 'mean':
        # 使用均值模糊
        img_sharp = img.filter(ImageFilter.BLUR)
    elif filter_type == 'median':
        # 使用中值滤波
        img_sharp = img.filter(ImageFilter.MedianFilter(size=radius))

    # 保存去抖动后的图像
    img_sharp.save(output_path)

def batch_remove_shake(input_folder, output_folder, filter_type='gaussian', radius=5):
    # 确保输出文件夹存在,如果不存在则创建
    if not os.path.exists(output_folder):
        os.makedirs(output_folder)

    # 遍历输入文件夹中的所有图像文件
    for filename in os.listdir(input_folder):
        if filename.endswith('.png') or filename.endswith('.jpg') or filename.endswith('.jpeg'):
            # 构建完整的文件路径
            input_path = os.path.join(input_folder, filename)

            # 构建输出文件路径
            output_path = os.path.join(output_folder, filename)

            # 调用去抖动函数
            remove_strong_shake(input_path, output_path, filter_type=filter_type, radius=radius)

# 输入文件夹路径和输出文件夹路径
input_folder = '1'
output_folder = '2'

# 调用函数进行批量去抖动
batch_remove_shake(input_folder, output_folder, filter_type='gaussian', radius=10)

print("去抖动完成!")

  • 6
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值