海南大学数字图像处理实验5.docx

上传人:b****6 文档编号:16703558 上传时间:2023-07-16 格式:DOCX 页数:17 大小:1.39MB
下载 相关 举报
海南大学数字图像处理实验5.docx_第1页
第1页 / 共17页
海南大学数字图像处理实验5.docx_第2页
第2页 / 共17页
海南大学数字图像处理实验5.docx_第3页
第3页 / 共17页
海南大学数字图像处理实验5.docx_第4页
第4页 / 共17页
海南大学数字图像处理实验5.docx_第5页
第5页 / 共17页
海南大学数字图像处理实验5.docx_第6页
第6页 / 共17页
海南大学数字图像处理实验5.docx_第7页
第7页 / 共17页
海南大学数字图像处理实验5.docx_第8页
第8页 / 共17页
海南大学数字图像处理实验5.docx_第9页
第9页 / 共17页
海南大学数字图像处理实验5.docx_第10页
第10页 / 共17页
海南大学数字图像处理实验5.docx_第11页
第11页 / 共17页
海南大学数字图像处理实验5.docx_第12页
第12页 / 共17页
海南大学数字图像处理实验5.docx_第13页
第13页 / 共17页
海南大学数字图像处理实验5.docx_第14页
第14页 / 共17页
海南大学数字图像处理实验5.docx_第15页
第15页 / 共17页
海南大学数字图像处理实验5.docx_第16页
第16页 / 共17页
海南大学数字图像处理实验5.docx_第17页
第17页 / 共17页
亲,该文档总共17页,全部预览完了,如果喜欢就下载吧!
下载资源
资源描述

海南大学数字图像处理实验5.docx

《海南大学数字图像处理实验5.docx》由会员分享,可在线阅读,更多相关《海南大学数字图像处理实验5.docx(17页珍藏版)》请在冰点文库上搜索。

海南大学数字图像处理实验5.docx

海南大学数字图像处理实验5

实验五、图象复原

一、实验目的

1.了解图象退化的几种原因;

2.掌握对相应退化原因的复原方法。

二、实验内容

1.使用函数fspecial()和imfilter()模拟产生退化图象;

2.对于不同的噪声引起图像的退化,采用不同的滤波方法复原图象。

3.学会使用维纳滤波器deconvwnr()函数对图像进行复原的方法。

三、实验步骤

1.加性噪声退化图象

用imnoise()函数给图象加噪声,如增加高斯白噪声。

使用平滑滤波器对其进行滤波,可达到复原图像的效果

x=imread(‘cameraman.tif’);

x=imnoise(x,’gaussian’)

imshow(x)

加噪声后图象

h=fspecial(‘average’)

y=imfilter(x,h);

figure

imshow(y)

平滑滤波后

2、周期噪声退化图像

对于周期噪声可以通过频域滤波来减弱或消除,实现复原图像。

实验五文件夹中有被正弦周期噪声污染退化的图像'pout_g_64.bmp',使用理想带阻滤波器对其频域滤波,复原图像。

(1)pout_g_64.bmp图像及其傅立叶谱见下图。

 

(2)构造理想带阻滤波器

closeall

x=imread('pout_g_64.bmp');

xm=size(x,1);xn=size(x,2);

M2=floor(xm/2);N2=floor(xn/2);

u=-M2:

1:

M2-1;v=-N2:

1:

N2-1;

[U,V]=meshgrid(u,v);

D=sqrt(U.^2+V.^2);

D0=64;W=4;

H=double(D<(D0-W/2)|D>(D0+W/2));

figure

Mesh(U,V,H);

title('D0=64,W=4,理想带阻滤波器')

思考:

使用上述理想带阻滤波器对’pout_g_64.bmp’图像进行频域滤波,得到复原图像,结果类似下图。

代码如下:

closeall

x=imread('pout_g_64.bmp');

xm=size(x,1);xn=size(x,2);

M2=floor(xm/2);N2=floor(xn/2);

u=-M2:

1:

M2-1;v=-N2:

1:

N2-1;

[U,V]=meshgrid(u,v);

D=sqrt(U.^2+V.^2);

D0=64;W=4;

H=double(D<(D0-W/2)|D>(D0+W/2));

figure

Mesh(U,V,H);

title('D0=64,W=4,理想带阻滤波器')

F=fft2(x);

G=H.*fftshift(F);%需要中心平移

g=ifft2(ifftshift(G));%反中心平移

figure%tu2

subplot(121);imshow(real(G));title('频域滤波')

subplot(122);imshow(uint8(real(g)));title('滤波后图象')

 

3、运动模糊退化图像

给图像添加运动模糊,使用deconvwnr()维纳滤波器进行图像复原。

closeall

I=imread('cameraman.tif');

imshow(I)

title('originalimage')

len=31;

theta=10;

PSF=fspecial('motion',len,theta);%len模糊长度,theta运动角度

Iblurred=imfilter(I,PSF,'circular','conv');%对图像进行运动模糊

figure

imshow(Iblurred)

title('blurredimage')

原始图象添加运动模糊后图象

Irestored=deconvwnr(Iblurred,PSF);%使用维纳滤波器复原图像

figure

imshow(Irestored)

title('retoredimage')

使用维纳滤波器复原后图像

思考:

修改deconvwnr()函数的参数PSF,使len和theta分别为原来的2倍,观察结果,体会真实PSF在图像复原中的重要性。

PSF1=fspecial('motion',2*len,theta),PSF2=fspecial('motion',len,2*theta)

代码如下:

loseall

I=imread('cameraman.tif');

imshow(I)

title('originalimage')

len=31;

theta=10;

PSF1=fspecial('motion',2*len,theta);

PSF2=fspecial('motion',len,theta*2);%len模糊长度,theta运动角度

Iblurred=imfilter(I,PSF,'circular','conv');%对图像进行运动模糊

figure

imshow(Iblurred)

title('blurredimage')

Irestored=deconvwnr(Iblurred,PSF1);%使用维纳滤波器复原图像

figure

imshow(Irestored)

title('retoredby2*len')

Irestored=deconvwnr(Iblurred,PSF2);%使用维纳滤波器复原图像

figure

imshow(Irestored)

title('retoredbytheta*2')

4、模拟模糊和噪声:

模拟实时图像可能出现的模糊(即由于摄像头运动或者缺乏聚集而产生的模糊)和噪声(即随机分布噪声)。

使用维纳滤波器复原图像,即使用deconvwnr()函数复原。

(1)只使用点扩散函数PSF参数复原图像。

deconvwnr(BlurredNoisy,PSF)

%---------使用高斯模板模糊图像------------------

closeall

I=imread('cameraman.tif');

figure

imshow(I)

title('originalimage')

PSF=fspecial('gaussian',11,5);

blurredI=imfilter(I,PSF);%模糊图像

figure

imshow(blurredI)

title('blurredimage')

%-----------产生噪声,并加噪声到已模糊的图像----------------

%----------使用randn()函数产生随机数据------------------

noise=0.2*randn(size(I));%同图像大小一致

blurredInoisy=imadd(blurredI,im2uint8(noise));%噪声添加到图像

figure

imshow(blurredInoisy)

title('blurred&noiseimage')

%----------------------使用维纳滤波复原图像---------------

wnrI1=deconvwnr(blurredInoisy,PSF);%噪声被放大了

figure

imshow(wnrI1)

title('restoredwithPSF')

(2)使用信噪比NSR参数复原图像。

deconvwnr(BlurredNoisy,PSF,NSR)

I是输入图像,noise是randn()函数产生的随机噪声,下面的公式用于计算信噪比:

NSR=sum(noise(:

).^2)/sum(im2double(I(:

)).^2);%计算信噪比

 

代码如下:

closeall

I=imread('cameraman.tif');

figure

subplot(221)

imshow(I)

title('originalimage')

PSF=fspecial('gaussian',11,5);

blurredI=imfilter(I,PSF);%模糊图像

figure

subplot(222)

imshow(blurredI)

title('blurredimage')

%-----------产生噪声,并加噪声到已模糊的图像----------------

%----------使用randn()函数产生随机数据¬------------------

noise=0.2*randn(size(I));%同图像大小一致

blurredInoisy=imadd(blurredI,im2uint8(noise));%噪声添加到图像

NSR=sum(noise(:

).^2)/sum(im2double(I(:

)).^2);

figure

subplot(223)

imshow(blurredInoisy)

title('blurred&noiseimage')

%----------------------使用维纳滤波复原图像---------------

wnrI1=deconvwnr(BlurredNoisy,PSF,NSR)%噪声被放大了

figure

subplot(224)

imshow(wnrI1)

title('restoredwithPSF,NSR')

 

运行结果如上图

思考:

使用deconvwnr(BlurredNoisy,PSF,NSR)维纳滤波器对上述被模糊和噪声退化的图像进行复原。

结果类似下图。

代码如下:

wnrI1=deconvwnr(BlurredNoisy,PSF,NSR)%噪声被放大了

figure

subplot(224)

imshow(wnrI1)

title('restoredwithPSF,NSR')

运行结果:

 

(3)使用自相关函数改善图像复原的效果。

deconvwnr(BlurredNoisy,PSF,NCORR,ICORR)

NCORR:

噪声的自相关函数

NP=abs(fft2(noise)).^2;%噪声的功率谱

NCORR=fftshift(real(ifft2(NP)));%噪声的自相关函数

ICORR:

图像自相关函数

IP=abs(fft2(im2double(I))).^2;%图像的功率谱

ICORR=fftshift(real(ifft2(IP)));%图像的自相关函数

代码如下:

closeall

I=imread('cameraman.tif');

subplot(221)

imshow(I)

title('originalimage')

PSF=fspecial('gaussian',11,5);

blurredI=imfilter(I,PSF);

subplot(222)

imshow(blurredI)

title('blurredimage')

noise=0.2*randn(size(I));

blurredInoisy=imadd(blurredI,im2uint8(noise));

NP=abs(fft2(noise)).^2;

NCORR=fftshift(real(ifft2(NP)));

IP=abs(fft2(im2double(I))).^2;

ICORR=fftshift(real(ifft2(IP)));

subplot(223)

imshow(blurredInoisy)

title('blurred&noiseimage')

wnrI1=deconvwnr(blurredInoisy,PSF,NCORR,ICORR)

subplot(224)

imshow(wnrI1)

title('restoredwithPSF,NCORR,ICORR')

思考:

使用deconvwnr(BlurredNoisy,PSF,NCORR,ICORR)维纳滤波器对上述被模糊和噪声退化的图像进行复原。

结果类似下图。

代码如下:

wnrI1=deconvwnr(blurredInoisy,PSF,NCORR,ICORR)

subplot(224)

imshow(wnrI1)

title('restoredwithPSF,NCORR,ICORR')

运行结果:

 

仅供个人用于学习、研究;不得用于商业用途。

Forpersonaluseonlyinstudyandresearch;notforcommercialuse.

NurfürdenpersönlichenfürStudien,Forschung,zukommerziellenZweckenverwendetwerden.

Pourl'étudeetlarechercheuniquementàdesfinspersonnelles;pasàdesfinscommerciales.

 толькодлялюдей,которыеиспользуютсядляобучения,исследованийинедолжныиспользоватьсявкоммерческихцелях. 

以下无正文

展开阅读全文
相关资源
猜你喜欢
相关搜索
资源标签

当前位置:首页 > 医药卫生 > 基础医学

copyright@ 2008-2023 冰点文库 网站版权所有

经营许可证编号:鄂ICP备19020893号-2