wiener滤波图像处理_wiener滤波 - CSDN
  • 实验要求 ...  (c) 如图5.26(b)所示,对图像5.26(a) 进行+45o 方向,T = 1 的污损滤波;   (d) 对污损后的图像加入均值为0,方差为10 的高斯噪声;   (e) 编写程序使用公式(5.8-6)所示的参数维

    实验要求

      (a) 编写一个给图像中添加高斯噪声的程序,程序的输入参数为噪声的均值与方差。

      (b) 编写程序实现公式(5.6-11)所示的污损滤波;

      (c) 如图5.26(b)所示,对图像5.26(a) 进行+45o 方向,T = 1 的污损滤波;

      (d) 对污损后的图像加入均值为0,方差为10 的高斯噪声;

      (e) 编写程序使用公式(5.8-6)所示的参数维纳滤波对图像进行恢复。


    技术论述

    1、高斯噪声

      高斯噪声是指概率密度函数服从高斯分布(即正态分布)的一类噪声。常见的高斯噪声包括起伏噪声、宇宙噪声、热噪声和散粒噪声等等。

      在空间域和频率域中,由于高斯噪声在数学上的易处理性,故实践中常用这种噪声模型。

    这里写图片描述

      高斯随机变量z的PDF由上式给出,其中z表示灰度值,u表示z的均值,σ表示z的方差。当z服从高斯分布时,其值有大约70%落在范围[(u-σ),(u+σ)]内,有大约95%落在范围[(u-2σ),(u+2σ)]内。

    这里写图片描述

      在MATLAB中,通常使用randn()函数来产生标准正态分布的随机数或矩阵。

    2、污损滤波

      通过均匀线性运动模糊对图像进行污损滤波。假定图像只在x方向以给定的速度x0(t)=at/T 做匀速直线运动。当 t=T 时,图像位移的总距离为a,则有

    这里写图片描述

      若允许y分量也随着变化,按 y0=bt/T 给出的运动,则退化函数变为

    这里写图片描述

    3、参数维纳滤波

      维纳滤波又称最小均方滤波,是一种综合了退化函数和噪声统计特征进行复原处理的方法。它是一种基于最小均方误差准则、对平稳过程的最优估计器。这种滤波器的输出与期望输出之间的均方误差为最小,因此,维纳滤波是一个最佳滤波系统,可用于提取被平稳噪声所污染的信号。

      该方法建立在图像和噪声都是随机变量的基础上,目标是找到未污染图像f的一个估计,使它们之间的均方误差最小。这种误差度量为:

    这里写图片描述

      当未退化图像的功率谱未知或者是不能估计时,通常使用的一种方法是由下面的表达式来近似:

    这里写图片描述

      其中,K是一个加到|H(u,v)|2的所有项上的特定常数。


    实验结果

    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述
    这里写图片描述


    实验程序

    % --------------------------实验要求------------------------------------------
    
    img = imread('Fig5.26(a).jpg');                             % 原图像
    img_fouling = fouling_filter(img,0.1,0.1,1);                % 污损滤波
    img_gaussian_10 = gaussian_noise(img_fouling,0,10);         % 高斯噪声
    img_wiener = wiener_filter(img,img_gaussian_10,0.1);        % 维纳滤波
    
    subplot(3,1,1);imshow(img);title('原图像');
    subplot(3,1,2);imshow(img_fouling);title('污损滤波: +45°,T=1');
    subplot(3,1,3);imshow(img_gaussian_10);  title('高斯噪声: 均值0,方差10');
    figure;
    imshow(img_wiener);title('维纳滤波图像');
    
    
    % ------------------------ 高斯噪声比较-----------------------------------------
    
    img_gaussian_100 = gaussian_noise(img_fouling,0,100);       % 均值0,方差100
    img_gaussian_1000 = gaussian_noise(img_fouling,0,1000);     % 均值0,方差1000
    
    figure;
    subplot(2,1,1);imshow(img_gaussian_100); title('高斯噪声: 均值0,方差100(仅作对比)');
    subplot(2,1,2);imshow(img_gaussian_1000);title('高斯噪声: 均值0,方差1000(仅作对比)');
    
    
    % ------------------------ 调整合适参数-----------------------------------------
    
    img_fouling = fouling_filter(img,0.01,0.01,1);              % 污损滤波
    img_gaussian_10 = gaussian_noise(img_fouling,0,10);       % 高斯噪声
    img_wiener = wiener_filter(img,img_gaussian_10,0.1);        % 维纳滤波
    
    figure;
    subplot(3,1,1);imshow(img_fouling);title('污损滤波: +45°,T=1');
    subplot(3,1,2);imshow(img_gaussian_10);title('高斯噪声: 均值0,方差10');
    subplot(3,1,3);imshow(img_wiener);title('调整参数后的维纳滤波图像');
    
    
    % ------------------------MATLAB自带函数------------------------------------
    
    psf = fspecial('motion',25,45);
    mf = imfilter(img,psf,'circular','conv');
    noise = imnoise(img,'gaussian',0,10);
    mfn = mf + noise;
    nsr = sum(noise(:).^2)/sum(mf(:).^2);
    img_out = deconvwnr(mfn,psf,nsr);
    
    figure;
    subplot(3,1,1);imshow(mf);title('Matlab自带污损滤波');
    subplot(3,1,2);imshow(mfn);title('Matlab添加高斯噪声');
    subplot(3,1,3);imshow(img_out);title('Matlab自带维纳滤波');
    % -------------------------------------------END-----------------------------------------------
    % --------------------------------------污损滤波-----------------------------------------------
    
    function img_fouling = fouling_filter(img,a,b,T) 
    
    [M,N] = size(img);
    F = fft2(img);
    
    for u = 1:M
        for v = 1:N
            K(u,v) = pi * (u * a + v * b);
            H(u,v) = T * sin(K(u,v)) * exp(-1j * K(u,v))/K(u,v);
            G(u,v) = H(u,v) * F(u,v);
        end
    end
    
    img_fouling = ifft2(G);
    img_fouling = uint8(abs(img_fouling));
    
    end
    % ----------------------------------给图像添加高斯噪声-----------------------------------
    
    function img_noise = gaussian_noise(img,mean,var) 
    
    [M,N] = size(img);
    add_noise = mean + randn(M,N)*sqrt(var);
    img_noise = img + uint8(add_noise);
    
    end
    % --------------------------------------维纳滤波-----------------------------------------------
    
    function img_wiener = wiener_filter(img_src,img_degradation,K) 
    
    [M,N] = size(img_src);
    S = fft2(img_src);
    G = fft2(img_degradation);
    
    for u = 1:M
        for v = 1:N
            H(u,v) = G(u,v)/S(u,v);
            F(u,v) = 1/H(u,v)*(abs(H(u,v)))^2/((abs(H(u,v)))^2+K)*G(u,v);
        end
    end
    
    img_wiener = ifft2((F));
    img_wiener = uint8(abs(img_wiener));
    
    end
    
    展开全文
  • ispforfun会在从今天开始定期给大家带来维纳滤波器在图像处理中应用。本节讲诉维纳滤波器在图像去噪中的简单应用。  让我们从Matlab中的函数wiener2开始。Matlab的help中对wiener2的说明如下:  wiener2估计图像...

      维纳滤波器是一种自适应的滤波器,在数字信号处理中有着广泛的应用。ispforfun会在从今天开始定期给大家带来维纳滤波器在图像处理中应用。本节讲诉维纳滤波器在图像去噪中的简单应用。

           让我们从Matlab中的函数wiener2开始。Matlab的help中对wiener2的说明如下:

           wiener2估计图像中每个像素的局部均值和局部方差,


          其中,是图像A中每个像素的NXM邻域。维纳滤波器的去噪原理如下:


          其中是噪声的方差,如果没有给出来,那么会根据图像的局部方差进行估计。

         

         ispforfun根据这段原理,编写了如下的matlab代码,共享给大家。

    function J = wiener_image_denoising_filter(I, Win, noise_var)
    % J = wiener_image_denoising_filter(I, w)
    % -----------------------------------------
    % by: ispforfun
    % I is the input image. Single channel image.
    % Win is the window size for filtering.
    
    [img_height, img_width] = size(I);
    half_win_size = floor(Win/2.0);
    
    [X, Y] = meshgrid(1:img_width, 1:img_height);
    [dX, dY] = meshgrid(-half_win_size(2):half_win_size(2), -half_win_size(1):half_win_size(1));
    
    dX = reshape(dX, [1 1 Win(1) Win(2)]);
    dY = reshape(dY, [1 1 Win(1) Win(2)]);
    X = repmat(X, [1 1 Win(1) Win(2)]) + repmat(dX, [img_height img_width 1 1]);
    Y = repmat(Y, [1 1 Win(1) Win(2)]) + repmat(dY, [img_height img_width 1 1]);
    
    X(X<1) = 2 - X(X<1);
    X(X>img_width) = 2*img_width - X(X>img_width);
    Y(Y<1) = 2 - Y(Y<1);
    Y(Y>img_height) = 2*img_height - Y(Y>img_height);
    
    patch = @(f)f(Y + (X-1)*img_height);
    
    P = patch(I);
    
    img_mean = local_image_mean(P);
    img_var = local_image_var(P, img_mean, Win);
    
    if nargin < 3
        estimated_noise_var = sum(sum(img_var))/(img_height * img_width);
    else
        estimated_noise_var = noise_var;
    end
    
    gain = (estimated_noise_var == 0.0).*zeros(img_height, img_width) + ...
        (estimated_noise_var ~= 0.0).*((img_var - estimated_noise_var)./img_var);
    
    J = img_mean + gain.*(double(I) - img_mean);
    
    J = min(max(J, 0), 255);
    
    J = uint8(J);
    
    %gain = (img_var - estimated_noise_var)./img_var;
    
    
    
    function img_mean = local_image_mean(P)
    % img_mean = local_image_mean(P)
    
    local_img_sum = sum(sum(double(P), 4), 3);
    sum_size = size(P,3)*size(P,4);
    
    img_mean = local_img_sum/sum_size;
    
    
    function img_var = local_image_var(P, img_mean, Win)
    % img_var = local_img_var(P, img_mean)
    
    diff_img_patch = double(P) - repmat(img_mean, [1 1 Win(1) Win(2)]);
    diff_img_patch_pow2 = diff_img_patch.^2;
    local_diff_img_sum = sum(sum(double(diff_img_patch_pow2), 4), 3);
    img_var = local_diff_img_sum/(Win(1)*Win(2) - 1);
    

    实验如下,富含噪声的图像如下:


    去噪后的图像如下:



           

    展开全文
  • 维纳滤波图像恢复中的应用 维纳滤波实现图像恢复 基于MATLAB的维纳滤波图像恢复中的应用 基于MATLAB的图像复原
  • 觉得很有用,但是在python并没有直接可以调用维纳滤波的函数,看见网上很多的教程都是自己根据原理自己编写的函数,这样也很有用,不过有个直接调用的函数我觉得很方便,最后我发现SciPy库有wiener滤波函数的调用。...

    MATLAB中直接有个维纳滤波函数wiener2可以调用,觉得很有用,但是在python并没有直接可以调用维纳滤波的函数,看见网上很多的教程都是自己根据原理自己编写的函数,这样也很有用,不过有个直接调用的函数我觉得很方便,最后我发现SciPy库有wiener滤波函数的调用。

    我不写维纳滤波的原理,其原理在网上有很多博主写的都很详细、易懂,我在此主要讲一下如何实现SciPy库中wiener的实现。


    语法:

    scipy.signal.wiener
    (
      im,
      mysize=None,
      noise=None
    )
    

    输入参数:

    • im:矩阵ndarray(一个N维矩阵)
    • mysize:每个维度滤波窗口的大小,一个标量或者长度为N的列表,最好为奇数值
    • noise:使用的噪音功率。如果没有,则估计噪声为输入的局部方差的平均值。

    返回参数:

    • out:跟im大小相同的维纳滤波的结果

    举例说明

    from scipy.signal import wiener
    import cv2
    import numpy as np
    import matplotlib.pyplot as plt
    
    def gasuss_noise(image, mean=0, var=0.001):
        '''
            添加高斯噪声
            mean : 均值
            var : 方差
        '''
        image = np.array(image/255, dtype=float)
        noise = np.random.normal(mean, var ** 0.5, image.shape)
        out = image + noise
        if out.min() < 0:
            low_clip = -1.
        else:
            low_clip = 0.
        out = np.clip(out, low_clip, 1.0)
        out = np.uint8(out*255)
        #cv.imshow("gasuss", out)
        return out
    
    if __name__ == '__main__':
        lena = cv2.imread(r'C:\Users\99347\.atom\packages\markdown-preview-plus\node_modules\markdown-it-imsize\test\img\lena.jpg')
        if lena.shape[-1] == 3:
            lenaGray = cv2.cvtColor(lena, cv2.COLOR_BGR2GRAY)
        else:
            lenaGray = lena.copy()
    
        plt.figure('原图')
        plt.imshow(lenaGray, cmap='gray')
    
        # 添加高斯噪声
        lenaNoise = gasuss_noise(lenaGray)
    
        plt.figure('添加高斯噪声后的图像')
        plt.imshow(lenaNoise, cmap='gray')
    
        # 维纳滤波
        lenaNoise = lenaNoise.astype('float64')
        lenaWiener = wiener(lenaNoise, [3, 3])
        lenaWiener = np.uint8(lenaWiener / lenaWiener.max() * 255)
    
        plt.figure('经过维纳滤波后的图像')
        plt.imshow(lenaWiener, cmap='gray')
        plt.show()
    

    输出结果:

    CSDN图标
    展开全文
  • 维纳滤波图像处理

    2019-06-15 12:57:05
    2019独角兽企业重金招聘Python工程师标准>>> ...

    维纳滤波处理模糊图像

    代码链接: https://github.com/hoijui/DIP/tree/master/ex04/src/main/native 感谢作者。

    滤波结果

    wiener.h

    //wiener.h
    #ifndef WIENER_H
    #define WIENER_H
    #include <opencv2/opencv.hpp>
    
    using namespace std;
    using namespace cv;
    
    // function headers of not yet implemented functions
    
    /**
     * Function applies inverse filter to restore a degraded image.
     * @param degraded  degraded input image
     * @param filter  filter which caused degradation
     * @return  restored output image
     */
    Mat inverseFilter(Mat& degraded, Mat& filter);
    
    /**
     * Function applies wiener filter to restore a degraded image.
     * @param degraded  degraded input image
     * @param filter  filter which caused degradation
     * @param snr  signal to noise ratio of the input image
     * @return  restored output image
     */
    Mat wienerFilter(Mat& degraded, Mat& filter, double snr);
    
    /**
     * Creates a filter kernel matrix of a certain type and size.
     * @param kernel  where to store the generated kernel to
     * @param kSize  size of the kernel (kSize * kSize)
     * @param name  name of the type of kernel to generate; possible values:
     *   "gaussian", "uniform"
     */
    void createKernel(Mat& kernel, int kSize, string name = "gaussian");
    
    /**
     * Performs a circular shift in (dx,dy) direction.
     * @param in  input matrix
     * @param out  circular shifted matrix
     * @param dx  shift in x-direction
     * @param dy  shift in y-direction
     */
    void circShift(Mat& in, Mat& out, int dx, int dy);
    
    // function headers of given functions
    
    /**
     * Function degrades a given image with gaussian blur and additive gaussian noise.
     * @param img  input image
     * @param degradedImg  degraded output image
     * @param filterDev  standard deviation of kernel for gaussian blur
     * @param snr  signal to noise ratio for additive gaussian noise
     * @return the used gaussian kernel
     */
    Mat degradeImage(Mat& img, Mat& degradedImg, double filterDev, double snr);
    
    /**
     * Function displays image (after proper normalization).
     * @param win  Window name
     * @param img  Image that shall be displayed
     * @param cut  whether to cut or scale values outside of [0,255] range
     */
    void showImage(const char* win, Mat img, bool cut = true);
    
    
    
    
    #endif // WIENER_H
    

    wiener.cpp

    //wiener.cpp
    #include <iostream>
    #include <opencv2/opencv.hpp>
    
    // function headers of not yet implemented functions
    #include "wiener.h"
    
    static void circShiftXXX(Mat& in, Mat& out, int dx, int dy){
    
        int dstI, dstJ;
    
        for(int i=0; i<in.rows;i++)
        {
            dstI = i+dx;
            if(dstI<0)
            {
                dstI += out.rows;
            } else if(dstI>=out.rows){
                dstI -= out.rows;
            }
    
            for(int j=0; j<in.cols;j++)
            {
                dstJ = j+dy;
                if(dstJ<0)
                {
                    dstJ += out.cols;
                } else if(dstJ>=out.cols){
                    dstJ -= out.cols;
                }
    
                out.at<float>(dstI,dstJ) = in.at<float>(i,j);
            }
        }
    }
    
    static Mat inverseAndWiener(Mat& s, Mat& p, double snr, bool inverse) {
    
        const bool wiener = !inverse;
    
        // Pad input image to avoid ringing artifacts along image borders.
        int bH = p.cols;
        int bV = p.rows;
        Mat sBorder;
        copyMakeBorder(s, sBorder, bV, bV, bH, bH, BORDER_REPLICATE);
    
        // Allocate some memory like it is going out of style.
        Mat pBigShifted = Mat::zeros(sBorder.size(), CV_32F);
        Mat P = Mat::zeros(sBorder.size(), CV_32F);
        Mat S = Mat::zeros(sBorder.size(), CV_32F);
        Mat OApprox = Mat::zeros(sBorder.size(), CV_32F);
        Mat oApprox = Mat::zeros(sBorder.size(), CV_32F);
    
        // Shift kernel.
        const int pHalf = p.rows / 2;
        circShiftXXX(p, pBigShifted, -pHalf, -pHalf);
    
        // Transform shifted kernel and degrated input image into frequency domain.
        // Note: DFT_COMPLEX_OUTPUT means that we want the complex result to be stored
        //       in a two-channel matrix as opposed to the default compressed output.
        dft(pBigShifted, P, DFT_COMPLEX_OUTPUT);
        dft(sBorder, S, DFT_COMPLEX_OUTPUT);
    
        if (inverse) {
            const double epsilon = 0.05f;
    
            // Remove frequencies whose magnitude is below epsilon * max(freqKernel magnitude).
            double maxMagnitude;
            minMaxLoc(abs(P), 0, &maxMagnitude);
    
            const double threshold =  maxMagnitude * epsilon;
            for (int ri = 0; ri < P.rows; ri++) {
                for (int ci = 0; ci < P.cols; ci++) {
                    if (norm(P.at<Vec2f>(ri, ci)) < threshold) {
                        P.at<Vec2f>(ri, ci) = threshold;
                    }
                }
            }
        }
    
        // OpenCV only provides a multiplication operation for complex matrices, so we need
        // to calculate the inverse (1/H) of our filter spectrum first. Since it is complex
        // we need to compute 1/H = H*/(HH*) = H*/(Re(H)^2+Im(H)^2), where H* -> complex conjugate of H.
    
        // Multiply spectrum of the degrated image with the complex conjugate of the frequency spectrum
        // of the filter.
        const bool conjFreqKernel = true;
        mulSpectrums(S, P, OApprox, DFT_COMPLEX_OUTPUT, conjFreqKernel); // I * H*
    
        // Split kernel spectrum into real and imaginary parts.
        Mat PChannels[] = {Mat::zeros(sBorder.size(), CV_32F), Mat::zeros(sBorder.size(), CV_32F)};
        split(P, PChannels); // 0:real, 1:imaginary
    
        // Calculate squared magnitude (Re(H)^2 + Im(H)^2) of filter spectrum.
        Mat freqKernelSqMagnitude = Mat::zeros(sBorder.rows, sBorder.cols, CV_32F);
        magnitude(PChannels[0], PChannels[1], freqKernelSqMagnitude); // freqKernelSqMagnitude = magnitude
        pow(PChannels[0], 2, freqKernelSqMagnitude); // freqKernelSqMagnitude = magnitude^2 = Re(H)^2 + Im(H)^2
    
        if (wiener) {
            // Add 1 / SNR^2 to the squared filter kernel magnitude.
            freqKernelSqMagnitude += 1 / pow(snr, 2.0);
        }
    
        // Split frequency spectrum of degradedPadded image into real and imaginary parts.
        Mat OApproxChannels[] = {Mat::zeros(sBorder.size(), CV_32FC1), Mat::zeros(sBorder.size(), CV_32F)};
        split(OApprox, OApproxChannels);
    
        // Divide each plane by the squared magnitude of the kernel frequency spectrum.
        // What we have done up to this point: (I * H*) / (Re(H)^2 + Im(H)^2) = I/H
        divide(OApproxChannels[0], freqKernelSqMagnitude, OApproxChannels[0]); // Re(I) / (Re(H)^2 + Im(H)^2)
        divide(OApproxChannels[1], freqKernelSqMagnitude, OApproxChannels[1]); // Im(I) / (Re(H)^2 + Im(H)^2)
    
        // Merge real and imaginary parts of the image frequency spectrum.
        merge(OApproxChannels, 2, OApprox);
    
        // Inverse DFT.
        // Note: DFT_REAL_OUTPUT means that we want the output to be a one-channel matrix again.
        dft(OApprox, oApprox, DFT_INVERSE | DFT_SCALE | DFT_REAL_OUTPUT);
    
        // Crop output image to original size.
        oApprox = oApprox(Rect(bH, bV, oApprox.cols - (bH * 2), oApprox.rows - (bV * 2)));
    
        return oApprox;
    }
    
    Mat inverseFilter(Mat& degraded, Mat& filter) {
        return inverseAndWiener(degraded, filter, -1.0, true);
    }
    
    Mat wienerFilter(Mat& degraded, Mat& filter, double snr) {
        return inverseAndWiener(degraded, filter, snr, false);
    }
    
    void circShift(Mat& in, Mat& out, int dx, int dy) {
    
        const int h = in.rows;
        const int w = in.cols;
    
    //	out = Mat::zeros(h, w, in.type());
    
        for (int y = 0; y < h; ++y) {
            int yNew = y + dy;
            if (yNew < 0) {
                yNew = yNew + h;
            } else if (yNew >= h) {
                yNew = yNew - h;
            }
    
            for (int x = 0; x < w; ++x) {
                int xNew = x + dx;
                if (xNew < 0) {
                    xNew = xNew + w;
                } else if (xNew >= w) {
                    xNew = xNew - w;
                }
    
                out.at<float>(yNew, xNew) = in.at<float>(y, x);
            }
        }
    }
    

    mian.cpp

    //mian.cpp
    
    #include<iostream>
    #include<vector>
    #include <opencv2/opencv.hpp>
    
    
    #include "wiener.h"
    
    using namespace cv;
    using namespace std;
    
    Mat degradeImage(Mat& img, Mat& degradedImg, double filterDev, double snr);
    void showImage(const char* win, Mat img, bool cut);
    int main()
    {
    
        const char* win_1 = "Original Image";
        const char* win_2 = "Degraded Image";
        const char* win_3 = "Restored Image: Inverse filter";
        const char* win_4 = "Restored Image: Wiener filter";
        namedWindow(win_1);
        namedWindow(win_2);
        namedWindow(win_3);
        namedWindow(win_4);
    
        // load image, path in argv[1]
        cout << "load image" << endl;
        Mat img = imread("lena.jpg", 0);
        // convert U8 to 32F
        img.convertTo(img, CV_32FC1);
        cout << " > done" << endl;
    
        // show and safe gray-scale version of original image
        showImage(win_1, img);
        imwrite("original.png", img);
    
        // degrade image
        cout << "degrade image" << endl;
        double filterDev = 9;
        double snr = 10; //10000;
        Mat degradedImg;
        Mat gaussKernel = degradeImage(img, degradedImg, filterDev, snr);
        cout << " > done" << endl;
    
        // show and safe degraded image
        showImage(win_2, degradedImg);
        imwrite("degraded.png", degradedImg);
    
        // inverse filter
        cout << "inverse filter" << endl;
        Mat restoredImgInverseFilter = inverseFilter(degradedImg, gaussKernel);
        cout << " > done" << endl;
    
        // show and safe restored image
        showImage(win_3, restoredImgInverseFilter);
        imwrite("restored_inverse.png", restoredImgInverseFilter);
    
        // wiener filter
        cout << "wiener filter" << endl;
        Mat restoredImgWienerFilter = wienerFilter(degradedImg, gaussKernel, snr);
        cout << " > done" << endl;
    
        // show and safe restored image
        showImage(win_4, restoredImgWienerFilter, false);
        imwrite("restored_wiener.png", restoredImgWienerFilter);
    
        // wait
        waitKey(0);
    
        return 0;
    }
    
    /*
          *************************
          ***   GIVEN FUNCTIONS ***
          *************************
          */
    
    Mat degradeImage(Mat& img, Mat& degradedImg, double filterDev, double snr) {
    
        int kSize = round(filterDev * 3)*2 - 1;
    
        Mat gaussKernel = getGaussianKernel(kSize, filterDev, CV_32FC1);
        gaussKernel = gaussKernel * gaussKernel.t();
        filter2D(img, degradedImg, -1, gaussKernel);
    
        Mat mean, stddev;
        meanStdDev(img, mean, stddev);
    
        Mat noise = Mat::zeros(img.rows, img.cols, CV_32FC1);
        randn(noise, 0, stddev.at<double>(0) / snr);
        degradedImg = degradedImg + noise;
        threshold(degradedImg, degradedImg, 255, 255, CV_THRESH_TRUNC);
        threshold(degradedImg, degradedImg, 0, 0, CV_THRESH_TOZERO);
    
        return gaussKernel;
    }
    
    void showImage(const char* win, Mat img, bool cut) {
    
        Mat tmp = img.clone();
    
        if (tmp.channels() == 1) {
            if (cut) {
                threshold(tmp, tmp, 255, 255, CV_THRESH_TRUNC);
                threshold(tmp, tmp, 0, 0, CV_THRESH_TOZERO);
            } else {
                normalize(tmp, tmp, 0, 255, CV_MINMAX);
            }
    
            tmp.convertTo(tmp, CV_8UC1);
        } else {
            tmp.convertTo(tmp, CV_8UC3);
        }
        imshow(win, tmp);
    }
    
    
    

    转载于:https://my.oschina.net/u/1046919/blog/804709

    展开全文
  • 数字图像处理第五章维纳滤波的matlab实现
  • 图像处理自适应滤波

    2017-09-28 21:24:53
    图像处理基础(2):自适应中值滤波器(基于OpenCV实现) 标签: opencv滤波器 2017-02-08 19:44 986人阅读 评论(0) 收藏 举报  分类: DIP(8)  版权声明:本文为博主原创文章,未经博...
  • 维纳滤波图像去噪

    2020-07-21 10:01:12
    维纳滤波图像去噪,程序用了维纳滤波去除图像里的噪声。
  • 图像处理滤波处理 C/C++语言实现..........................
  • 图像复原和维纳滤波

    2018-09-06 16:43:23
    之前上课的时候其实就没搞懂什么是维纳滤波和卡尔曼滤波,老师完全讲不清楚来龙去脉,滤波、预测都说不清楚。后来刷知乎看到大神的解释,当时倒是茅塞顿开,但是前几天做笔试遇到关于维纳滤波的题目,发现功课没做够...
  • 目的:对获取图像在频域用高斯函数进行退化并叠加白噪声,对退化图像进行逆滤波和维纳滤波恢复,比较原始图像和恢复图像,对利用逆滤波和维纳滤波恢复方法恢复图像进行比较。 一、基本原理  图像复原是一种客观的...
  • ***【数字图像处理】图像复原–逆滤波 *** ** 1.逆滤波的问题点 图像的老化,可以视为以下这样的一个过程。一个是退化函数的影响(致使图片模糊,褪色等),一个可加性噪声的影响。 用算式表示为 前几篇博文,主要是...
  • 卡尔曼滤波 Kalman Filter 与维纳滤波 Wiener Filter 是什么关系?链接 数字图像去噪滤波算法性能和复杂度比较:链接 转载于:https://www.cnblogs.com/2008nmj/p/8110979.html...
  • 图像退化/复原模型  g(x,y) = h(x,y)*f(x,y)+n(x,y) 频域:G(u,v) = H(u,v)F(u,v) +N(u,v)   其中f(x,y)为原始图像,h(x,y)为退化函数,n(x,y)为噪声函数,目标就是根据观测图像g(x,y)以及一些先验或者估计信息...
  • 在数学应用上,对于运动引起的图像模糊,最简单的方法是直接做逆滤波,但是逆滤波对加性噪声特别敏感,使得回复的图像几乎不可用。最小均方差(维纳)滤波用来去除含有噪声的模糊图像,其目标是找到未污染图像的一个...
  • 图像降噪算法——维纳滤波图像降噪算法——维纳滤波 图像降噪算法——维纳滤波
  • 维纳滤波原理

    2017-05-02 21:01:39
    维纳滤波原理(Wiener Filter) 维纳 Norbert Wiener滤波器
  • 一、实验目的 利用逆滤波和维纳滤波,对Lena加噪运动模糊降质图像进行复原,比较不同参数选择对复原结果的影响。二、实验内容1) 输入Lena图像,对图像进行运动降质;降质模型:2) 对图像叠加高斯白噪声;3) 寻找...
  • 滤波和维纳滤波 ...为此, 要较好地显示原始图像,必须对退化后的图像进行处理,恢复出真实的原始图像,这一过程就称为图像复原。 大气湍流退化 对经过大气湍流退化的图片实现全逆滤波,半径受限逆滤波
  • %中值滤波 I0=imread('photo.jpeg'); j=rgb2gray(I0); I = imnoise(j,'salt & pepper'); Z1=medfilt2(I,[3,3]); Z2=medfilt2(I,[5,5]); figure; subplot(1,3,1),imshow(I),title('原图'); subplot(1,3,2),imshow...
1 2 3 4 5 ... 20
收藏数 623
精华内容 249
关键字:

wiener滤波图像处理