数字图像处理实验(7):PROJECT 04-03 , Lowpass Filtering
實驗要求:
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:Pfor j = 1:QH(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:Pfor y = 1:Qimg_f(x, y) = img_fp(x, y) .* (-1)^(x+y);end endimg_F = fft2(img_f);img_G = img_F .* H; img_g = real(ifft2(img_G));% img_g = ones .* img_g;for x = 1:Pfor y = 1:Qimg_g(x, y) = img_g(x, y) .* (-1)^(x+y);end endimg_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:Pfor j = 1:QH(i, j) = exp(-((i-P/2)^2 + (j-Q/2)^2) / (2 * alf^2));end end其余部分就是頻率域濾波的流程,不做贅述。
實驗結果:
說明:
第一幅圖是原始圖像;
第二幅是高斯低通濾波器;
第三幅是低通濾波處理后的結果,其較原始圖像明顯變得更模糊。
總結
以上是生活随笔為你收集整理的数字图像处理实验(7):PROJECT 04-03 , Lowpass Filtering的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数字图像处理实验(6):PROJECT
- 下一篇: 数字图像处理实验(8):PROJECT