《数字图像处理》实验指导书Word格式.docx
《《数字图像处理》实验指导书Word格式.docx》由会员分享,可在线阅读,更多相关《《数字图像处理》实验指导书Word格式.docx(22页珍藏版)》请在冰点文库上搜索。
(2)实验项目(指导书中的详细内容不必抄录);
测试记录表;
波形图及现象记录。
(3)实验数据整理,计算后的结果、及根据实验数据绘制的曲线。
(4)实验分析,应包括和理论计算值的比较、现象分析。
7.关于实验考核:
学生在实验课中的实际技能水平和实验报告的质量是评定本课程实验成绩的标准。
因各种原因缺做实验和缺交实验报告者,实验成绩要受影响。
实验一图像增强和平滑
一.实验目的及要求
1.了解MATLAB的操作环境和基本功能。
2.掌握MATLAB中图像增强和平滑的函数的使用方法。
3.加深理解图像增强和平滑的算法原理。
二、实验内容
(一)研究以下程序,分析程序功能;
输入执行各命令行,认真观察命令执行的结果。
熟悉程序中所使用函数的调用方法,改变有关参数,观察试验结果。
(可将每段程序保存为一个.m文件)
1.直方图均衡化
clearall;
closeall%CleartheMATLABworkspaceofanyvariables
%andcloseopenfigurewindows.
I=imread('
pout.tif'
);
%Readsthesampleimages‘pout.tif’,andstoresitin
imshow(I)%anarraynamedI.displaytheimage
figure,imhist(I)%Createahistogramoftheimageanddisplayitin
%anewfigurewindow.
[I2,T]=histeq(I);
%Histogramequalization.
figure,imshow(I2)%Displaythenewequalizedimage,I2,inanewfigurewindow.
figure,imhist(I2)%CreateahistogramoftheequalizedimageI2.
figure,plot((0:
255)/255,T);
%plotthetransformationcurve.
imwrite(I2,'
pout2.png'
%WritethenewlyadjustedimageI2toadiskfilenamed
%‘pout2.png’.
imfinfo('
)%Checkthecontentsofthenewlywrittenfile
注意:
imadjust()
功能:
调整图像灰度值或颜色映像表,也可实现伽马校正。
语法:
J=imadjust(I,[low_inhigh_in],[low_outhigh_out],gamma)
newmap=imadjust(map,[low_inhigh_in],[low_outhigh_out],gamma)
RGB2=imadjust(RGB1,...)
2.直接灰度变换
closeall
cameraman.tif'
J=imadjust(I,[00.2],[0.51]);
imshow(I)
figure,imshow(J)
[X,map]=imread('
forest.tif'
figure,imshow(X,map)
I2=ind2gray(X,map);
J2=imadjust(I2,[],[],0.5);
figure,imshow(I2)
figure,imshow(J2)
J3=imadjust(I2,[],[],1.5);
figure,imshow(J3)
helpimadjust%Displaytheimadjust()functioninformation.
3.空域平滑滤波(模糊、去噪)
eight.tif'
h1=ones(3,3)/9;
h2=ones(5,5)/25;
I1=imfilter(I,h1);
I2=imfilter(I,h2);
figure
(1),imshow(I),title('
OriginalImage'
figure
(2),imshow(I1),title('
FilteredImageWith3*3'
)
figure(3),imshow(I2),title('
FilteredImageWith5*5'
%加入Gaussian噪声
J1=imnoise(I,'
gaussian'
0,0.005);
%加入椒盐噪声
J2=imnoise(I,'
salt&
pepper'
0.02);
%对J1、J2进行平均值平滑滤波
K1=imfilter(J1,fspecial('
average'
3));
K2=imfilter(J2,fspecial('
figure(4);
subplot(2,2,1),imshow(J1),title('
subplot(2,2,2),imshow(J2),title('
pepper'
subplot(2,2,3),imshow(K1),title('
average'
subplot(2,2,4),imshow(K2);
%对J1、J2进行中值滤波
K3=medfilt2(J1,[33]);
K4=medfilt2(J2,[33]);
figure(5);
subplot(2,2,3),imshow(K3),title('
Medianfiltering'
subplot(2,2,4),imshow(K4)
4.空域锐化滤波
moon.tif'
w=fspecial('
laplacian'
0)
w8=[1,1,1;
1,-8,1;
1,1,1]
I1=imfilter(I,w,'
replicate'
figure
(1);
imshow(I),title('
LaplacianImage'
f=im2double(I);
f1=imfilter(f,w,'
figure(3),imshow(f1,[]),title('
f2=imfilter(f,w8,'
f4=f-f1;
f8=f-f2;
figure(4),imshow(f4);
figure(5),imshow(f8);
(二)采用MATLAB底层函数编程实现
1.灰度变换之动态范围扩展
假定原图像f(x,y)的灰度范围为[a,b],希望变换后图像g(x,y)的灰度范围扩展至[c,d],则线性变换可表示为:
用MATLAB底层函数编程实现上述变换函数。
观察图像‘pout.tif’的灰度直方图,选择合适的参数[a,b]、[c,d]对图像‘pout.tif’进行灰度变换,以获得满意的视觉效果。
2.非锐化掩蔽和高升滤波
从原图像中减去其非锐化(平滑过的)图像的过程称为非锐化掩蔽,其基本步骤为:
对原图像进行平滑滤波得到模糊图像
;
从原图像中减去模糊图像,产生的差值图像称为模板
将模板加到原图像上,得到锐化后的图像
。
即,
用MATLAB函数编程实现上述功能。
三、实验设备
1.计算机;
2.MATLAB6.5及以上;
四、预习和思考
1.预习实验内容,阅读教材熟悉实验原理;
2.查阅资料,熟悉MATLAB的操作环境和基本功能。
熟悉实验中涉及的有关函数。
3.利用课余时间,用MATLAB底层函数编程实现实验内容
(二)中的灰度线性变换。
4.你能否给出实现样例程序功能的其它方法?
五、实验报告要求
1.简述试验的目的和试验原理;
2.叙述各段程序功能,改变有关函数的参数,分析比较实验结果;
3.打印出所编写的实验程序。
4.写出本实验的心得体会及意见。
实验二图像的几何变换
掌握图像几何变换的基本原理,熟练掌握数字图像的缩放、旋转、平移、镜像和转置的基本原理及其MATLAB编程实现方法。
1.图像缩放
clearall,closeall
Scale=1.35;
%将图像放大1.35倍
J1=imresize(I,Scale,'
nearest'
%usingthenearestneighborinterpolation
J2=imresize(I,Scale,'
bilinear'
%usingthebilinearinterpolation
imshow(I),title('
figure,imshow(J1),title('
ResizedImage--usingthenearestneighborinterpolation'
figure,imshow(J2),title('
ResizedImage--usingthebilinearinterpolation'
%查看imresize使用帮助
helpimresize
说明:
❶注意观察不同插值方法的图像表现;
❷改变图像缩放因子Scale,重做上述实验。
2.图像旋转
Theta=45;
%将图像逆时针旋转45︒。
J1=imrotate(I,Theta,'
%andenlargetheoutputimage
Theta=-45;
%将图像顺时针旋转45︒。
J2=imrotate(I,Theta,'
'
crop'
%usingthebilinearinterpolation
%andcropstheoutputimage
RotatedImage--usingthenearestneighborinterpolation'
RotatedImage--usingthebilinearinterpolation'
%查看imrotate使用帮助
helpimrotate
❶注意观察不同插值方法和输出图像后处理方法的图像表现;
❷改变旋转角度大小和方向,重做上述实验。
3.图像水平镜象
I1=flipdim(I,2);
I2=flipdim(I,1);
figure
(1),subplot(1,2,1),imshow(I);
subplot(1,2,2),imshow(I1);
figure
(2),subplot(2,1,1),imshow(I);
subplot(2,1,2),imshow(I2);
(二)用MATLAB编程实现以下图像几何变换
1.图像平移
2.图像转置
图像的转置是将给定图像像素的x坐标和y坐标互换的几何变换,设点P0(x0,y0)转置后的对应点为P(x,y),转置变换可表述为:
或
,对应的逆变换为:
转置后图像的宽、高发生改变,即输出图像的高度为原始图像的宽度,输出图像的宽度为原始图像的高度。
2.MATLAB6.5;
2.查阅资料,熟悉实验中涉及的有关MATLAB函数;
3.利用课余时间,采用MATLAB底层函数编程实现实验内容
(二)中的图像平移、图像转置等几何变换。
1.简述试验的目的和试验原理;
2.叙述各段程序功能,改变有关函数的参数,分析比较实验结果;
3.打印出所编写的实验程序。
4.写出本实验的心得体会及意见。
实验三图像形态学处理
1.利用MATLAB研究二值形态学图像处理常用算法;
2.掌握MATLAB形态学图像处理基本操作函数的使用方法;
3.了了解形态学的基本使用。
1.膨胀和腐蚀(DilationandErosion)
(1)对简单二值图像进行膨胀和腐蚀
BW=zeros(9,10);
BW(4:
6,4:
7)=1;
BW
SE=strel('
square'
3)
BW1=imdilate(BW,SE)
BW2=imerode(BW,SE)
figure
(1),
subplot(1,2,1),imshow(BW,'
notruesize'
),title('
OriginalImage'
subplot(1,2,2),imshow(BW1,'
DilatedImage'
figure
(2),
subplot(1,2,2),imshow(BW2,'
ErodedImage'
(2)对文本图像进行膨胀和腐蚀
text.tif'
SE=[0,1,0;
1,1,1;
0,1,0]
BW1=imdilate(I,SE);
BW2=imerode(I,SE);
subplot(1,2,1),imshow(I,'
),title('
2.开、闭运算(OpenandClose)
nodules1.tif'
bw=~im2bw(I,graythresh(I));
se=strel('
disk'
5);
bw2=imopen(bw,se);
subplot(1,2,1),imshow(bw),title('
ThresholdedImage'
subplot(1,2,2),imshow(bw2),title('
Afteropening'
bw3=imclose(bw,se);
figure;
subplot(1,2,1),imshow(bw,'
truesize'
subplot(1,2,2),imshow(bw3,'
AfterClosing'
❶改变结构元素形状、大小,重做上述实验,比较实验结果,分析结构元素对运算的影响;
❷对图像'
circlesm.tif'
进行开、闭运算,仔细观察两种运算的结果,总结二者的作用。
3.击中/击不中变换(hit-and-missoperation)
bw=[000000
001100
011110
001000]
interval=[0-1-1
11-1
010]
bw2=bwhitmiss(bw,interval)
subplot(1,3,1),imshow(bw,'
subplot(1,3,2),imshow(interval,'
IntervalImage'
subplot(1,3,3),imshow(bw2,'
afterhit/misstransformation'
4.细化和骨架抽取
BW=~imread('
logo.tif'
BW1=bwmorph(BW,'
thin'
Inf);
BW2=bwmorph(BW,'
skel'
subplot(1,3,1),imshow(BW),title('
subplot(1,3,2),imshow(BW1),title('
ThinnedImage'
subplot(1,3,3),imshow(BW2),title('
Imageskeleton'
%查看bwmorph函数使用说明
helpbwmorph
(二)用MATLAB二值数学形态学函数编程提取’rice.tif’图像中的物体边界。
2.查阅资料,熟悉实验中涉及的有关函数。
3.利用课余时间,采用MATLAB函数编程实现实验内容
(二)。
实验四图像分割和边缘检测
1.利用MATLAB研究图像分割和边缘检测的常用算法原理;
2.掌握MATLAB图像域值分割和边缘检测函数的使用方法;
3.了解边缘检测的算法和用途,比较Sobel、Prewitt、Canny等算子边缘检测的差异。
1.图像阈值分割
clearall,closeall;
rice.tif'
figure
(1),imshow(I)
figure
(2);
imhist(I)
T=120/255;
Ibw1=im2bw(I,T);
%选择阈值T=120/255对图像二值化;
figure(3);
subplot(1,2,1),imshow(Ibw1);
T=graythresh(I);
%采用Otsu方法计算最优阈值T对图像二值化;
L=uint8(T*255)
Ibw2=im2bw(I,T);
subplot(1,2,2),imshow(Ibw2);
helpim2bw;
helpgraythresh;
(令T取不同值,重做上述试验,观察试验结果)
2.边缘检测
BW1=edge(I,'
sobel'
BW2=edge(I,'
canny'