数字图像实验报告Word文件下载.docx
《数字图像实验报告Word文件下载.docx》由会员分享,可在线阅读,更多相关《数字图像实验报告Word文件下载.docx(19页珍藏版)》请在冰豆网上搜索。
-1:
1];
ford=range
s1=2^(8-d)+s1;
s2=2^(8-d+1);
iftemp>
=s1&
temp<
s2;
J(i,j)=255;
break;
end
J=uint8(J);
figure;
imshow(J);
end
例4.11使用中值滤波降低图像噪声
57.jpg'
J=imnoise(I,'
salt&
pepper'
0.02);
subplot(121);
title('
含有椒盐噪声的图像'
)
J=double(J);
f=fft2(J);
g=fftshift(f)
[M,N]=size(f);
n=3;
d0=20
n1=floor(M/2)
n2=floor(N/2)
fori=1:
d=sqrt((i-n1)^2+(j-n2)^2)
h=1/(1+(d/d0)^(2*n));
g(i,j)=h*g(i,j);
g=ifftshift(g);
g=uint8(real(ifft2(g)));
subplot(122);
imshow(g);
例4.16同态滤波的增强效果
J=imread('
416.jpg'
g=fftshift(f);
d0=10;
r1=0.5;
rh=2
c=4;
n1=floor(M/2);
n2=floor(N/2);
d=sqrt((i-n1)^2+(j-n2)^2);
h=(rh-r1)*(1-exp(-c*(d.^2/d0.^2)))+r1;
例5.3逆滤波与威纳滤波的比较
F=checkerboard(8);
figure
(1);
imshow(F,[]);
PSF=fspecial('
motion'
7,45);
MF=imfilter(F,PSF,'
circular'
noise=imnoise(zeros(size(F)),'
gaussian'
0,0.001);
MFN=MF+noise;
figure
(2);
imshow(MFN,[]);
NSR=sum(noise(:
).^2)/sum(MFN(:
).^2);
figure(3);
imshow(deconvwnr(MFN,PSF),[]);
figure(4);
imshow(deconvwnr(MFN,PSF,NSR),[]);
例5.7顺序统计滤波器比较
f=imread('
imshow(f);
原始图像'
g=imnoise(f,'
0.2);
椒盐噪声污染的图像'
g1=double(g)/255;
j1=medfilt2(g1,'
symmetric'
imshow(j1);
中值滤波图像'
j2=ordfilt2(g1,median(1:
3*3),ones(3,3),'
imshow(j2);
中点滤波图像'
j3=ordfilt2(g1,1,ones(3,3));
figure(5);
imshow(j3);
最小值滤波图像'
j4=ordfilt2(g1,9,ones(3,3));
figure(6);
imshow(j4);
最大值滤波图像'
例6.9灰度级---彩色变换法的MATLAB实现
69.jpg'
L=256;
ifI(i,j)<
L/4
R(i,j)=0;
G(i,j)=4*I(i,j);
B(i,j)=L;
elseifI(i,j)<
=L/2
G(i,j)=L;
B(i,j)=-4*I(i,j)+2*L;
=3*L/4
R(i,j)=4*I(i,j)-2*L;
B(i,j)=0;
else
R(i,j)=L;
G(i,j)=-4*I(i,j)+4*L;
G2C(i,j,1)=R(i,j);
G2C(i,j,2)=G(i,j);
G2C(i,j,3)=B(i,j);
G2C=G2C/256;
figure;
imshow(G2C);
例7.11DM编码的MATLAB实现
functiony=DMencode(x,a,delt)
X=[141514151315151420262728272729374762757778798081818282]
functiont=entropy(X)
t=entropy(X)
a=1;
delt=6.5;
y=DMencode(X,a,delt);
XX=DMdecode(y);
ax=[0:
1:
26]
[X2,Y2]=STAIRS(ax,XX)
plot(X2,Y2,'
k'
ax,X,'
error(nargchk(1,3,nargin))
ifnargin<
3
delt=6.5
2
x=double(x);
[m,n]=size(x);
p=zeros(m,n);
e=zeros(m,n);
qe=zeros(m,n);
ff=zeros(m,n);
ff(:
1)=x(:
1);
qe(:
m
forj=2:
n
p(i,j)=a.*ff(i,j-1);
e(i,j)=x(i,j)-p(i,j);
ife(i,j)>
qe(i,j)=delt;
else
qe(i,j)=-delt;
ff(i,j)=p(i,j)+qe(i,j);
end
y=qe;
functionx=DMdencode(y,a)
error(nargchk(1,2,nargin));
[m,n]=size(y);
x=zeros(m,n+1);
forj=1:
jj=j+1;
x(:
jj)=y(:
j)+a.*x(:
(jj-1));
x=x(:
1+1:
end);
运行结果如下:
X=
Columns1through19
14151415131515142026272827272937476275
Columns20through27
7778798081818282
例7.14基于FFT的图像压缩技术
cr=0.5;
I1=imread('
lena.bmp'
I1=double(I1)/255;
imshow(I1);
fftcoe=blkproc(I1,[88],'
fft2(x)'
coevar=im2col(fftcoe,[88],'
distinct'
coe=coevar;
[y,ind]=sort(coevar);
[m,n]=size(coevar);
snum=64-64*cr;
coe(ind(1:
snum),i)=0;
B2=col2im(coe,[88],[512512],'
I2=blkproc(B2,[88],'
ifft2(x)'
imshow(I2);
e=double(I1)-double(I2);
[m,n]=size(e);
erms=sqrt(sum(e(:
).^2)/(m*n))
例9.5灰度图像便捷跟踪
functiong=boundary_trace2(f);
95.jpg'
subplot(1,2,1);
g=im2double(f);
w=fspecial('
laplacian'
0);
g=imfilter(g,w,'
replicate'
h=boundary_tracr2(g)
subplot(1,2,2);
imshow(h);
边界跟踪结果'
cell_cp={[0,1],[-1,1],[-1,0],[-1,-1],[0,-1],[1,-1],[1,0],[1,1]};
cell_n={[-1,1],[1,1],[0,1];
[-1,0],[0,1],[-1,1];
[-1,-1],[-1,1],[-1,0];
[0,-1],...[-1,0],[-1,-1];
[1,-1],[-1,-1],[0,-1];
[1,0],[0,-1],[1,-1];
[1,1],[1,-1],...[1,0];
[0,1],[1,0],[1,1]};
f=padarray(f,[1,1],0,'
both'
boundaryval=-1000;
maxval=max(f(:
));
[rv,cv]=find(f==maxval);
s=[rv
(1),cv
(1)];
p=s;
minval=min(f(:
t=(maxval+minval)/2;
f(s
(1),s
(2))=boundaryval;
g=f(s
(1)-1:
s
(1)+1,s
(2)-1:
s
(2)+1);
maxval+max(g(:
[v,cv]=find(g==maxval);
c=p+[rv
(1)-2,cv
(1)-2];
done=f(c
(1),c
(2))<
t;
f(s
(1),s
(2))=-boundaryval;
while~done
f(c
(1),c
(2))=boundaryval;
c_p=c-p;
fordir=1:
length(cell_cp)
ifcell_cp{dir}==c_p
break;
maxval=boundaryval;
fori=1;
size(cell_n,2)
n2=c+cell_n{dir,i};
if(maxval<
f(n2
(1),n2
(2)))
maxval=f(n2
(1),n2
(2));
n=n2;
if(f(n
(1),n
(2))<
t|n==s)
done=ture;
p=c;
c=n;
end%while
bi=find(f==boundaryval);
f(:
)=0;
f(bi)=1;
f(s
(1),s
(2))=1;
f=f(2:
end-1.2:
end-1);
g=im2bw(f);
(95.jpg)
此题没运行出来
例9.9用wateshed算法分割图像
cameraman.tif'
subplot(2,2,1);
(a)原始图像'
subplot(2,2,2);
f=double(f);
hv=fspecial('
prewitt'
hh=hv.'
;
gv=abs(imfilter(f,hv,'
gh=abs(imfilter(f,hh,'
g=sqrt(gv.^2+gh.^2);
L=watershed(g);
wr=L==0;
imshow(wr);
(b)分水岭'
f(wr)=255;
subplot(2,2,3);
imshow(uint8(f));
(c)分割结果'
rm=imregionalmin(g);
subplot(2,2,4);
imshow(rm);
(d)局部极小值'
例9.10用改过的watershed算法分割图像
subplot(2,3,1);
subplot(2,3,2);
df=bwdist(f);
imshow(uint8(df*8));
(b)原图像的距离变换'
L=watershed(df);
em=L==0;
subplot(2,3,3);
imshow(em);
(c)标记外部约束'
im=imextendedmax(f,20);
subplot(2,3,4);
imshow(im);
(d)标记内部约束'
g2=imimposemin(g,im|em);
subplot(2,3,5);
imshow(g2);
(e)由标记内外约束重构梯度图'
L2=watershed(g2);
wr2=L2==0;
subplot(2,3,6);
f(wr2)=255;
(f)分割及结果'
实验总结:
在这几次试验中,我在运用MATLAB对图像进行数字化处理同时,不仅加深了对数字图像处理的理论知识的理解,而且更进一步的了解了一些课本以外的相关知识,感觉受益匪浅。
在今后的学习过程中,一定会更加努力,争取学好这方面的专业知识,为以后的深造打基础。