• 数字图像处理实验(7):PROJECT 04-03 , Lowpass Filtering 标签: 图像处理MATLAB 2017-05-25 09:30 109人


    实验要求:

    Objective:
    To observe how the lowpass filtering smoothes an image.
    Main requirements:
    Ability of programming with C, C++, or Matlab.
    Instruction manual:
    (a) Implement the Gaussian lowpass filter in Eq. (4.3-7). You must be able to specify the size, M x N, of the resulting 2D function. In addition, you must be able to specify where the 2D location of the center of the Gaussian function.
    (b) Download Fig. 4.11(a) [this image is the same as Fig. 4.18(a)] and lowpass filter it to obtain Fig. 4.18(c).

    实验要求我们通过在频域的高斯低通滤波器对图像进行低通滤波。
    频域滤波的处理可以参考前面的实验04-01实现。(点我打开链接

    实验代码:

    % PROJECT 04-03 Lowpass Filtering
    close all;
    clc;
    clear all;
    
    %
    img = imread('Fig4.11(a).jpg');
    img = mat2gray(img);
    figure;
    subplot(1,3,1);
    imshow(img);
    title('原图像');
    
    % 产生滤波函数
    [M, N] = size(img);
    P = 2 * M;
    Q = 2 * N;
    
    alf = 100;
    H = zeros(P, Q);
    for i = 1:P
        for j = 1:Q
            H(i, j) = exp(-((i-P/2)^2 + (j-Q/2)^2) / (2 * alf^2));
        end
    end
    
    % H = ones(P, Q);
    subplot(1,3,2);
    imshow(H);
    title('滤波函数');
    
    % 
    % 图像填充
    [M, N] = size(img);
    P = 2 * M;
    Q = 2 * N;
    
    img_fp = zeros(P, Q);
    img_fp(1:M, 1:N) = img(1:M, 1:N);
    
    % [X, Y] = meshgrid(1:P, 1:Q);
    % ones = (-1)^(X+Y);
    
    % img_f = ones .* img_fp;
    img_f = zeros(P, Q);
    for x = 1:P
        for y = 1:Q
            img_f(x, y) = img_fp(x, y) .* (-1)^(x+y);
        end
    end
    
    img_F = fft2(img_f);
    
    img_G = img_F .* H;
    img_g = real(ifft2(img_G));
    
    % img_g = ones .* img_g;
    
    for x = 1:P
        for y = 1:Q
            img_g(x, y) = img_g(x, y) .* (-1)^(x+y);
        end
    end
    
    img_o = img_g(1:M, 1:N);
    
    subplot(1,3,3);
    imshow(img_o, []);
    title('高斯低通滤波后的图像');

    其中套用公式产生高斯滤波函数的代码如下:

    [M, N] = size(img);
    P = 2 * M;
    Q = 2 * N;
    
    alf = 100;
    H = zeros(P, Q);
    for i = 1:P
        for j = 1:Q
            H(i, j) = exp(-((i-P/2)^2 + (j-Q/2)^2) / (2 * alf^2));
        end
    end

    其余部分就是频率域滤波的流程,不做赘述。

    实验结果:
    这里写图片描述
    说明:
    第一幅图是原始图像;
    第二幅是高斯低通滤波器;
    第三幅是低通滤波处理后的结果,其较原始图像明显变得更模糊。

  • 相关阅读:
    二次离线莫队
    串串题-各种算法的应用
    插头dp 笔记
    ST03模拟赛#1 比赛记录
    AtCoder Regular Contest 123 比赛记录(vp)
    冷门trick:线性区间单调求和
    dp优化瞎吹
    概率期望
    NOI挑战赛#2 (vp) 记录
    动态规划-线性dp-序列组成-5833. 统计特殊子序列的数目
  • 原文地址:https://www.cnblogs.com/xuhongbin/p/7134163.html
Copyright © 2020-2023  润新知