波浪纹噪声无法消除,有好的方法吗?

import cv2
import pywt
import numpy as np


def wavelet_denoise(image, wavelet='db4', level=1, mode='soft'):
    # 将图像转换为灰度图
    if len(image.shape) == 3:
        image = cv2.cvtColor(image, cv2.COLOR_BGR2GRAY)

    # 进行小波分解
    coeffs = pywt.wavedec2(image, wavelet, level=level)

    # 对每个细节系数应用阈值处理
    threshold = np.std(coeffs[-1]) * np.sqrt(2 * np.log2(image.size))
    new_coeffs = [coeffs[0]]
    for detail_coeffs in coeffs[1:]:
        new_detail_coeffs = [pywt.threshold(d, threshold, mode=mode) for d in detail_coeffs]
        new_coeffs.append(new_detail_coeffs)

    # 进行小波重构
    denoised_image = pywt.waverec2(new_coeffs, wavelet)

    # 将像素值限制在 0 到 255 之间
    denoised_image = np.clip(denoised_image, 0, 255).astype(np.uint8)

    return denoised_image


# 读取图像
image = cv2.imread('2.png')

# 进行小波去噪
denoised_image = wavelet_denoise(image)

cv2.imwrite('3.png', denoised_image)

# 显示原始图像和去噪后的图像
cv2.imshow('Original Image', image)
cv2.imshow('Denoised Image', denoised_image)
cv2.waitKey(0)
cv2.destroyAllWindows()
    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

potato_potato_123

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值