图像处理综合性实验报告
实验四 综合实验
一、实验目的
1、掌握matlab编程语言进行编程。
2、用matlab及运用各种数字图像处理方法实现对图像的变换。
二、实验设备
计算机、Matlab软件
三、实验原理
图像预处理是相对于图像识别、图像理解而言的一种前期处理。不论采用何种装置,输入的图像往往不能令人满意。例如,从美学的角度会感到图像中物体的轮廓过于鲜明而显得不协调;按检测对象物大小和形状的要求看,图像的边缘过于模糊;在相当满意的一幅图像上会发现多了一些不知来源的黑点或白点;图像的失真、变形等等。总之,输入的图像在视觉效果和识别方便性等方面可能存在诸多问题,这类问题不妨统称为“质量”问题。尽管由于目的、观点、爱好等的不同,图像质量很难有同意的定义和标准,但是,根据应用要改善图像质量却是一个共同的愿望。
改善图像质量的处理称为图像预处理,主要是指按需要对图像进行适当的变换突出某些游泳的信息,去除或削弱无用的信息,如改变图像对比度,去除噪声或强调边缘的处理等。
四、实验步骤
1.对图像灰度非线性变换
2.对某个图像进行直方图均衡化
3.对图像进行直方图规定化
4.对图像进行空间域低通滤波
5.对图片进行低通滤波处理
6.对图像进行空域高通滤波法
7.通过各种频域低通滤波器方法对图像进行处理
五、源程序清单、测试数据、结果
1、灰度非线性变换
图像灰度变换是图像增强的一种手段。其中灰度非线性变换能使图像灰度的分布均匀,与人的视觉特性相匹配。MATLAB语言编写的例程和图像运行结果如下:
%GRAY TRANSFORM
clc;
imshow(I);
J=imadjust(I,[0.3 0.7],[0 1],1);%transfroms the values in the intensity image I to
%values in J by linealy mapping values between %0.3 and 0.7 to values between 0 and 1
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],1);%If GAMMA is less than 1,the mapping%is weighted toward higher (brighter)output values.
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],1.5);% If GAMMA is greater than 1,the % mapping is weighted toward lower (darker)output values.
figure;
imshow(J);
J=imadjust(I,[0.3 0.7],[0 1],1);% If TOP < BOTTOM,the output image % is reversed,as in a photogrphic negative.
figure;
imshow(J);
2、对 tire图像进行直方图均衡化图示:
直方图均衡化是通过变换函数将原图的直方图调整为平坦的直方图。MATLAB语言编写的例程和图像运行结果如下:
% HISTGRAM EAQUALIZATION
clc; %Clear command window
imshow(I); %displays the intensity image I with 256 gray levels
figure; %creats a new figure window
imhist(I); %displays s histogram for the imtensity image I
J=histeq(I,); %transforms the intensity image I, returning in J an
%intensity
%image with discrete levels
figure;
imshow(J);
figure;
imhist(J);
J=histeq(I,32); %transfforms the intensity imageI, returning in
%J an intensity
%image with 32 discrete levels
figure;
imshow(J);
digure;
imhist(J);
3、直方图规定化
直方图规定化校正在运用均衡化原理的基础上,向人们提供了根据给定直方图作图像增强的手段。MATLAB语言编写的例程和图像运行结果如下:
% HISTGRAM REGULIZATION
clc; %Clear command window
J=histeq(I,32); %transforms the intensity image I,returning in
%J an intensity image with 32 discrete levels
[counts,x]=imhist(J); %displays a histogram for the intensity image I
figure;
imshow(Q);
figure;
imhist(Q);
M=histeq(Q,counts); %transforms the intensity image Q so that the
%histogram of the output image M approximately matches counts
figure;
imshow(M);
figure;
imhist(M);
4、空间域低通滤波
由于图像中噪声空间相关性弱的性质,它们的频谱一般为于空间频率较高的区域,而图像本身的频率分量则处于较低的空间频率区域之内,可通过低通滤波的方法来实现平滑。
4.1、三种躁声举例
clc;
imshow(I);
J1=imnoise(I,'gaussian');%adds Gaussian white noise of mean O and
%variance 0.01 to image I.
figure;
imshow(J1);
J2=imnoise(I,'salt & pepper');%adds salt and pepper noise of 0.05
%noise density to image I
figure;
imshow(J2);
J3=imnoise(I,'speckle');%adds multiplicative noise to image I
figure;
imshow(J3);
4.2、二维中值滤波
% IMAGE NOISE REDUCTION WITH MEDIAN FILTER
clc;
hood=3;
imshow(I,map);
noisy=imnoise(I,'salt & pepper',0.05);
figure;
imshow(noisy,map);
filtered1=medfilt2(noisy,[hood hood]);
figure;
imshow(filtered1,map);
hood=5;
filtered2=medfilt2((noisy,hood hood]);
figure;
imshow(filtered2,map);
hood=7;
filtered3=medfilt2(noisy,[hood hood]);
figure;
imshow(filtered3,map);
4.3、均值滤波
%IMAGE NOISE REDUCTION WITH MEAN ALGORITHM
clc;
[I,map]=imread('eight.tif');
noisy=imnoise(I,'salt & pepper', 0.05);
myfit1=[0 1 0;1 1 1;0 1 0];
myfit1=myfit1/9;
filtered1=filter2(myfit1,noisy);
imshow(filtered1,map);
myfit2=[1 1 1 ;1 1 1;1 1 1];
myfit2=myfit2/9;
filtered2=filter2(myfit1,noisy);
figure;
imshow(filtered2,map);
5、低通滤波
%LOWPASS FILTER
clc;
[I,map]=imread('eight.tif');
noisy=imnoise(I,'gaussian',0.05);
imshow(noisy,map);
myfit1=[1 1 1 ;1 1 1;1 1 1];
myfit1=myfit1/9;
filtered1=filter2(myfit1,noisy);
figure;
imshow(filtered1,map);
myfit2=[1 1 1 ;1 2 1;1 1 1];
myfit2=myfit2/10;
filtered2=filter2(myfit2,noisy);
figure;
imshow(filtered2,map);
myfit3=[1 2 1 ;2 4 2;1 2 1];
myfit3=myfit3/16;
filtered3=filter2(myfit3,noisy);
figure;
imshow(filtered3,map);
6、空域高通滤波法
图像边缘与高频分量相对应,高通滤波器让高频分量畅通无阻,而对低频分量则充分。MATLAB语言编写的例程和图像运行结果如下:
%highpass filter
clc;
[I,map]=imread('eight.tif');
imshow(I,map);
myfilt1=[0 -1 0; -1 5 -1;0 -1 0]
filtered1=filter2(myfilt1,I);
figure;
imshow(filtered1,map);
myfilt2=[-1 -1 -1; -1 9 -1;-1 -1 -1]
filtered2=filter2(myfilt2,I);
figure;
imshow(filtered2,map);
myfilt3=[1 -2 1;-2 5 -2;1 -2 1];
filtered3=filter2(myfilt3,I)
figure;
imshow(filtered3,map);
myfilt4=[-1 -2 -1;-2 19 -2;-1 -2 -1];
myfilt4=myfilt4/7;
filtered4=filter2(myfilt4,I);
figure;
imshow(filtered4,map);
myfilt5=[-2 1 -2; 1 6 1;-2 1 -2];
myfilt5=myfilt5/2;
filtered5=filter2(myfilt5,I);
figure;
imshow(filtered5,map);
7、各种频域低通滤波器
通过频域对一定范围的高频分量的衰减能够达到平滑化,其中有理想低通滤波器、巴特沃思滤波器、指数滤波器、梯形低通滤波器。各种频域低通滤波器的MATLAB语言编写的例程和图像运行结果如下:
%FREQUENCY LOW PASS FILTER
clc;
[I,map]=imread('eight.tif');
noisy=imnoise(I,'gaussian',0.01);
imshow(noisy,map);
[M N]=size(1);
F=fft2(noisy);
fftshift(F);
Dcut=100;
D0=150;
D1=250;
for u=1:M
for v=1:N
D(u,v)=sqrt(u^2+v^2);
BUTTERH(u,v)=1/(1+(sqrt(2)-1)*(D(u,v)/Dcut)^2);%BUTTEREORTH
%LOW PASS FILTER
EXPOTH(u,v)=exp(log(1/sqrt(2))*(D(u,v)/Dcut)^2);%EXPOTIONAL
%LOW PASS FILTER
if D(u,v)<=200
IDEALH(u,v)=1;%IDEAL LOE PASS FILTER
else
IDEAL(u,v)=0;
end
if D(u,v)<=D0
TRAPEH(u,v)=(D(u,v)-D1)/(D0-D1);
else
TRAPEH(u,v)=0;
end
end
end
IDEALG=IDEALH.*F;
IDEALfiltered=ifft2(IDEALG);
BUTTERG=BUTTERH.*F;
BUTTERfiltered=ifft2(BUTTERG);
EXPOTG=EXPOTH.*F;
EXPOTfiltered=ifft2(EXPOTG);
TRAPEG=BUTTERH.*F;
TRAPEfiltered=ifft2(TRAPEG);
figure;
imshow(IDEALfiltered,map)
figure;
imshow(BUTTERfiltered,map)
figure;
imshow(EXPOTfiltered,map)
figure;
imshow(TRAPEfiltered,map)
六、实验出现的问题、实验结果分析
1. 在对图像进行处理时如果图片格式不符,则在运行时会出现错误。
2. 黑白图片比彩色图片容易处理,效果明显。
3. 出现这些问题可能是因为matlab有误差的原因。
七、试验小结和思考
在进行对图像处理的实验中,输入的图像在视觉效果和识别方便性等方面可能存在诸多问题 。图像处理就是对图像进行适当的变换突出某些有用的信息,去除或削弱无用的信息。他应用于日常生活中的很多方面如通讯、宇宙探测、医学领域等。下载本文