




版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、%系统自动生成的创建对话框的代码function varargout = myproject(varargin)% MYPROJECT M-file for myproject.fig% MYPROJECT, by itself, creates a new MYPROJECT or raises the existing% singleton*.% H = MYPROJECT returns the handle to a new MYPROJECT or the handle to% the existing singleton*.% MYPROJECT('CALLBACK'
2、;,hObject,eventData,handles,.) calls the local% function named CALLBACK in MYPROJECT.M with the given input arguments.% MYPROJECT('Property','Value',.) creates a new MYPROJECT or raises the% existing singleton*. Starting from the left, property value pairs are% applied to the GUI bef
3、ore myproject_OpeningFcn gets called. An% unrecognized property name or invalid value makes property application% stop. All inputs are passed to myproject_OpeningFcn via varargin.% *See GUI Options on GUIDE's Tools menu. Choose "GUI allows only one% instance to run (singleton)".% See a
4、lso: GUIDE, GUIDATA, GUIHANDLES% Edit the above text to modify the response to help myproject% Last Modified by GUIDE v2.5 07-Jun-2008 11:33:02% Begin initialization code - DO NOT EDITgui_Singleton = 1;gui_State = struct('gui_Name', mfilename, . 'gui_Singleton', gui_Singleton, . '
5、;gui_OpeningFcn', myproject_OpeningFcn, . 'gui_OutputFcn', myproject_OutputFcn, . 'gui_LayoutFcn', , . 'gui_Callback', );if nargin && ischar(varargin1) gui_State.gui_Callback = str2func(varargin1);endif nargout varargout1:nargout = gui_mainfcn(gui_State, varargin:
6、);else gui_mainfcn(gui_State, varargin:);end% End initialization code - DO NOT EDIT% - Executes just before myproject is made visible.function myproject_OpeningFcn(hObject, eventdata, handles, varargin)% This function has no output args, see OutputFcn.% hObject handle to figure% eventdata reserved -
7、 to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% varargin command line arguments to myproject (see VARARGIN)% Choose default command line output for myprojecthandles.output = hObject;% Update handles structureguidata(hObject, handles);% UIWAIT
8、 makes myproject wait for user response (see UIRESUME)% uiwait(handles.figure1);% - Outputs from this function are returned to the command line.function varargout = myproject_OutputFcn(hObject, eventdata, handles) % varargout cell array for returning output args (see VARARGOUT);% hObject handle to f
9、igure% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)% Get default command line output from handles structurevarargout1 = handles.output;%以下为另存为按钮的回调函数,功能为存储图像处理后的图像到用户选择的磁盘空间中。% - Executes on button press in lingcunwei.fu
10、nction lingcunwei_Callback(hObject, eventdata, handles) %另存为按钮的回调函数global ImagenUmbral %定义全局变量if isempty(ImagenUmbral)=1,msgbox('Doesn''t exist an image');return,end %如果ImagenUmbral不包含图像,则弹出对话框并显示'Doesn''t exist an image'filename,pathname=uiputfile('*.jpg',
11、9;*.tif','*.gif','*.bmp','*.png', . '*.hdf','*.pcx','*.xwd','*.ico','*.cur','*.ras', . '*.pdm','*.pgm','*.ppm','Save file name'); %显示保存文件的对话框if isequal(filename,0) | isequal(pathname,0) errord
12、lg('Saving canceled','Threshold GUI'); error('Saving canceled')else %如果不存在该文件,或者不存在保存路径,则显示错误信息 try imwrite(ImagenUmbral, pathname,filename); %保存文件 end %tryend %if% hObject handle to lingcunwei (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% hand
13、les structure with handles and user data (see GUIDATA)%打印按钮的回调函数% - Executes on button press in dayinshuchu.function dayinshuchu_Callback(hObject, eventdata, handles) %打印按钮的回调函数printdlg %显示打印对话框% hObject handle to dayinshuchu (see GCBO)% eventdata reserved - to be defined in a future version of MATL
14、AB% handles structure with handles and user data (see GUIDATA)%复制到剪切板的回调函数,其功能为将处理后的图像存储到剪切板,以备处理图像处理后的图像之用。% - Executes on button press in fuzhidaojianqieban.function fuzhidaojianqieban_Callback(hObject, eventdata, handles)%复制到剪切板按钮的回调函数global ImagenUmbral %处理后的图像global J %处理前的图像J=ImagenUmbral %将处理
15、后的图像赋予处理前的图像% hObject handle to fuzhidaojianqieban (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%几何变换的回调函数,它包含三个基本的几何变换,分别为水平变换,垂直变换,对角变换。均使用了将像素灰度值进行对换的方式。% - Executes on button press in jihebianhuan.function
16、 jihebianhuan_Callback(hObject, eventdata, handles)global ImagenUmbral %定义一个全局变量ImagenUmbralglobal J %使用全局变量Jselection = questdlg('请选择几何变换','选择几何变换','水平镜像','垂直镜像','对角镜像','default') if strcmp(selection,'水平镜像') %如果选择“水平镜像” M,N=size(J) %测量图像尺寸参数 I
17、=J %将J赋给I for i=1:M %从第一行到最后一行 for j=1:N/2 %对每一行的第一个像素到中间的一个像素 t=I(i,j);I(i,j)=I(i,N-j+1);I(i,N-j+1)=t; %交换这一行第一个像素和最后一个像素的灰度值,交换第二个和倒数第二个灰度值,以此类推,直到中间的像素。 end %end for end %end for subplot(224); %分割绘图窗口为两行两列,将句柄移到第四个位置 imshow(I) %显示图像 ImagenUmbral=I; %将图像赋予全局变量ImagenUmbralelse if strcmp(selection,&
18、#39;垂直镜像') %如果选择“垂直镜像” M,N=size(J) %测量图像尺寸参数 I=J %将J赋给I for j=1:N %从第一列到最后一列 for i=1:M/2 %对每一列的第一个像素到中间的一个像素 t=I(i,j);I(i,j)=I(M-i+1,j);I(M-i+1,j)=t; %交换这一列第一个像素和最后一个像素的灰度值,交换第二个和倒数第二个灰度值,以此类推,直到中间的像素。 end %end for end %end for subplot(224); %分割绘图窗口为两行两列,将句柄移到第四个位置 imshow(I) %显示图像 ImagenUmbral=I
19、; %将图像赋予全局变量ImagenUmbral else if strcmp(selection,'对角镜像') %如果选择“垂直镜像” I=J %将J赋给I M,N=size(I) %测量图像尺寸参数 for i=1:M %从第一行到最后一行 for j=1:N/2 %对每一行的第一个像素到中间的一个像素 t=I(i,j);I(i,j)=I(M-i+1,N-j+1);I(M-i+1,N-j+1)=t;%交换第i行的第一个像素和M-i+1行的最后一个像素的灰度值,以此类推,直到中间的像素。 end %end for end %end for subplot(224); %分割
20、绘图窗口为两行两列,将句柄移到第四个位置 imshow(I) %显示图像 ImagenUmbral=I; %将图像赋予全局变量ImagenUmbral end %end of else if strcmp(selection,'对角镜像') end %end of else if strcmp(selection,'垂直镜像') end %end of if strcmp(selection,'水平镜像') % hObject handle to jihebianhuan (see GCBO)% eventdata reserved - to b
21、e defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%灰度反转按钮的回调函数,灰度反转采用公式T=L-1-S,其中S为存储原始图像的灰度值的矩阵,T为存储反转后图像灰度值的矩阵。% - Executes on button press in huidufanzhuan.function huidufanzhuan_Callback(hObject, eventdata, handles)%灰度反转按钮的回调函数global ImagenUmbral
22、%定义一个全局变量ImagenUmbral,将灰度反转后的图像存入ImagenUmbral中global J %使用全局变量JA=double(J) %将图像J的各点像素值存入矩阵A中A=255-A %用255减去A的各点像素值,再重新存入A中A=uint8(A) %将A的每个元素转换成整数 subplot(224) %分割绘图窗口为两行两列,将句柄移到第四个位置imshow(A) %显示图像AImagenUmbral=A %将A赋给全局变量ImagenUmbral% hObject handle to huidufanzhuan (see GCBO)% eventdata reserved
23、- to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%直方图均衡化按钮的回调函数,直方图均衡化的处理目的是使图像变得清晰,明快。% - Executes on button press in zhifangtujunhenghua.function zhifangtujunhenghua_Callback(hObject, eventdata, handles)%直方图均衡化按钮的回调函数global ImagenUmbral %定义一个
24、全局变量ImagenUmbral,将直方图均衡化后的图像存入ImagenUmbral中global J %使用全局变量Jsubplot(2,2,4); %分割绘图窗口为两行两列,将当前句柄移到第四个位置%W = histeq(J); %Matlab自带直方图均衡化函数PS=J %令PS为待处理的图像m,n=size(PS); %测量图像尺寸参数GP=zeros(1,256); %预创建存放灰度出现概率的向量for k=0:255 %对每一个像素值 GP(k+1)=length(find(PS=k)/(m*n);%计算每级灰度出现的概率,将其存入GP中相应位置end %end forS1=zer
25、os(1,256); %分配一个256维数组for i=1:256 %对每一个像素值 for j=1:i %对从1到这个像素值的所有像素的 S1(i)=GP(j)+S1(i); %计算Sk,Sk为一个映射,将对从1到这个像素值的所有像素的概率相加 end %end forend %end forS2=round(S1*256)+0.5); %将Sk归到相近级的灰度PA=PS; %定义一个与PS一样大小的矩阵for i=0:255 %对每一个像素值 PA(find(PS=i)=S2(i+1); %将各个像素归一化后的灰度值赋给这个像素end %end forimshow(PA) %显示均衡化后的
26、图像 ImagenUmbral=PA; %将均衡化图像赋给ImagenUmbral% hObject handle to zhifangtujunhenghua (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%直方图统计按钮的回调函数,此按钮可以统计处理前后的图像的直方图。% - Executes on button press in zhifangtutongji.fu
27、nction zhifangtutongji_Callback(hObject, eventdata, handles)%直方图统计按钮的回调函数global ImagenUmbral %定义一个全局变量ImagenUmbralglobal J %使用全局变量Jfigure %弹出绘图窗口subplot(211) %分割绘图窗口为两行一列,将当前句柄移到第一个区域m,n=size(J); %测量图像尺寸参数GP=zeros(1,256); %预创建存放灰度出现概率的向量for k=0:255 %对每一个像素 GP(k+1)=length(find(J=k)/(m*n); %计算每级灰度出现的概
28、率,将其存入GP中相应位置end %end forbar(0:255,GP,'b') %绘制直方图title('原图像直方图') %标题为'原图像直方图'subplot(212) %分割绘图窗口为两行一列,将当前句柄移到第二个区域K=ImagenUmbral %将全局变量ImagenUmbral赋予K m,n=size(K); %测量图像尺寸参数GP=zeros(1,256); %预创建存放灰度出现概率的向量for k=0:255 %对每一个像素 GP(k+1)=length(find(K=k)/(m*n);%计算每级灰度出现的概率,将其存入GP
29、中相应位置end %end for bar(0:255,GP,'b') %绘制直方图title('处理后图像直方图') %标题为'处理后图像直方图'% hObject handle to zhifangtutongji (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user data (see GUIDATA)%图像复原按钮的回调函数,采用中值滤波和均值滤波两种方法,其
30、中,中值滤波是将图像中一点的值用该点的一个邻域中各点值的中值代替,以达到滤波的效果。均值滤波与之不同的是将图像中一点的值用该点的一个邻域中各点值的均值代替。% - Executes on button press in tuxiangfuyuan.function tuxiangfuyuan_Callback(hObject, eventdata, handles)%图像复原按钮的回调函数global ImagenUmbral %定义一个全局变量ImagenUmbral global J %使用全局变量Jselection = questdlg('请选择图像复原方法','
31、;图像复原方法','中值滤波','均值滤波','default')if strcmp(selection,'中值滤波') %如果选择'中值滤波'A=J %将J赋给A m,n = size(A); %测量图像尺寸参数 B=A; %将A赋给B pixel_block = zeros(1,9); %开辟一个一行九列的数组,均赋于初值0 for i = 2:m-1 %对A中的各个像素点(不包括边界) for j = 2:n-2 pixel_block = reshape(A(i-1:i+1,j-1:j+1),9,1
32、); %采用3*3的窗口,将一个像素点及其周围的8各点,依次存入新开辟的数组pixel_block中 sorted_block = sort(pixel_block); %将数组pixel_block排序block_median = sorted_block(5); %将数组的中值赋予block_medianB(i,j) = block_median; %将block_median赋予B的相应位置的像素值end; %end of for j = 2:n-2 end; %end of for i = 2:m-1B = uint8(B); %将B中所有元素转换成0255之间的整数subplot(2
33、24) %分割绘图窗口为两行两列,将句柄移到第四个位置imshow(B) %显示图像BImagenUmbral=B %将B赋给全局变量ImagenUmbralelse if strcmp(selection,'均值滤波')%如果选择'均值滤波'A=J %将J赋给A m,n = size(A); %m为A的行数,n为A的列数 B=A; %将A赋给B pixel_block = zeros(1,9); %开辟一个一行九列的数组,均赋于初值0 for i = 2:m-1 %对A中的各个像素点(不包括边界) for j = 2:n-1 pixel_block = res
34、hape(A(i-1:i+1,j-1:j+1),32,1);%采用3*3的窗口,将一个像素点及其周围的8各点,一次存入新开辟的数组pixel_block中 mean_block = mean(pixel_block); %求出数组中所有元素的平均值B(i,j) = mean_block; %将mean_block赋予B的相应位置的像素值end; %end of for j = 2:n-2 end; %end of for i = 2:m-1B = uint8(B); %将B中所有元素转换成0255之间的整数subplot(224) %分割绘图窗口为两行两列,将句柄移到第四个位置imshow(B
35、) %显示图像BImagenUmbral=B %将B赋给全局变量ImagenUmbral end %end of else if strcmp(selection,'均值滤波') end %end of if strcmp(selection,'中值滤波') % hObject handle to tuxiangfuyuan (see GCBO)% eventdata reserved - to be defined in a future version of MATLAB% handles structure with handles and user da
36、ta (see GUIDATA)%边缘提取的回调函数,包括三种边缘提取方法,分别为Sobel边缘算子法,Prewitte边缘算子法和Robert边缘算子法,它们都采用了求梯度的方法。% - Executes on button press in bianyuantiqu.function bianyuantiqu_Callback(hObject, eventdata, handles)%边缘提取函数的回调函数global ImagenUmbral %定义一个全局变量ImagenUmbral global J %使用全局变量Jselection = questdlg('请选择边缘算子法
37、','边缘算子法','Sobel边缘算子法','Prewitte边缘算子法','Robert边缘算子法','default')if strcmp(selection,'Sobel边缘算子法')%如果选择了'Sobel边缘算子法' % BW=edge(J,'sobel') %Matlab自带sobel边缘算子法I=J %将J赋予IA=J %令A=J,准备将处理后图像存入A中M,N=size(I); %测量图像尺寸参数I=double(I); %将I中的所有元素变
38、为双精度型for y=2:M-1 %对每一个像素(不包括边界) for x=2:N-1 B(1)=I(x-1,y+1)+I(x,y+1)*2+I(x+1,y+1)-I(x-1,y-1)-I(x,y-1)*2-I(x+1,y-1);%用第一个方向算子对这个像素做卷积 B(2)=I(x-1,y)+I(x-1,y+1)*2+I(x,y+1)-I(x,y-1)-I(x+1,y+1)*2-I(x+1,y); %用第二个方向算子对这个像素做卷积 B(3)=I(x-1,y-1)+I(x-1,y)*2+I(x-1,y+1)-I(x+1,y+1)-I(x+1,y)*2-I(x+1,y+1);%用第三个方向算子对
39、这个像素做卷积 B(4)=I(x-1,y)+I(x-1,y-1)*2+I(x,y+1)-I(x+1,y)-I(x+1,y+1)*2-I(x,y+1); %用第四个方向算子对这个像素做卷积 B(5)=I(x-1,y-1)+I(x,y-1)*2+I(x+1,y+1)-I(x-1,y+1)-I(x,y+1)*2-I(x+1,y+1);%用第五个方向算子对这个像素做卷积 B(6)=I(x,y-1)+I(x+1,y+1)*2+I(x+1,y)-I(x-1,y)-I(x-1,y+1)*2-I(x,y+1); %用第六个方向算子对这个像素做卷积 B(7)=I(x+1,y+1)+I(x+1,y)*2+I(x+
40、1,y+1)-I(x-1,y-1)-I(x-1,y)*2-I(x-1,y+1);%用第七个方向算子对这个像素做卷积 B(8)=I(x+1,y)+I(x+1,y+1)*2+I(x,y+1)-I(x-1,y)-I(x-1,y-1)*2-I(x,y-1); %用第八个方向算子对这个像素做卷积 b=max(B) %将这八个卷积值的最大值赋予b if b>255 b=255 %如果b的值超过255,则重置为255 end %end if A(x,y)=b; %将b作为A中相应点的输出值 end %end forend %end forsubplot(224) %分割绘图窗口为两行两列,将句柄移到第
41、四个位置imshow(A) %显示图像AImagenUmbral=A %将A赋给全局变量ImagenUmbral else if strcmp(selection,'Prewitte边缘算子法')%如果选择了'Prewitte边缘算子法' % BW=edge(J,'prewitt') %Matlab自带prewitte边缘算子法 I=J %将J赋予IA=J %令A=J,准备将处理后图像存入A中M,N=size(I); %将I的各点像素值存入M行N列的矩阵中I=double(I); %将I中的所有元素变为双精度型for y=2:M-1 %对每一个像
42、素(不包括边界) for x=2:N-1 B(1)=I(x-1,y+1)+I(x,y+1)+I(x+1,y+1)-I(x-1,y-1)-I(x,y-1)-I(x+1,y-1);%用第一个方向算子对这个像素做卷积 B(2)=I(x-1,y)+I(x-1,y+1)+I(x,y+1)-I(x,y-1)-I(x+1,y+1)-I(x+1,y); %用第二个方向算子对这个像素做卷积 B(3)=I(x-1,y-1)+I(x-1,y)+I(x-1,y+1)-I(x+1,y+1)-I(x+1,y)-I(x+1,y+1);%用第三个方向算子对这个像素做卷积 B(4)=I(x-1,y)+I(x-1,y-1)+I(x,y+1)-I(x+1,y)-I(x+1,y+1)-I(x,y+1); %用第四个方向算子对这个像素做卷积 B(5)=I(x-1,y-1)+
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 甘肃省靖远县部分学校2024-2025学年高一下学期期中考试政治试题(原卷版+解析版)
- 高端生活广场商户租赁协议
- 设计实践对国际商业美术设计师考试的影响与试题及答案
- 纺织行业发展趋势与试题及答案探讨
- 2025广东汕尾市水务集团有限公司招聘人员8人笔试参考题库附带答案详解
- 2025宁夏银川高新区建设投资有限公司招聘10人笔试参考题库附带答案详解
- 推动教育高质量发展的路径与措施
- 老旧农机更新换代新政解读
- 低空经济助力应急救援体系现代化建设方案
- 施工合同合同协议书
- GA/T 751-2024公安视频图像屏幕显示信息叠加规范
- 2025至2030中国长链氯化石蜡行业供需现状与前景策略研究报告
- 租地盖大棚合同协议
- 自体输血知识培训课件
- 人教A版高一下册必修第二册高中数学8.6.2直线与平面垂直【课件】
- 薪酬管理制度框架搭建
- 小学生涯课件
- 西藏拉萨中学2024-2025学年高三第二学期英语试题4月月考试卷含解析
- 软件开发行业智能化软件开发方案
- GB/T 45421-2025城市公共设施非物流用智能储物柜服务规范
- 档案相关法律法规知识复习试题及答案
评论
0/150
提交评论