Image matlab中无加性噪声的高斯滤波图像去模糊

Image matlab中无加性噪声的高斯滤波图像去模糊,image,matlab,gaussian,gaussianblur,Image,Matlab,Gaussian,Gaussianblur,我必须使用逆滤波器来消除图像中的模糊 不幸的是,我必须计算出成像的传递函数H 系统用来获得这些更清晰的图像,它应该是高斯的。所以,我应该通过在逆滤波器中尝试不同的高斯宽度,并判断哪个结果图像看起来“最好”,来确定高斯的近似宽度 最佳结果将是最佳锋利–即边缘看起来锋利,但不会有可见的响声 我尝试了三种方法: 我创建了一个具有N维度的传递函数(为简单起见,是奇数),方法是创建一个N维度的网格,然后将高斯函数应用于该网格。然后,我们在传递函数中加入零,以获得与原始图像相同的大小。然而,在对原始图像应

我必须使用逆滤波器来消除图像中的模糊

不幸的是,我必须计算出成像的传递函数
H
系统用来获得这些更清晰的图像,它应该是高斯的。所以,我应该通过在逆滤波器中尝试不同的高斯宽度,并判断哪个结果图像看起来“最好”,来确定高斯的近似宽度

最佳结果将是最佳锋利–即边缘看起来锋利,但不会有可见的响声

我尝试了三种方法:

  • 我创建了一个具有
    N
    维度的传递函数(为简单起见,是奇数),方法是创建一个
    N
    维度的网格,然后将高斯函数应用于该网格。然后,我们在传递函数中加入零,以获得与原始图像相同的大小。然而,在对原始图像应用过滤器之后,我只看到了噪声(太多的伪影)
  • 通过创建与原始图像大小相同的网格,我创建了与原始图像大小相同的传递函数。如果
    sigma
    太小,则
    PSF FFT
    幅度较宽。否则它会变薄。如果
    sigma
    很小,则图像会变得更加模糊,但如果我们设置非常高的
    sigma
    值,则会得到相同的图像(一点也不好)
  • 我使用了
    fspecial
    函数,处理
    sigma
    h
    的大小。但我仍然没有得到比原始模糊图像更清晰的图像 有什么想法吗

    以下是用于在方法1中创建传递函数的代码:

    %Create Gaussian Filter
    function h = transfer_function(N, sigma, I) %N is the dimension of the kernel
    %create a 2D-grid that is the same size as the Gaussian filter matrix
    grid = -floor(N/2) : floor(N/2);
    [x, y] = meshgrid(grid, grid);
    arg = -(x.*x + y.*y)/(2*sigma*sigma);
    h = exp(arg); %gaussian 2D-function
    kernel = h/sum(h(:)); %Normalize so that total weight equals 1
    
    [rows,cols] = size(I);
    add_zeros_w = (rows - N)/2;
    add_zeros_h = (cols - N)/2;
    
    h = padarray(kernel,[add_zeros_w  add_zeros_h],0,'both'); % h = kernel_final_matrix
    
    end 
    
    这是每种方法的代码:

    I = imread('lena_blur.jpg');
    I1 = rgb2gray(I);
    figure(1),
    I1 = double(I1);
    %---------------Approach 1
    % N = 5; %Dimension Assume is an odd number
    % sigma = 20; %The bigger number, the thinner the PSF in FREQ
    % H = transfer_function(N, sigma, I1);
    %I1=I1(2:end,2:end); %To simplify operations
    imagesc(I1); colormap('gray'); title('Original Blurred Image')
    
    I_fft = fftshift(fft2(I1)); %Shift the image in Fourier domain to let its DC part in the center of the image
    
    
    
    % %FILTER-----------Approach 2---------------
    % N = 5; %Dimension Assume is an odd number
    % sigma = 20; %The bigger number, the thinner the PSF in FREQ
    % 
    % 
    % [x,y] = meshgrid(-size(I,2)/2:size(I,2)/2-1, -size(I,1)/2:size(I,1)/2-1);
    % H = exp(-(x.^2+y.^2)*sigma/2);
    % %// Normalize so that total area (sum of all weights) is 1
    % H = H /sum(H(:));
    % 
    % %Avoid zero freqs
    % for i = 1:size(I,2) %Cols
    %     for j = 1:size(I,1) %Rows
    %         if (H(i,j) == 0)
    %             H(i,j) = 1e-8;
    %         end
    %     end
    % end
    % 
    % [rows columns z] = size(I);
    % G_filter_fft = fft2(H,rows,columns);
    %FILTER---------------------------------
    
    
    %Filter--------- Aproach 3------------
    N = 21; %Dimension Assume is an odd number
    sigma = 1.25; %The bigger number, the thinner the PSF in FREQ
    
    H = fspecial('gaussian',N,sigma)
    [rows columns z] = size(I);
    G_filter_fft = fft2(H,rows,columns);
    
    %Filter--------- Aproach 3------------
    
    
    
    %DISPLAY FFT PSF MAGNITUDE
    figure(2),
    imshow(fftshift(abs(G_filter_fft)),[]); title('FFT PSF magnitude 2D');
    
    
    % Yest = Y_blurred/Gaussian_Filter
    I_restoration_fft = I_fft./G_filter_fft;
    I_restoration = (ifft2(I_restoration_fft));
    I_restoration = abs(I_restoration);
    
    
    
    
    I_fft = abs(I_fft);
    
    % Display of Frequency domain (To compare with the slides) 
    figure(3),
    subplot(1,3,1); 
    imagesc(I_fft);colormap('gray');title('|DFT Blurred Image|')
    subplot(1,3,2)
    imshow(log(fftshift(abs(G_filter_fft))+1),[]) ;title('| Log DFT Point Spread Function + 1|');
    subplot(1,3,3)
    imagesc(abs(I_restoration_fft));colormap('gray'); title('|DFT Deblurred|')
    % imshow(log(I_restoration+1),[])
    
    %Display PSF FFT in 3D
    figure(4)
    hf_abs = abs(G_filter_fft);
    %270x270
    surf([-134:135]/135,[-134:135]/135,fftshift(hf_abs));
    % surf([-134:134]/134,[-134:134]/134,fftshift(hf_abs));
    shading interp, camlight, colormap jet
    xlabel('PSF FFT magnitude')
    
    %Display Result (it should be the de-blurred image)
    figure(5),
    %imshow(fftshift(I_restoration));
    imagesc(I_restoration);colormap('gray'); title('Deblurred Image')
    
    %Pseudo Inverse restoration
    % cam_pinv = real(ifft2((abs(G_filter_fft) > 0.1).*I_fft./G_filter_fft));
    % imshow(fftshift(cam_pinv));
    % xlabel('pseudo-inverse restoration')
    
    一个可能的解决办法是。我将首先从未失真的lena图像开始展示它的性能。所以,我确切地知道高斯模糊函数。请注意,将
    estimated_nsr
    设置为零将由于量化噪声而完全破坏性能

     I_ori = imread('lenaTest3.jpg'); % Download an original undistorted lena file
     N = 19;
     sigma = 5;
     H = fspecial('gaussian',N,sigma) 
     estimated_nsr = 0.05;
    
     I = imfilter(I_ori, H)
    
     wnr3 = deconvwnr(I, H, estimated_nsr); 
     figure
     subplot(1, 4, 1);
     imshow(I_ori) 
     subplot(1, 4, 2);
     imshow(I) 
     subplot(1, 4, 3);
     imshow(wnr3) 
     title('Restoration of Blurred, Noisy Image Using Estimated NSR'); 
     subplot(1, 4, 4);
     imshow(H, []);
    
    通过反复试验,我找到了解决您问题的最佳参数

     N = 19; 
     sigma = 2; 
     H = fspecial('gaussian',N,sigma) 
     estimated_nsr = 0.05;
    
    编辑:精确计算使用的模糊过滤器

    如果下载未失真的lena(
    I_original_fft
    ),可以按如下方式计算使用的模糊滤波器:

    G_filter_fft = I_fft./I_original_fft
    
    一个可能的解决办法是。我将首先从未失真的lena图像开始展示它的性能。所以,我确切地知道高斯模糊函数。请注意,将
    estimated_nsr
    设置为零将由于量化噪声而完全破坏性能

     I_ori = imread('lenaTest3.jpg'); % Download an original undistorted lena file
     N = 19;
     sigma = 5;
     H = fspecial('gaussian',N,sigma) 
     estimated_nsr = 0.05;
    
     I = imfilter(I_ori, H)
    
     wnr3 = deconvwnr(I, H, estimated_nsr); 
     figure
     subplot(1, 4, 1);
     imshow(I_ori) 
     subplot(1, 4, 2);
     imshow(I) 
     subplot(1, 4, 3);
     imshow(wnr3) 
     title('Restoration of Blurred, Noisy Image Using Estimated NSR'); 
     subplot(1, 4, 4);
     imshow(H, []);
    
    通过反复试验,我找到了解决您问题的最佳参数

     N = 19; 
     sigma = 2; 
     H = fspecial('gaussian',N,sigma) 
     estimated_nsr = 0.05;
    
    编辑:精确计算使用的模糊过滤器

    如果下载未失真的lena(
    I_original_fft
    ),可以按如下方式计算使用的模糊滤波器:

    G_filter_fft = I_fft./I_original_fft
    


    Matlab网页中有一些解决方案:,你看了这些吗?看看@monakons可能也很有趣是的,实际上我的解决方案部分基于那个博客。问题是我根本没有噪音。图像只是模糊(不是附加噪声)。@m7913d我没有任何噪声…您可以将其用于无噪声图像,只需将NSR设置为零。请注意,你总是有量化噪声。Matlab网页中有一些解决方案:,你看了这些吗?看看@monakons可能也很有趣是的,实际上我的解决方案部分基于那个博客。问题是我根本没有噪音。图像只是模糊(不是附加噪声)。@m7913d我没有任何噪声…您可以将其用于无噪声图像,只需将NSR设置为零。请注意,你总是有量化噪声。谢谢你的回答。但是我需要处理我在第一张图片中发布的这张图片。正如我所写的:我应该通过在逆滤波器中尝试不同的高斯宽度,并判断哪个结果图像看起来“最好”,来确定高斯的近似宽度。这意味着如果我写:I_恢复_fft=I_fft./G_滤波器_fft;然后逆FFT应该是我想要的图像。我通过找到高斯函数的正确参数来实现这一点。正如我在上面的例子中所展示的那样,deconwnr没有用处(我没有被要求处理噪声或使用维纳滤波器)。在图像上假设一些噪声是个好主意。如果运行上面的示例,如果将
    estimated\u nsr
    设置为零,即使高斯模糊滤波器完全已知,也会得到非常糟糕的结果。如果我正确地查看了您的代码,那么您基本上是以零噪声实现了
    deconwnr
    。我的第二部分代码是使图像稍微锐化的参数。不管怎样,如果你使用:I=imfilter(I_ori,H),你就是在空间域中进行卷积。我应该做的是在频域进行逐点分割,即I_restoration_fft=I_fft./G_filter_fft,这与空间域的卷积不同。请注意,我使用imfilter来模糊未失真的lena图像,因此我知道确切的模糊函数,并且我能够测试
    decovwnr
    。我使用
    deconvwnr
    来恢复图像,而不必自己编写一堆代码。第二,请注意,你说你的方法是基于,这与那篇文章评论中讨论的维纳方法非常相似。好吧,你可能会得到一个很好的结果,因为你已经知道高斯(当你模糊图像时),你用同样的高斯去模糊模糊图像。这里的重点是猜测高斯的参数,因为你得到了一个模糊的图像(它已经被具有特定参数的高斯模糊了;你必须猜测相同的参数)。所以,请便,试着用我的图片解压一下,就像我在第一篇文章中发布的一样。你会发现deconwnr并没有给出任何好的结果。谢谢你的回答。但是我需要处理我在第一张图片中发布的这张图片。正如我写的:我应该