八、数字图像处理Matlab实验 第四章 频率域滤波(下)

在这里插入图片描述

文章目录

实验所用教材配图资源:数字图像处理-冈萨雷斯-第三版(教材配图)
实验Matlab代码资源:数字图像处理 第四章 频率域滤波(Matlab实验代码)

一、滤波器:平滑滤波 — 理想低通滤波器 P171

1.1 实验内容

理想低通滤波器的实验

1.2 文件目录结构

在这里插入图片描述

1.3 Matlab代码

% 理想低通滤波器的实验 P171
close all;clear all;clc;
% 读入图像
in = imread('Fig0441(characters_test_pattern).tif');
% 计算得到图像的频谱
dft_spectrum = fftshift(fft2(double(in)));
 
% 取不同的截止频率得到的模糊图像
% 截止频率
[row,column] = size(in);
 
d0 = [10,30,60,160,460];
h_ilpf = {};
for i = 1:length(d0)
    h_ilpf{end+1} = ilpf(row,column,d0(i));
end
 
% 使用不同截止频率的滤波器对原图像进行过滤
idft_out = {};
for i = 1:length(h_ilpf)
    idft_out{end+1} = real(ifft2(ifftshift(h_ilpf{i} .* dft_spectrum)));
end
 
% 显示图像
figure;
subplot(1,2,1);
imshow(in);
title('原图');
 
subplot(1,2,2);
imshow(log(1 + abs(dft_spectrum)),[]);
title('原图的频谱');
 
 
figure;
for i = 1:length(idft_out)+1
    subplot(2,3,i);
    if i == 1
        imshow(in);
        str = '原图';
    else
        imshow(idft_out{i-1},[]);
        str = ['经D0=',num2str(d0(i-1)),'的理想低通滤波器滤波后的结果'];
    end
    title(str);   
end

1.4 实验结果

在这里插入图片描述


二、频率域:平滑滤波 — 布特沃斯低通滤波器 P172

2.1 实验内容

布特沃斯低通滤波器的实验

2.2 文件目录结构

在这里插入图片描述

2.3 Matlab代码

% 布特沃斯低通滤波器的实验 P172
close all;clear all;clc;
% 读入图像
in = imread('Fig0441(characters_test_pattern).tif');
[row,column] = size(in);
% 得到频谱
dft_spectrum = fftshift(fft2(double(in)));
 
% 得到不同截止频率的理想低通滤波器
h_blpf = {};
d0 = [10,30,60,160,460];
for i = 1:length(d0)
    h_blpf{end+1} = blpf(row,column,2,d0(i));
end
 
% 使用不同截止频率的滤波器对原图像进行过滤
idft_out = {};
for i = 1:length(h_blpf)
    idft_out{end+1} = real(ifft2(ifftshift(h_blpf{i} .* dft_spectrum)));
end
 
figure;
for i = 1:length(idft_out)+1
    subplot(2,3,i);
    if i == 1
        imshow(in);
        str = '原图';
    else
        imshow(idft_out{i-1},[]);
        str = ['经D0=',num2str(d0(i-1)),'的布特沃斯低通滤波器滤波后的结果'];
    end
    title(str);   
end
 

2.4 实验结果

在这里插入图片描述


三、频率域:平滑滤波 — 高斯低通滤波器 P174

3.1 实验内容

高斯低通滤波器滤波的实验

3.2 文件目录结构

在这里插入图片描述

3.3 Matlab代码

% 高斯低通滤波器滤波的实验 P174
close all;clear all;clc;
% 读入图像
in = imread('Fig0441(characters_test_pattern).tif');
[row,column] = size(in);
% 得到频谱
dft_spectrum = fftshift(fft2(double(in)));
 
% 得到不同截止频率的理想低通滤波器
h_hlpf = {};
d0 = [10,30,60,160,460];
for i = 1:length(d0)
    h_hlpf{end+1} = hlpf(row,column,d0(i));
end
 
% 使用不同截止频率的滤波器对原图像进行过滤
idft_out = {};
for i = 1:length(h_hlpf)
    idft_out{end+1} = real(ifft2(ifftshift(h_hlpf{i} .* dft_spectrum)));
end
 
figure;
for i = 1:length(idft_out)+1
    subplot(2,3,i);
    if i == 1
        imshow(in);
        str = '原图';
    else
        imshow(idft_out{i-1},[]);
        str = ['经D0=',num2str(d0(i-1)),'的高斯低通滤波器滤波后的结果'];
    end
    title(str);   
end
 
 

3.4 实验结果

在这里插入图片描述


四、频率域:锐化图像 — 理想高通滤波器 P178

4.1 实验内容

理想高通滤波器的实验

4.2 文件目录结构

在这里插入图片描述

4.3 Matlab代码

% 理想高通滤波器的实验 P171
close all;clear all;clc;
% 读入图像
in = imread('Fig0441(characters_test_pattern).tif');
% 计算得到图像的频谱
dft_spectrum = fftshift(fft2(double(in)));
 
% 取不同的截止频率得到的模糊图像
% 截止频率
[row,column] = size(in);
 
d0 = [30,60,160];
h_ihpf = {};
for i = 1:length(d0)
    h_ihpf{end+1} = ihpf(row,column,d0(i));
end
 
% 使用不同截止频率的滤波器对原图像进行过滤
idft_out = {};
for i = 1:length(h_ihpf)
    idft_out{end+1} = real(ifft2(ifftshift(h_ihpf{i} .* dft_spectrum)));
end
 
% 显示图像
figure;
for i = 1:length(idft_out)+1
    subplot(1,4,i);
    if i == 1
        imshow(in);
        str = '原图';
    else
        idft_out{i-1}(idft_out{i-1}<0) = 0;
        imshow(idft_out{i-1},[]);
        str = ['经D0=',num2str(d0(i-1)),'的理想高通滤波器滤波后的结果'];
    end
    title(str);   
end

4.4 实验结果

在这里插入图片描述


五、频率域:锐化图像 — 布特沃斯高通滤波器 P178

5.1 实验内容

布特沃斯高通滤波器的实验

5.2 文件目录结构

在这里插入图片描述

5.3 Matlab代码

% 布特沃斯高通滤波器的实验 P171
close all;clear all;clc;
% 读入图像
in = imread('Fig0441(characters_test_pattern).tif');
% 计算得到图像的频谱
dft_spectrum = fftshift(fft2(double(in)));
 
% 取不同的截止频率得到的模糊图像
% 截止频率
d0 = [30,60,160];
[row,column] = size(in);
 
 
h_bhpf = {};
for i = 1:length(d0)
    h_bhpf{end+1} = bhpf(row,column,2,d0(i));
end
 
% 使用不同截止频率的滤波器对原图像进行过滤
idft_out = {};
for i = 1:length(h_bhpf)
    idft_out{end+1} = real(ifft2(ifftshift(h_bhpf{i} .* dft_spectrum)));
end
 
% 显示图像
figure;
for i = 1:length(idft_out)+1
    subplot(1,4,i);
    if i == 1
        imshow(in);
        str = '原图';
    else
        idft_out{i-1}(idft_out{i-1}<0) = 0;
        imshow(idft_out{i-1},[]);
        str = ['经D0=',num2str(d0(i-1)),'的布特沃斯高通滤波器滤波后的结果'];
    end
    title(str);   
end

5.4 实验结果

在这里插入图片描述


六、频率域:锐化图像 — 高斯高通滤波器 P178

6.1 实验内容

高斯高通滤波器的实验

6.2 文件目录结构

在这里插入图片描述

6.3 Matlab代码

% 高斯高通滤波器的实验 P171
close all;clear all;clc;
% 读入图像
in = imread('Fig0441(characters_test_pattern).tif');
% 计算得到图像的频谱
dft_spectrum = fftshift(fft2(double(in)));
 
% 取不同的截止频率得到的模糊图像
% 截止频率
d0 = [30,60,160];
[row,column] = size(in);
 
 
h_hhpf = {};
for i = 1:length(d0)
    h_hhpf{end+1} = hhpf(row,column,d0(i));
end
 
% 使用不同截止频率的滤波器对原图像进行过滤
idft_out = {};
for i = 1:length(h_hhpf)
    idft_out{end+1} = real(ifft2(ifftshift(h_hhpf{i} .* dft_spectrum)));
end
 
% 显示图像
figure;
for i = 1:length(idft_out)+1
    subplot(1,4,i);
    if i == 1
        imshow(in);
        str = '原图';
    else
        idft_out{i-1}(idft_out{i-1}<0) = 0;
        imshow(idft_out{i-1},[]);
        str = ['经D0=',num2str(d0(i-1)),'的高斯高通滤波器滤波后的结果'];
    end
    title(str);   
end

6.4 实验结果

在这里插入图片描述


七、频率域:锐化图像 — 指纹图像的锐化 P179

7.1 实验内容

对指纹图像进行高斯高通滤波

7.2 文件目录结构

在这里插入图片描述

7.3 Matlab代码

% 对指纹图像进行高斯高通滤波 P179
close all;clear all;clc;
 
% 读入图像
in = imread('Fig0457(thumb_print).tif');
 
% 布特沃斯高通滤波器滤波
[row,column] = size(in);
 
% n = 4,截止频率取 50
h_bhpf = bhpf(row,column,4,50);
 
% 滤波
dft_center = fftshift(fft2(double(in)));
idft_finger = real(ifft2(ifftshift(dft_center .* h_bhpf)));
 
% 阈值处理
 
% 显示图片
figure;
subplot(1,3,1);
imshow(in);
title('(a)指纹图像');
 
subplot(1,3,2);
idft_finger(idft_finger<0) = 0;
imshow(idft_finger,[]);
title('(b)使用n=4,d0=50的布特沃斯高通滤波器滤波后的图像');
 
subplot(1,3,3);
idft_finger(idft_finger<5) = 0;
idft_finger(idft_finger>0) = 1;
imshow(idft_finger);
title('(c)对图(b)进行阈值处理');
 

7.4 实验结果

在这里插入图片描述


八、频率域:锐化图像 — 拉普拉斯算子 P180

8.1 实验内容

频率中使用拉普拉斯算子的实验

8.2 文件目录结构

在这里插入图片描述

8.3 Matlab代码

% 频率中使用拉普拉斯算子的实验 P180
close all;clear all;clc;
 
% 读入图像
in = imread('Fig0458(blurry_moon).tif');
 
% 创建拉普拉斯的滤波器
[row,column] = size(in);
h_laplace = laplace(row,column);
 
% 使用拉普拉斯滤波器对原图像进行滤波
dft_center = fftshift(fft2(double(in)));
idft_laplace = real(ifft2(ifftshift(dft_center .* h_laplace)));
 
% 标定 idft_laplace
% idft_laplace = idft_laplace - min(idft_laplace);
% idft_laplace = 255 * (idft_laplace ./ max(idft_laplace));
 
out = mat2gray(in) - mat2gray(idft_laplace);
 
 
% 显示图像
figure;
subplot(1,2,1);
imshow(in);
title('(a)原始模糊图像')
 
subplot(1,2,2);
imshow(mat2gray(out));
title('(b)在频率域中使用拉普拉斯算子增强后的图像')

8.4 实验结果

在这里插入图片描述


九、频率域:锐化图像 — 胸部X射线图像(高频强调滤波) P181

9.1 实验内容

高频强调滤波增强图像

9.2 文件目录结构

在这里插入图片描述

9.3 Matlab代码

% 高频强调滤波增强图像 P181
close all;clear all;clc;
% 读入图像
in = imread('Fig0459(orig_chest_xray).tif');
 
% 创建高频强调滤波器(d0 = 40)
% 强调量的大小
e = 1;
[row,column] = size(in);
h_hhpf = hhpf(row,column,40);
 
% 高频强调滤波器
h_hhepf = hhepf(row,column,0.25,0.75,40);
 
% 使用高斯高通滤波器过滤的图像
dft_center = fftshift(fft2(double(in)));
idft_hhpf = real(ifft2(ifftshift(dft_center .* h_hhpf)));
 
% 使用高频强调滤波器过滤的图像
dft_center = fftshift(fft2(double(in)));
idft_hhepf = real(ifft2(ifftshift(dft_center .* h_hhepf)));
 
% 显示图像
figure;
subplot(2,2,1);
imshow(in);
title('(a)一幅胸部X射线图像');
 
subplot(2,2,2);
idft_hhpf(idft_hhpf < 0) = 0;
imshow(idft_hhpf,[]);
title('(b)使用高斯高通滤波器滤波的结果');
 
subplot(2,2,3);
idft_hhepf(idft_hhepf < 0) = 0;
imshow(idft_hhepf,[]);
title('(c)使用高频强调滤波器滤波的结果');
 
subplot(2,2,4);
imshow(histeq(mat2gray(idft_hhepf),255));
title('(d)将图像(c)直方图均衡后的结果');
 

9.4 实验结果

在这里插入图片描述


十、频率域:锐化图像 — 同态滤波器 P184

10.1 实验内容

使用同态滤波器滤波的实验

10.2 文件目录结构

在这里插入图片描述

10.3 Matlab代码

% 使用同态滤波器滤波的实验 P183
close all;clear all;clc;
 
% 读入图像
in = imread('Fig0462(PET_image).tif');
 
% 创建同态滤波器
[row,column] = size(in);
h_cs = com_status(row,column,0.25,2,1,80);
 
% 使用同态滤波器滤波
% 防止in = 0,导致ln发送错误
in_ln = log(double(in + 1));
dft_center = fftshift(fft2(in_ln));
idft_cs = ifft2(ifftshift(dft_center .* h_cs));
out = exp(idft_cs) - 1;
 
 
% 显示图像
figure;
subplot(1,2,1);
imshow(in);
title('(a)全身PET扫面图像');
 
subplot(1,2,2);
out(out<0) = 0;
imshow(out,[]);
title('(b)用同态滤波增强的图像');
 

10.4 实验结果

在这里插入图片描述


十一、频率域:选择滤波 — 陷波滤波器(过滤莫尔模式) P186

11.1 实验内容

显示使用陷波滤波器对莫尔模式图像进行过滤的实验1 P186

11.2 文件目录结构

在这里插入图片描述

11.3 Matlab代码

% 显示使用陷波滤波器对莫尔模式图像进行过滤的实验1 P186
close all;clear all;clc;
% 读入图像
in = imread('Fig0464(car_75DPI_Moire).tif');
[row,column] = size(in);
% 傅里叶变换(中心化)
dft_out = fftshift(fft2(double(in)));
 
% 创建陷波带阻滤波器
n = 4;
d0 = 10;
h_nr = double(ones(row,column));
xy_label = {[43,55],[39,112],[84,56],[81,112],[165,57],[161,113],[207,57],[203,114]};
for i = 1:length(xy_label)
    x = xy_label{i}(1);
    y = xy_label{i}(2);
    h_nr = h_nr .* bhpf(row,column,x,y,n,d0);
end
% F*H频率域中的结果
g_nr = dft_out .* h_nr;
 
% 傅里叶反变换求出在空间域中的图像阵列
space_out = real(ifft2(ifftshift(g_nr)));
 
 
 
% 显示图像
show_ = {in,log(1+abs(dft_out)),log(1+abs(g_nr)),space_out};
title_ = {'(a)显示莫尔模式的取样过的报纸图像','(b)该图像的谱','(c)布特沃斯陷波带阻滤波器乘以傅里叶变换后的结果','(d)滤波后的图像'};
figure;
for i = 1:length(show_)
    subplot(1,4,i);
    imshow(show_{i},[]);
    title(title_{i});
end

11.4 实验结果

在这里插入图片描述


十二、频率域:选择滤波 — 陷波滤波器(过滤近似的周期干扰) P186

12.1 实验内容

显示使用陷波滤波器对存有近似的周期干扰的图像进行过滤的实验

12.2 文件目录结构

在这里插入图片描述

12.3 Matlab代码

% 显示使用陷波滤波器对存有近似的周期干扰的图像进行过滤的实验2 P186
close all;clear all;clc;
% 读入图像
in = imread('Fig0465(cassini).tif');
[row,column] = size(in);
% 傅里叶变换(中心化)
dft_out = fftshift(fft2(double(in)));
 
% 窄陷波矩形带阻滤波器
h_nrbr = narrow_rectangle_brfilter(row,column,column/2 - 1,10) .* narrow_rectangle_brfilter(row,column,column/2,10) .* narrow_rectangle_brfilter(row,column,column/2 + 1,10);
% 窄陷波矩形带通滤波器
h_nrbp = double(ones(row,column)) - h_nrbr;
 
% 去除周期性干扰
g_nr_out = dft_out .* h_nrbr;
idft_nr_out = real(ifft2(ifftshift(g_nr_out)));
 
% 获取干扰信息的空间域信息
g_np_out = dft_out .* h_nrbp;
idft_np_out = real(ifft2(ifftshift(g_np_out)));
 
% 显示图像
show_ = {in,log(1 + abs(dft_out)),log(1 + abs(h_nrbr)),idft_nr_out,h_nrbp,idft_np_out};
title_ = {'(a)显示近似周期干扰的土星环图像,图像大小为674*674像素','(b)谱:垂直轴上靠近原点的对应干扰模式的能量脉冲','(c)一个垂直陷波带阻滤波器','(d)滤波后的结果','(e)对应的一个垂直陷波带通滤波器','(f)图(a)中的周期性干扰成分的空间模式'};
 
figure;
for i = 1:length(show_)
    subplot(2,4,i);
    imshow(show_{i},[]);
    title(title_{i});
end

12.4 实验结果

在这里插入图片描述

  • 8
    点赞
  • 11
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

ModelBulider

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值