数字图像处理 实验3

数字图像处理 实验3及思考题

基本实验1

基于空间滤波的去噪

clear;clc
I = imread('Fig0507(b)(ckt-board-gauss-var-400).tif');
K1=medfilt2(I);
K2=medfilt2(K1);
K3=medfilt2(K2);
subplot(221);imshow(I);title('椒盐噪声图像');
subplot(222);imshow(K1);title('第1次中值滤波结果');
subplot(223);imshow(K2);title('第2次中值滤波结果');
subplot(224);imshow(K3);title('第3次中值滤波结果');

实验现象图
1

基本实验2

产生一模糊图像,采用维纳滤波图像复原的方法对图像进行处理

clc;clear;
d=15;%设定长度
h=zeros(2*d+1,2*d+1);
h(d+1,1:2*d+1)=1/(2*d);
f=imread('lena.tif');
[m,n]=size(f);
fe=zeros(m+2*d,n+2*d);%扩展f
fe(1:m,1:n)=f;
he=zeros(m+2*d,n+2*d);
he(1:2*d+1,1:2*d+1)=h;
F=fft2(fe);
H=fft2(he);
ns=5*rand(m+2*d,n+2*d);%产生噪声
g=ifft2(F.*H)+ns;
G=fft2(g);
K=0;
F_est=((H.^2)./(H.^2+K)).*G./H;%维纳滤波
f_est=real(ifft2(F_est));
subplot(131);imshow(f);title('原始图像');
subplot(132);imshow(g(d+1:m+d,d+1:n+d),[min(g(:))max(g(:))]);title('模糊后加噪声的图像');
subplot(133);imshow(f_est(1:m,1:n),[min(f_est(:))max(f_est(:))]);title('恢复后的图像');

实验现象图
2
这里有一个注意点
这里min和max之间是有空格的,或者加一个逗号,紧密相连会报错,分别表示low和high。
下面imshow函数是用法参考:

imshow(I)
example
imshow(X,map)
example
imshow(filename)
example
imshow(I,[low high])
imshow(___,Name,Value)
himage = imshow(___)



imshow(I,[low high])
[low high] — Grayscale image display range
two-element vector
Grayscale image display range, specified as a two-element vector. For more information, see the'DisplayRange' name-value pair argument.
Example: [50 250]
Data Types: single | double | int8 | int16 | int32 | int64 | uint8 | uint16 | uint32 | uint64

基本实验3

逆滤波与维纳滤波的比较

F = checkerboard(8);%生成原始图像
subplot(1,5,1);imshow(F,[]);title('a');
PSF=fspecial('motion',7,45)%生成运动模糊图像
MF=imfilter(F,PSF,'circular');
noise=imnoise(zeros(size(F)),'gaussian',0,0.01);%产生噪声
MFN=MF+noise;
subplot(152);imshow(MFN,[]);title('b.');
NSR=sum(noise(:).^2)/sum(MFN(:).^2);
subplot(153);imshow(deconvwnr(MFN,PSF),[]);title('c.');%逆滤波复原
subplot(154);imshow(deconvwnr(MFN,PSF,NSR),[]);title('d.');%维纳滤波复原
Sn=abs(fft2(noise)).^2;
Sf=abs(fft2(F)).^2;%未退化图像功率谱
NCORR=fftshift(real(ifft2(Sn)));
ICORR=fftshift(real(ifft2(Sf)));
subplot(155);imshow(deconvwnr(MFN,PSF,NCORR,ICORR),[]);title('e.');

实验想象图

3

实验思考题

设计一个二维线形运动滤波器PSF对图像文件进行运动模糊处理,然后分别用逆滤波与维纳滤波的方法进行复原.

实验代码

F=imread('cameraman.tif');
subplot(2,2,1);imshow(F,[]);title('原图');
PSF=fspecial('motion',6,45);
MFN=imfilter(F,PSF);
subplot(2,2,2);
imshow(MFN,[]);title('模糊图像');
subplot(2,2,3);
imshow(deconvwnr(MFN,PSF),[]);title('逆滤波复原');
NSR=0.1;
subplot(2,2,4);
imshow(deconvwnr(MFN,PSF,NSR),[]);title('维纳滤波复原');

实验现象图

4

猜你喜欢

转载自blog.csdn.net/klaus_x/article/details/80544526
今日推荐