实验二 空间域图像增强.docx
《实验二 空间域图像增强.docx》由会员分享,可在线阅读,更多相关《实验二 空间域图像增强.docx(11页珍藏版)》请在冰点文库上搜索。
实验二空间域图像增强
实验二空间域图像增强
一、实验目的
1、了解空间域图像增强的各种方法(点处理、掩模处理);
2、通过编写程序掌握采用直方图均衡化进行图像增强的方法;
3、使用邻域平均法编写程序实现图像增强,进一步掌握掩模法及其改进(加门限法)消除噪声的原理;
二、实验环境及开发工具
Windws2000/XP、MATLAB6.x、VisualC++、VisualBasic或其它
三、实验方法
对如图所示的两幅128×128、256级灰度的数字图像fing_128.img和cell_128.img进行如下处理:
(1)对原图像进行直方图均衡化处理,同屏显示处理前后图像及其直方图,比较异同,并回答为什么数字图像均衡化后其直方图并非完全均匀分布。
(2)对原图像加入点噪声,用4-邻域平均法平滑加噪声图像(图像四周边界不处理,下同),同屏显示原图像、加噪声图像和处理后的图像。
①不加门限;
②加门限
,(其中
)
四、实验结果及分析
1、直方图均衡化处理
程序如下:
clc;
fid=fopen('F:
\数字图像\图像\img\fing_128.img','r');
f=fread(fid,[128,128],'uchar');
subplot(2,1,1);
imshow(f,[0,255]);
q=zeros(1,256);
forx=1:
128
fory=1:
128
q(f(x,y)+1)=q(f(x,y)+1)+1;
end
end
s=q./(128*128);
X=0:
255;
subplot(2,1,2);
bar(X,s');
figure;
t=zeros(1,256);
t
(1)=s
(1);
fori=2:
256
t(i)=t(i-1)+s(i);
end
subplot(2,1,1);
bar(X,t');
t0=floor(255*t+0.5);
subplot(2,1,2);
bar(X,t0');
figure;
t1=zeros(1,256);
fori=1:
256
t1(t0(i)+1)=s(i)+t1(t0(i)+1);
end
subplot(2,1,1);
bar(X,t1');
f1=zeros(128,128)
forx=1:
128
fory=1:
128
f1(x,y)=t0(f(x,y)+1);
end
end
subplot(2,1,2);
imshow(f1,[0,255]);
运行结果:
(1)、指纹均衡化处理
(2)、细胞的均衡化处理
2、对原图像加入点噪声
程序代码
不加门限:
clc;
fid=fopen('F:
\数字图像\图像\img\fing_128.img','r');
f=fread(fid,[128,128],'uchar');
subplot(2,2,1);
imshow(f,[0,255]);
forx=1:
128
fory=1:
128
ifx==y
f(x,y)=255;
elseifx+y==100
f(x,y)=0;
end
end
end
subplot(2,2,2);
imshow(f,[0,255]);
f0=f;
forx=2:
127
fory=2:
127
f0(x,y)=(f((x-1),y)+f((x+1),y)+f(x,(y-1))+f(x,(y+1)))./4;
end
end
subplot(2,2,3);
imshow(f0,[0,255]);
t=fft2(f);
T=t(1,1)/128;
f1=f;
forx=2:
127
fory=2:
127
h=(f((x-1),y)+f((x+1),y)+f(x,(y-1))+f(x,(y+1)))./4;
ifabs(f(x,y)-h)>T
f1(x,y)=h;
else
f1(x,y)=f(x,y);
end
end
end
subplot(2,2,4);
imshow(f1,[0,255]);
运行结果:
加门限:
clc;
fid=fopen('F:
\数字图像\图像\img\fing_128.img','r');
fg=fread(fid,[128,128],'uchar');
subplot(2,2,1);
imshow(fg,[0,255]);
a=randn(128,128);
f=a.*20+fg;
subplot(2,2,2);
imshow(f,[0,255]);
f0=f;
forx=2:
127
fory=2:
127
f0(x,y)=(f((x-1),y)+f((x+1),y)+f(x,(y-1))+f(x,(y+1)))./4;
end
end
subplot(2,2,3);
imshow(f0,[0,255]);
t=fft2(f);
T=t(1,1)/128;
f1=f;
forx=2:
127
fory=2:
127
h=(f((x-1),y)+f((x+1),y)+f(x,(y-1))+f(x,(y+1)))./4;
ifabs(f(x,y)-h)>T
f1(x,y)=h;
else
f1(x,y)=f(x,y);
end
end
end
subplot(2,2,4);
imshow(f1,[0,255]);
运行结果:
(1)细胞加入噪声及去噪
3、结果分析
(1)直方图均衡化处理后图像的对比度增强,变得相对清晰,达到了图像增强的效果。
(2)去噪的同时图像的某些细节变得模糊。
五、实验心得
1、通过本次试验了解了空间域图像增强的各种方法,如点处理、掩模处理等。
2、学会并掌握了编写采用直方图均衡化进行图像增强的方法。