基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx

上传人:b****5 文档编号:16284237 上传时间:2022-11-22 格式:DOCX 页数:57 大小:9.65MB
下载 相关 举报
基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx_第1页
第1页 / 共57页
基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx_第2页
第2页 / 共57页
基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx_第3页
第3页 / 共57页
基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx_第4页
第4页 / 共57页
基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx_第5页
第5页 / 共57页
点击查看更多>>
下载资源
资源描述

基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx

《基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx》由会员分享,可在线阅读,更多相关《基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx(57页珍藏版)》请在冰豆网上搜索。

基于MATLAB语言的数字图像处理实验GUIWord格式文档下载.docx

界面正中部分为图片显示部分。

设计完成后运行的软件界面如下:

4.模块设计

以下介绍各个功能模块的功能与实现

4.1图像的读取、保存和程序退出

通过MenuEditor

创建如下菜单,通过以下菜单来实现“载入图像”、“保存图像”、“退出”的功能。

4.1.1载入图像

利用MATLAB中“uigetfile”、“imread”、“imshow”实现图像文件的读取与显示。

functionInput_Callback(hObject,eventdata,handles)

[filename,pathname]=uigetfile({'

*.jpg'

;

'

*.bmp'

*.tif'

},'

选择图片'

);

str=[pathnamefilename];

globalS%设计一个全局变量S,保存初始图像路径,以便之后的还原操作

S=str;

A=imread(str);

set(handles.axes1,'

HandleVisibility'

'

ON'

axes(handles.axes1);

imshow(A);

OFF'

axes(handles.axes2);

cla(handles.axes2);

handles.img=A;

guidata(hObject,handles);

end

程序关键部分:

通过[filename,pathname]=uigetfile({'

)选择相应路径打开的图像;

通过str=[pathnamefilename];

A=imread(str);

读取选中的图像;

最后,通过imshow(A)在显示区域上显示图像。

4.1.2保存图像

利用“uiputfile”、“imwrite”函数实现图像文件的保存。

functionSave_Callback(hObject,eventdata,handles)

[sfilename,sfilepath]=uiputfile({'

*.*'

保存图像文件'

untitled.jpg'

if~isequal([sfilename,sfilepath],[0,0])

sfilefullname=[sfilepath,sfilename];

imwrite(handles.img,sfilefullname);

else

msgbox('

取消保存'

保存失败'

通过[sfilename,sfilepath]=uiputfile({'

)选择图像文件保存的路径与格式;

然后,通过sfilefullname=[sfilepath,sfilename];

imwrite(handles.img,sfilefullname);

实现对图像的保存。

4.1.3退出程序

functionExit_Callback(hObject,eventdata,handles)

clc;

closeall;

close(gcf);

clear;

4.2图像转化为灰度图像

由于在MATLAB中较多的图像处理函数支持对灰度图像进行处理,故对图像进行灰度转化十分必要。

可利用rgb2gray(X)函数对其他图像进行灰度图像的转化。

实现程序段如下:

functionto_gray_Callback(hObject,eventdata,handles)

globalT%设计一个全局变量T,保存初始图像路径,以便之后的撤销操作

T=handles.img;

img=handles.img;

ifnumel(size(img))>

2

C=rgb2gray(img);

C=img;

imshow(C);

handles.img=C;

4.3底片处理(反色)

将图像变为底片并显示。

functionnegative_Callback(hObject,eventdata,handles)

globalT

I=imcomplement(handles.img);

imshow(I);

handles.img=I;

4.4截图

通过imcrop(x)函数来实现对图片某一区域的截取,截取的图片在右框中显示。

结合“保存为…”,可把截图处理后的图片保存在指定路径。

functionCut_Callback(hObject,eventdata,handles)

x=imcrop(handles.img);

%截图

imshow(x);

handles.img=x;

4.5亮度和对比度度调节

4.5.1亮度调节

functionlight_Callback(hObject,eventdata,handles)

prompt={'

调整倍数([0,1]:

明[1,~):

暗)'

};

defans={'

1'

p=inputdlg(prompt,'

input'

1,defans);

p1=str2num(p{1});

y=imadjust(handles.img,[],[],p1);

%亮度调节

imshow(y);

handles.img=y;

4.5.2对比度调节

functioncontrast_Callback(hObject,eventdata,handles)

str=get(handles.contrast1,'

value'

请输入参数:

switchstr

case1

f=immultiply(handles.img,p1);

imshow(f);

handles.img=f;

guidata(hObject,handles);

case2

f=imdivide(handles.img,p1);

4.6图像的翻转与旋转

4.6.1翻转

functionturn_Callback(hObject,eventdata,handles)

str=get(handles.fanzhuan,'

I=handles.img;

ifnumel(size(I))>

switchstr

case1

T=handles.img;

b=I(:

:

1);

c=I(:

2);

d=I(:

3);

I1(:

1)=fliplr(b);

2)=fliplr(c);

3)=fliplr(d);

1)=flipud(b);

2)=flipud(c);

3)=flipud(d);

imshow(I1);

handles.img=I1;

f=fliplr(I);

f=flipud(I);

imshow(f);

handles.img=f;

通过f=fliplr(handles.img);

f=flipud(handles.img);

分别实现左右镜像翻转与上下镜像翻转。

4.6.2旋转

functionrotate_Callback(hObject,eventdata,handles)

str=get(handles.clockwise,'

请输入旋转角度:

0'

p1=-p1;

p1=p1;

f=imrotate(handles.img,p1,'

bilinear'

crop'

通过p=inputdlg(prompt,'

p1=str2num(p{1})来输入旋转参数。

通过函数f=imrotate(handles.img,p1,'

实现翻转。

4.7添加噪声

通过imnoise(I,type,parameters)来加入各种噪声。

functionADDNoise_Callback(hObject,eventdata,handles)

str=get(handles.Noise1,'

case1

T=handles.img;

prompt={'

输入椒盐噪声参数1:

defans={'

0.02'

p=inputdlg(prompt,'

p1=str2num(p{1});

f=imnoise(handles.img,'

salt&

pepper'

p1);

imshow(f);

handles.img=f;

guidata(hObject,handles);

case2

输入高斯噪声1:

输入高斯噪声2'

p2=str2num(p{2});

gaussian'

p1,p2);

case3

输入乘性噪声1:

speckle'

4.8平滑和锐化

4.8.1平滑滤波器

functionsmooth_Callback(hObject,eventdata,handles)

str=get(handles.pinghua,'

prompt={'

请输入模版维度:

defans={'

3'

p=inputdlg(prompt,'

p1=str2num(p{1});

h1=fspecial('

average'

[p1p1]);

I=imfilter(handles.img,h1);

imshow(I);

handles.img=I;

ifnumel(size(handles.img))>

A=handles.img;

R=A(:

G=A(:

B=A(:

GP(:

1)=medfilt2(R,[p1p1]);

2)=medfilt2(G,[p1p1]);

3)=medfilt2(B,[p1p1]);

imshow(GP);

handles.img=GP;

else

I=medfilt2(A,[p1p1]);

end

4.8.2锐化滤波器

functionsharpen_Callback(hObject,eventdata,handles)

str=get(handles.ruihua,'

g=handles.img;

h=fspecial('

sobel'

prewitt'

case3

laplacian'

ifnumel(size(g))>

R=g(:

G=g(:

B=g(:

R1=imfilter(R,h);

1)=imadd(R,R1);

G1=imfilter(G,h);

2)=imadd(G,G1);

B1=imfilter(B,h);

3)=imadd(B,B1);

g1=g;

g2=imfilter(g1,h);

g3=imadd(g2,g1);

imshow(g3);

handles.img=g3;

4.9直方图均衡化处理

4.9.1灰度图像

functiongray_histogram_Callback(hObject,eventdata,handles)

B=histeq(C);

imshow(B);

handles.img=B;

4.9.2RGB图像

functionrgb_histogram_Callback(hObject,eventdata,handles)

RGB=handles.img;

R=RGB(:

G=RGB(:

B=RGB(:

G1(:

1)=histeq(R);

2)=histeq(G);

3)=histeq(B);

imshow(G1);

handles.img=G1;

4.10图像的腐蚀和膨胀

4.10.1腐蚀

functioncorrode_Callback(hObject,eventdata,handles)

temp={'

腐蚀圆盘半径:

p=inputdlg(temp,'

请输入'

se=strel('

disk'

p1,0);

I1=imerode(handles.img,se);

4.10.2膨胀

functiondilate_Callback(hObject,eventdata,handles)

膨胀结构长度:

line'

I1=imdilate(handles.img,se);

4.11边缘检测

functionedge_Callback(hObject,eventdata,handles)

str=get(handles.edge2,'

ifnumel(size(handles.img))>

I=handles.img;

img=I;

[xyz]=size(img);

ifz==1

rslt=edge(img,'

Roberts'

elseifz==3

img1=rgb2ycbcr(img);

dx1=edge(img1(:

1),'

dx1=(dx1*255);

img2(:

1)=dx1;

2)=img1(:

3)=img1(:

rslt=ycbcr2rgb(uint8(img2));

imshow(rslt);

handles.img=rslt;

case2

Prewitt'

handles.img

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > PPT模板 > 卡通动漫

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1