美文网首页
109. 几何均值滤波

109. 几何均值滤波

作者: 大龙10 | 来源:发表于2025-09-01 06:53 被阅读0次

7. 图像复原与重建索引

一、退化图像复原

  • 图像复原是对图像退化的过程进行估计,并补偿退化过程造成的失真,以便获得未经退化的原始图像或原始图像的最优估值,从而改善图像质量的一种方法。

  • 典型的图像复原方法是根据图像退化的先验知识建立退化模型,以退化模型为基础采用滤波等手段进行处理,使复原后的图像符合一定的准则,达到改善图像质量的目的。

  • 因此,图像复原是沿着质量降低的逆过程来重现真实的原始图像,通过去模糊函数而去除图像模糊。

二、几何均值滤波

  • 几何均值滤波器是维纳滤波的推广,其传递函数由括号内幂次分别为 α 和 1 − α 的两个表达式组成


    式中,\alpha 和 β 是非负的实常数。
  • 当 α=1/2 时几何均值滤波器是幂次相同的两个量的乘积,这就是几何均值的含义。

  • 当 α=1/2,β=1 时,称为频谱均衡滤波器。当 α=1 时,简化为逆滤波器;当α=0 时,简化为带参数的维纳滤波器,并在β=1 时成为标准维纳滤波器。

三、例程

  • 9.23: 几何均值滤波
import cv2
import numpy as np
from matplotlib import pyplot as plt

# 9.23: 几何均值滤波器
def getMotionDsf(shape, angle, dist):
    xCenter = (shape[0] - 1) / 2
    yCenter = (shape[1] - 1) / 2
    sinVal = np.sin(angle * np.pi / 180)
    cosVal = np.cos(angle * np.pi / 180)
    PSF = np.zeros(shape)  # 点扩散函数
    for i in range(dist):  # 将对应角度上motion_dis个点置成1
        xOffset = round(sinVal * i)
        yOffset = round(cosVal * i)
        PSF[int(xCenter - xOffset), int(yCenter + yOffset)] = 1
    return PSF / PSF.sum()  # 归一化

def makeBlurred(image, PSF, eps):  # 对图片进行运动模糊
    fftImg = np.fft.fft2(image)  # 进行二维数组的傅里叶变换
    fftPSF = np.fft.fft2(PSF) + eps
    fftBlur = np.fft.ifft2(fftImg * fftPSF)
    fftBlur = np.abs(np.fft.fftshift(fftBlur))
    return fftBlur

def wienerFilter(input, PSF, eps, K=0.01):  # 维纳滤波,K=0.01
    fftImg = np.fft.fft2(input)
    fftPSF = np.fft.fft2(PSF) + eps
    fftWiener = np.conj(fftPSF) / (np.abs(fftPSF)**2 + K)
    imgWienerFilter = np.fft.ifft2(fftImg * fftWiener)
    imgWienerFilter = np.abs(np.fft.fftshift(imgWienerFilter))
    return imgWienerFilter

def geometricMeanFilter(image, PSF, eps, K=1, alpha=1, beta=1):  # 几何均值滤波器
    fftImg = np.fft.fft2(image)
    fftPSF = np.fft.fft2(PSF)
    conj = fftPSF.conj()
    squarePSF = (fftPSF * conj).real
    Huv = np.power(conj / (squarePSF), alpha) * np.power(conj / (squarePSF + beta * K), 1-alpha)
    ifftImg = np.fft.ifft2(fftImg * Huv)
    ifftShift = np.abs(np.fft.fftshift(ifftImg))
    imgGMFilter = np.uint8(cv2.normalize(np.abs(ifftShift), None, 0, 255, cv2.NORM_MINMAX))  # 归一化为 [0,255]
    return imgGMFilter


# # 读取原始图像
img = cv2.imread(r"E:/OpenCV/Fig0507b.tif", 0)  # flags=0 读取为灰度图像
hImg, wImg = img.shape[:2]

# 带有噪声的运动模糊
PSF = getMotionDsf((hImg, wImg), 45, 100)  # 运动模糊函数
imgBlurred = np.abs(makeBlurred(img, PSF, 1e-6))  # 生成不含噪声的运动模糊图像

scale = 0.01  # 噪声方差
noisy = imgBlurred.std() * np.random.normal(loc=0.0, scale=scale, size=imgBlurred.shape)  # 添加高斯噪声
imgBlurNoisy = imgBlurred + noisy  # 带有噪声的运动模糊
imgWienerFilter = wienerFilter(imgBlurNoisy, PSF, scale, K=0.01)  # 对含有噪声的模糊图像进行维纳滤波
imgGMFilter = geometricMeanFilter(imgBlurNoisy, PSF, scale, K=0.01, alpha=0.5, beta=1)  # 约束最小二乘方滤波

plt.figure(figsize=(9, 7))
plt.subplot(231), plt.title("blurred image (dev=0.01)"), plt.axis('off'), plt.imshow(imgBlurNoisy, 'gray')
plt.subplot(232), plt.title("Wiener filter"), plt.axis('off'), plt.imshow(imgWienerFilter, 'gray')
plt.subplot(233), plt.title("geometric mean filter"), plt.axis('off'), plt.imshow(imgGMFilter, 'gray')

scale = 0.1  # 噪声方差
noisy = imgBlurred.std() * np.random.normal(loc=0.0, scale=scale, size=imgBlurred.shape)  # 添加高斯噪声
imgBlurNoisy = imgBlurred + noisy  # 带有噪声的运动模糊
imgWienerFilter = wienerFilter(imgBlurNoisy, PSF, scale, K=0.01)  # 维纳滤波
imgGMFilter = geometricMeanFilter(imgBlurNoisy, PSF, scale, K=0.01, alpha=0, beta=1)  # 约束最小二乘方滤波

plt.subplot(234), plt.title("blurred image (dev=0.1)"), plt.axis('off'), plt.imshow(imgBlurNoisy, 'gray')
plt.subplot(235), plt.title("Wiener filter"), plt.axis('off'), plt.imshow(imgWienerFilter, 'gray')
plt.subplot(236), plt.title("geometric mean filter"), plt.axis('off'), plt.imshow(imgGMFilter, 'gray')
plt.tight_layout()
plt.show()

四、资料

youcans_的博客:
https://blog.csdn.net/youcans/article/details/123063149

相关文章

  • opencv python版-lesson 16

    均值滤波,高斯滤波,双边滤波

  • 7.2 方框滤波

    OpenCV还提供了方框滤波方式,与均值滤波的不同在于,方框滤波不会计算像素均值,在均值滤波中,滤波结果的像素值是...

  • 55. 高斯均值滤波

    本文使用高斯滤波api和均值滤波的源码实现图像滤波 高斯滤波: 结果如下: 均值滤波: 实现步骤: 读取原图片 指...

  • 10高斯均值滤波

    高斯滤波_模块去噪声 均值滤波_源码

  • OpenCV For iOS(六)方框、均值、高斯、中值、双边滤

    本节主要记录OpenCV 两类五种常见的滤波方式: 线性滤波:方框滤波、均值滤波、高斯滤波非线性滤波: 中值滤波、...

  • 均值滤波

    均值滤波使用像素点周围一定区域的像素的均值替换当前像素点的值。均值滤波可以平滑图像,但是对噪声几乎没有效果,最多只...

  • 均值滤波

    《OpenCV轻松入门:面向Python》读书笔记作者:李立宗出版社:电子工业出版社出版时间:2019-05 第7...

  • 7.6 2D卷积

    OpencV提供了多种滤波方式,来实现平滑图像的效果,例如均值滤波、方框滤波、高斯滤波、中值滤波等,大多数滤波方式...

  • 高斯滤波

    高斯滤波和均值滤波的原理一样,不过在均值滤波中像素点的权重都一样,而在高斯滤波中越靠近中心的像素点的权重越大,具体...

  • 009-Opencv笔记-高斯双边模糊-矩阵掩膜

    中值滤波 中值滤波对椒盐噪声有很好的抑制作用 均值模糊无法克服边缘像素信息丢失缺陷。原因是均值滤波是基于平均权重 ...

网友评论

      本文标题:109. 几何均值滤波

      本文链接:https://www.haomeiwen.com/subject/chbcajtx.html