图像增强频域增强法课程设计.docx
- 文档编号:13144407
- 上传时间:2023-06-11
- 格式:DOCX
- 页数:22
- 大小:1.83MB
图像增强频域增强法课程设计.docx
《图像增强频域增强法课程设计.docx》由会员分享,可在线阅读,更多相关《图像增强频域增强法课程设计.docx(22页珍藏版)》请在冰点文库上搜索。
图像增强频域增强法课程设计
《MATLAB实践》
课程设计
题目:
图像增强——频域增强法
指导教师:
王秋云
姓名
学号
刘利刚
200981010118
二○○六年6月29日
目录
1、设计目的2
2、题目分析2
3、总体设计3
4、具体设计4
4.1图像的读取和保存4
4.1.1利用“读入图像”按钮实现图片的读取4
4.1.2图像保存6
4.2程序的还原与撤销7
4.3图像的截取7
4.4加入各种噪声,并通过几种滤波算法实现去噪。
8
4.4.1加入噪声8
4.5滤除噪声11
4.6.1图像翻转15
4.6.2图像旋转16
5、结果分析17
6、心得体会18
参考书目19
摘要:
图像增强是指按特定的需要突出一幅图像中的某些信息,同时消弱或去除某些不需要的信息。
其主要目的是处理后的图像对某些特定的应用比原来的图像更加有效。
图像增强的方法分为空域法和频域法两类,空域法主要是对图像中的各个像素点进行操作;而频域法是在图像的某个变换域内,对图像进行操作,修改变换后的系数,例如傅立叶变换,DCT变换等的系数,然后再进行反变换得到处理后的图像。
关键字:
高斯噪声,巴特沃斯滤波,理想低通滤波,梯形低通滤波
1、设计目的
综合运用MATLAB工具箱实现图像处理的GUI程序设计,利用MATLAB图像处理工具箱,实现图像增强—频域增强。
2、题目分析
利用matlab的GUI程序设计一个简单实用的图像处理程序,该程序应具备图像处理的常用功能,以满足用户的使用。
现设计程序有以下基本功能:
1)图像的读取和保存。
2)设计图形用户界面,让用户能够对图像进行任意角度的翻转。
3)设计图形用户界面,让用户能够用鼠标截取图像感兴趣区域,并显示和保存该选择区域。
4)设计图形用户界面,让用户能够对图像添加任意参数的各种噪声,如椒盐噪声、高斯噪声、乘性噪声等。
5)设计图形用户界面,让用户能够对图像实现中值滤波、线性滤波、自适应滤波等操作。
6)设计图形用户界面,让用户能够对噪声图像实现理想低频滤波、巴特沃斯滤波、指数滤波、梯形低通滤波。
7)额外功能。
3、总体设计
图一
软件的总体设计界面布局如上图所示,主要分为两个部分:
显示区域与操作区域。
显示区域:
显示载入原图,以及通过处理后的图像。
操作区域:
通过功能键实现对图像的各种处理。
左部的一系列功能按键如“读入图像”、“存储图像”、“还原”、“撤销”、“截图”。
右部的一系列功能按键如“巴特沃斯滤波”、“理想低通滤波”、“梯形低通滤波”、“指数滤波”、“退出”。
界面正中部分为图片显示部分,界面中下方为一系列功能选择组。
设计完成后运行的软件界面如下:
图二
与图一相比,运行后的界面更为简洁。
4、具体设计
现介绍各个模块的功能与实现。
4.1图像的读取和保存
4.1.1利用“读入图像”按钮实现图片的读取
利用matlab中“uigetfile”、“imread”“imshow”等函数实现图像文件的读取与显示:
functionopenfile_Callback(hObject,eventdata,handles)
%hObjecthandletoopenfile(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
[filename,pathname]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'载入图像');
ifisequal(filename,0)|isequal(pathname,0)
errordlg('没有选中文件','出错');
return;
else
file=[pathname,filename];
globalS%设置一个全局变量S,保存初始图像路径,以便之后的还原操作
S=file;
x=imread(file);
set(handles.axes1,'HandleVisibility','ON');
axes(handles.axes1);
imshow(x);
set(handles.axes1,'HandleVisibility','OFF');
axes(handles.axes2);
imshow(x);
handles.img=x;
guidata(hObject,handles);
end
程序关键部分:
通过[filename,pathname]=uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'载入图像')选择相应路径打开的图像;通过file=[pathname,filename];x=imread(file);读取选中的图像;最后,通过imshow(x)在显示区域上显示图像。
4.1.2图像保存
利用“uiputfile”、“imwrite”函数实现图像文件的保存。
functionsave_Callback(hObject,eventdata,handles)
%hObjecthandletosave(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
[sfilename,sfilepath]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'保存图像文件','untitled.jpg');
if~isequal([sfilename,sfilepath],[0,0])
sfilefullname=[sfilepath,sfilename];
imwrite(handles.img,sfilefullname);
else
msgbox('你按了取消键','保存失败');
end
程序关键部分:
通[sfilename,sfilepath]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'保存图像文件','untitled.jpg')选择图像文件保存的路径与格式;然后,通过sfilefullname=[sfilepath,sfilename];
imwrite(handles.img,sfilefullname);实现对图像的保存。
4.2程序的还原与撤销
通过一个全局变量保存原始图像路径,在需要还原至原始图像时,重新读取该全局变量即可。
实现程序段如下:
functionpushbutton_huanyuan_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton_huanyuan(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalS%还原
axes(handles.axes2);
y=imread(S);
f=imshow(y);
handles.img=y;
guidata(hObject,handles);
撤销是指撤销上一步的操作,通过另设一个全局变量T保存是上一次操作后的图像。
实现程序段如下:
functionpushbutton_chexiao_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton3(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
axes(handles.axes2);%撤销
globalT
imshow(T);
handles.img=T;
guidata(hObject,handles);
4.3图像的截取
通过imcrop(x)函数来实现对图片某一区域的截取,截取的图片在右框中显示,并保存在指定的路径。
实现程序段如下:
functionpushbutton_jietu_Callback(hObject,eventdata,handles)
%hObjecthandletopushbutton_jietu(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
axes(handles.axes2);
T=getimage;
x=imcrop(handles.img);%截图
imshow(x);
handles.img=x;
guidata(hObject,handles);
4.4加入各种噪声,并通过几种滤波算法实现去噪。
4.4.1加入噪声
通过imnoise(I,type,parameters)来加入各种噪声。
<1>加入椒盐噪声
<2>加入高斯噪声:
<3>加入乘性噪声:
实现程序段如下:
functionuipanel1_SelectionChangeFcn(hObject,eventdata,handles)
%hObjecthandletotheselectedobjectinuipanel1
%eventdatastructurewiththefollowingfields(seeUIBUTTONGROUP)
%EventName:
string'SelectionChanged'(readonly)
%OldValue:
handleofthepreviouslyselectedobjectoremptyifnonewasselected
%NewValue:
handleofthecurrentlyselectedobject
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
str=get(hObject,'string');
axes(handles.axes2);
switchstr
case'椒盐噪声'
T=getimage;
prompt={'输入椒盐噪声参数:
'};
defans={'0.02'};
p=inputdlg(prompt,'input',1,defans);
p1=str2num(p{1});
f=imnoise(handles.img,'salt&pepper',p1);
imshow(f);
handles.img=f;
guidata(hObject,handles);
case'高斯噪声'
T=getimage;
prompt={'输入高斯噪声参数1:
','输入高斯噪声参数2'};
defans={'0','0.02'};
p=inputdlg(prompt,'input',1,defans);
p1=str2num(p{1});
p2=str2num(p{2});
f=imnoise(handles.img,'gaussian',p1,p2);
imshow(f);
handles.img=f;
guidata(hObject,handles);
case'乘性噪声'
T=getimage;
prompt={'输入乘性噪声参数1:
'};
defans={'0.02'};
p=inputdlg(prompt,'input',1,defans);
p1=str2num(p{1});
f=imnoise(handles.img,'speckle',p1);
imshow(f);
handles.img=f;
guidata(hObject,handles);
End
4.5滤除噪声
滤波前
中值滤波后
线性滤波后
实现程序段如下:
functionuipanel3_SelectionChangeFcn(hObject,eventdata,handles)
%hObjecthandletotheselectedobjectinuipanel3
%eventdatastructurewiththefollowingfields(seeUIBUTTONGROUP)
%EventName:
string'SelectionChanged'(readonly)
%OldValue:
handleofthepreviouslyselectedobjectoremptyifnonewasselected
%NewValue:
handleofthecurrentlyselectedobject
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
str=get(hObject,'string');
axes(handles.axes2);
switchstr
case'中值滤波'
T=getimage;
k=medfilt2(handles.img);
imshow(k);
handles.img=k;
guidata(hObject,handles);
case'线性滤波'
T=getimage;
h=[111;111;111];
H=h/9;
i=double(handles.img);
k=convn(i,h);
imshow(k,[]);
handles.img=k;
guidata(hObject,handles);
case'自适应滤波'
T=getimage;
k=wiener2(handles.img,[5,5]);
imshow(k);
handles.img=k;
guidata(hObject,handles);
end
理想低通滤波器滤波后
巴特沃斯滤波器滤波后
实现程序如下:
%---Executesonbuttonpressinpushbutton14.
functionpushbutton_bsiwote(hObject,eventdata,handles)
%hObjecthandletopushbutton14(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
axes(handles.axes2);
y1=handles.img;
f=double(y1);%数据类型转换,matlab不支持图像的无符号整型的计算
g=fft2(f);%傅里叶变换
g=fftshift(g);%转换数据矩阵
[M,N]=size(g);
nn=2;%巴特沃斯低通滤波器
d0=50;%截止频率50
m=fix(M/2);n=fix(N/2);
fori=1:
M
forj=1:
N
d=sqrt((i-m)^2+(j-n)^2);
h=1/(1+0.414*(d/d0)^(2*nn));%计算低通滤波器传递函数
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
y2=ifft2(result);
y3=uint8(real(y2));
imshow(y3);%显示处理后的图像
%---Executesonbuttonpressinpushbutton15.
functionpushbutton_lixiangditong(hObject,eventdata,handles)
%hObjecthandletopushbutton15(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
axes(handles.axes2);
x=(handles.img);
f=double(x);%数据类型转换
k=fft2(f);%傅里叶变换
g=fftshift(k);%转换数据矩阵
[M,N]=size(g);
nn=2;
d0=25;%截止频率25
m=fix(M/2);n=fix(N/2);
fori=1:
M
forj=1:
N
d=sqrt((i-m)^2+(j-n)^2);%计算理想低通滤波器传递函数
ifd<=d0
h=0;
elseh=1;
end
result(i,j)=h*g(i,j);
end
end
result=ifftshift(result);
y2=ifft2(result);
y3=uint8(real(y2));
imshow(y3);%显示滤波处理后的图像
4.6图像变形
4.6.1图像翻转
左右翻转:
上下翻转
实现程序如下:
functionuipanel7_SelectionChangeFcn(hObject,eventdata,handles)
%hObjecthandletotheselectedobjectinuipanel7
%eventdatastructurewiththefollowingfields(seeUIBUTTONGROUP)
%EventName:
string'SelectionChanged'(readonly)
%OldValue:
handleofthepreviouslyselectedobjectoremptyifnonewasselected
%NewValue:
handleofthecurrentlyselectedobject
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
str=get(hObject,'string');
axes(handles.axes2);
globalT
switchstr
case'左右翻转'
T=handles.img;
f=fliplr(handles.img);
imshow(f);
handles.img=f;
guidata(hObject,handles);
case'上下翻转'
T=handles.img;
f=flipud(handles.img);
imshow(f);
handles.img=f;
guidata(hObject,handles);
end
程序关键部分:
通过f=fliplr(handles.img);f=flipud(handles.img);分别实现左右镜像翻转与上下镜像翻转。
4.6.2图像旋转
实现图像的逆时针旋转任意角度。
实现程序段如下:
functionpushbutton15_Callback(hObject,eventdata,handles)
%图像爱那个旋转
%hObjecthandletopushbutton3(seeGCBO)
%eventdatareserved-tobedefinedinafutureversionofMATLAB
%handlesstructurewithhandlesanduserdata(seeGUIDATA)
globalT
axes(handles.axes2);
T=getimage;
prompt={'旋转角度:
'};
defans={'0'};
p=inputdlg(prompt,'input',1,defans);
p1=str2num(p{1});
f=imrotate(handles.img,p1,'bilinear','crop');
imshow(f);
handles.img=f;
guidata(hObject,handles);
关键部分:
通过p=inputdlg(prompt,'input',1,defans);p1=str2num(p{1});来输入旋转参数。
通过函数f=imrotate(handles.img,p1,'bilinear','crop');实现翻转。
5、结果分析
软件测试基本成功,课题所要求的功能均能较好实现。
但一些功能只支持灰度图像的处理。
其中值得一提的是在滤波处理中的低通滤波与高通滤波的效果。
由于一般图像中含有较多的低频信息成分高频成分较少,通过低通滤波后,噪声以及高频成分被滤除,图像虽有少量失真,略显模糊,但尚可辨识。
但若是通过高通滤波后,大量的有效低频信息被滤除,图像严重失真,不可辨识。
椒盐噪声的幅值近似相等,但发生的位置是随机的;
高斯噪声存在于每一点像素,但幅值是随机分布的。
中值滤波的原理是取合理的邻近像素值来替代噪声点,所以只适合于椒盐噪声的去除,不适合高斯噪声的去除。
理想低通滤波器的平滑作用非常明显,但由于变换有一个陡峭的波形,它的反变换h(x,y)有强烈的振铃特性,使滤波后图像产生模糊效果。
因此这种理想低通滤波实用中不能采用。
6、心得体会
通过为期两周的matlab课程设计实践,使我对matlab的使用有了进一步的了解和熟悉。
当我第一次拿到此次的课题时,感到有些无所适从。
虽然,曾经学习过matlab的课
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- 图像 增强 课程设计