数字图像处理实验(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: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

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

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

  • 1
    点赞
  • 5
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
对于处理EEG数据,我们可以使用Python中的MNE库。以下是对于CHB-MIT数据集进行高通和陷波滤波的代码示例: 首先,您需要安装MNE库。如果您还没有安装它,可以通过以下命令进行安装: ``` pip install mne ``` 接下来,我们需要导入所需的库: ```python import mne import os ``` 然后,我们需要读取数据并创建一个Raw对象: ```python data_path = '/path/to/chb-mit-data/' subject_id = '01' data_file = os.path.join(data_path, 'chb{:02d}.edf'.format(int(subject_id))) raw = mne.io.read_raw_edf(data_file, preload=True) ``` 接下来,我们需要进行高通和陷波滤波: ```python # High-pass filter raw.filter(l_freq=0.5, h_freq=None) # Notch filter raw.notch_filter(freqs=50) ``` 最后,我们可以保存处理后的数据: ```python # Save filtered data out_file = os.path.join(data_path, 'chb{:02d}_filtered.fif'.format(int(subject_id))) raw.save(out_file, overwrite=True) ``` 完整的代码示例: ```python import mne import os # Set data path and subject ID data_path = '/path/to/chb-mit-data/' subject_id = '01' # Read data data_file = os.path.join(data_path, 'chb{:02d}.edf'.format(int(subject_id))) raw = mne.io.read_raw_edf(data_file, preload=True) # High-pass filter raw.filter(l_freq=0.5, h_freq=None) # Notch filter raw.notch_filter(freqs=50) # Save filtered data out_file = os.path.join(data_path, 'chb{:02d}_filtered.fif'.format(int(subject_id))) raw.save(out_file, overwrite=True) ``` 请注意,以上代码示例假设您已经将CHB-MIT数据集下载到本地计算机,并且知道数据的路径。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值