matlab GUI界面设计

news2024/11/26 6:20:36

【实验内容】

用MATLAB的GUI程序设计一个具备图像边缘检测功能的用户界面,该设计程序有以下基本功能:

(1)图像的读取和保存。

(2)设计图形用户界面,让用户对图像进行彩色图像到灰度图像的转换,并显示原图和灰度图像。

(3)设计图形用户界面,让用户能够根据需要来选择边缘检测算子,即选择边缘检测的方法。

(4)设计图形用户界面,让用户能够自行设定检测的阈值和方向。

(5)显示边缘检测后的图像,并与原图和灰度图像进行对比。

【实验步骤】

1、建立菜单,选项包括“文件”(打开、保存、退出)、“检测方法”(sobel、prewitt、roberts、canny)和“帮助”。

建立3个坐标轴对象,用于显示原始图像、灰度图像和边缘检测后的图像。

建立1个按钮,用于将原始图像转换为灰度图像。

建立1个文本编辑框,用于输入数据。

建立菜单,选项包括“文件”(打开、保存、退出)、“检测方法”(sobel、prewitt、roberts、canny)和“帮助”。

五个静态文本框的string属性分别为“原图”、“灰度图像”、“检测图像”、“设定阈值”和“检测方向”。

三个坐标轴的Tag标识分别为original_image、gray_image、test_image。

按钮控件的string属性为“灰度转换”,Tag标识为rgbtogray。

文本编辑框的Tag标识为thresh_value。

列表框的string属性为horizontal、vertical、both,Tag标识为direction。

编写代码完成程序中的变量赋值、输入、输出等工作,打开对应文件,在对应函数位置添加如下程序,其他代码不变。

function varargout = m240531(varargin)
% M240531 MATLAB code for m240531.fig
%      M240531, by itself, creates a new M240531 or raises the existing
%      singleton*.
%
%      H = M240531 returns the handle to a new M240531 or the handle to
%      the existing singleton*.
%
%      M240531('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in M240531.M with the given input arguments.
%
%      M240531('Property','Value',...) creates a new M240531 or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before m240531_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to m240531_OpeningFcn via varargin.
%
%      *See GUI Options on GUIDE's Tools menu.  Choose "GUI allows only one
%      instance to run (singleton)".
%
% See also: GUIDE, GUIDATA, GUIHANDLES

% Edit the above text to modify the response to help m240531

% Last Modified by GUIDE v2.5 31-May-2024 11:43:02

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @m240531_OpeningFcn, ...
                   'gui_OutputFcn',  @m240531_OutputFcn, ...
                   'gui_LayoutFcn',  [] , ...
                   'gui_Callback',   []);
if nargin && ischar(varargin{1})
    gui_State.gui_Callback = str2func(varargin{1});
end

if nargout
    [varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
else
    gui_mainfcn(gui_State, varargin{:});
end
% End initialization code - DO NOT EDIT


% --- Executes just before m240531 is made visible.
function m240531_OpeningFcn(hObject, eventdata, handles, varargin)
% This function has no output args, see OutputFcn.
% hObject    handle to figure
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
% varargin   command line arguments to m240531 (see VARARGIN)

% Choose default command line output for m240531
handles.output = hObject;

% Update handles structure
guidata(hObject, handles);

% UIWAIT makes m240531 wait for user response (see UIRESUME)
% uiwait(handles.figure1);


% --- Outputs from this function are returned to the command line.
function varargout = m240531_OutputFcn(hObject, eventdata, handles) 
% varargout  cell array for returning output args (see VARARGOUT);
% hObject    handle to figure
% 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 structure
varargout{1} = handles.output;


% --- Executes on button press in rgbtogray.
function rgbtogray_Callback(hObject, eventdata, handles)
% hObject    handle to rgbtogray (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
gray=rgb2gray(handles.img)
set(handles.gray_image, 'HandleVisibility', 'ON');
axes(handles.gray_image)
imshow(gray);
handles.img=gray;
guidata(hObject,handles);


function thresh_value_Callback(hObject, eventdata, handles)
% hObject    handle to thresh_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: get(hObject,'String') returns contents of thresh_value as text
%        str2double(get(hObject,'String')) returns contents of thresh_value as a double


% --- Executes during object creation, after setting all properties.
function thresh_value_CreateFcn(hObject, eventdata, handles)
% hObject    handle to thresh_value (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: edit controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --- Executes on selection change in direction.
function direction_Callback(hObject, eventdata, handles)
% hObject    handle to direction (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)

% Hints: contents = cellstr(get(hObject,'String')) returns direction contents as cell array
%        contents{get(hObject,'Value')} returns selected item from direction


% --- Executes during object creation, after setting all properties.
function direction_CreateFcn(hObject, eventdata, handles)
% hObject    handle to direction (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    empty - handles not created until after all CreateFcns called

% Hint: popupmenu controls usually have a white background on Windows.
%       See ISPC and COMPUTER.
if ispc && isequal(get(hObject,'BackgroundColor'), get(0,'defaultUicontrolBackgroundColor'))
    set(hObject,'BackgroundColor','white');
end


% --------------------------------------------------------------------
function Untitled_1_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_1 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_2_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Untitled_3_Callback(hObject, eventdata, handles)
% hObject    handle to Untitled_3 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)


% --------------------------------------------------------------------
function Sobel_Callback(hObject, eventdata, handles)
% hObject    handle to Sobel (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
v1=str2double(get(handles.thresh_value, 'string' ));
contents=get(handles.direction,'string');
v2=contents{(get(handles.direction,'value'))};
edge_sobel=edge(handles.img,'sobel',v1,v2);
set(handles.test_image, 'HandleVisibility','ON');
axes(handles.test_image);
imshow(edge_sobel)
handles.img=edge_sobel;
guidata(hObject,handles);

% --------------------------------------------------------------------
function Prewitt_Callback(hObject, eventdata, handles)
% hObject    handle to Prewitt (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
v1=str2double(get(handles.thresh_value,'string'))
contents=get(handles.direction, 'string');
v2=contents{(get(handles.direction,'value' ))};
edge_prewitt=edge(handles.img, 'prewitt' ,v1,v2);
set(handles.test_image, 'HandleVisibility','ON');
axes(handles.test_image);
imshow(edge_prewitt)
handles.img=edge_prewitt;
guidata(hObject,handles);

% --------------------------------------------------------------------
function Roberts_Callback(hObject, eventdata, handles)
% hObject    handle to Roberts (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
v1=str2double(get(handles.thresh_value,'string'))
contents=get(handles.direction, 'string');
v2=contents{(get(handles.direction,'value'))};
edge_roberts=edge(handles.img, 'roberts' ,v1,v2);
set(handles.test_image, 'HandleVisibility','ON');
axes(handles.test_image);
imshow(edge_roberts)
handles.img=edge_roberts;
guidata(hObject,handles);


% --------------------------------------------------------------------
function Canny_Callback(hObject, eventdata, handles)
% hObject    handle to Canny (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
v1=str2double(get(handles.thresh_value, 'string'));
contents=get(handles.direction,'string');
v2=contents{(get(handles.direction,'value'))};
edge_canny=edge(handles.img,'canny',v1, v2);
set(handles.test_image, 'HandleVisibility','ON');
axes(handles.test_image);
imshow(edge_canny);
handles.img=edge_canny;
guidata(hObject,handles);

% --------------------------------------------------------------------
function open_Callback(hObject, eventdata, handles)
% hObject    handle to open (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[filename,pathname] = uigetfile({'*.jpg';'*.bmp';'*.tif';'*.*'},'载入图像');
if isequal(filename,0) || isequal(pathname,0)
    errordlg('没有选中文件','出错');
    return;
else
    file=[pathname,filename];
    global S
    S=file;
    x=imread(file);
    set(handles.original_image,'HandleVisibility','ON');
    axes(handles.original_image);
    imshow(x);
    handles.img=x;
    guidata(hObject,handles);
end

% --------------------------------------------------------------------
function save_Callback(hObject, eventdata, handles)
% hObject    handle to save (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
[sfilename,sfilepath]=uiputfile({'*.jpg';'*.bmp';'*.tif';'*.*'}, ...
    '保存图像文件','untitled.jpg');
if ~isequal([sfilename,sfilepath],[0,0])
    sfileullname = [sfilepath,sfilename];
    imwrite(handles.img, sfilefullname);
else
    msgbox('你按了取消键','保存失败');
end


% --------------------------------------------------------------------
function exit_Callback(hObject, eventdata, handles)
% hObject    handle to exit (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
  1. 执行程序后,单击菜单栏中的文件,打开图片,在原图位置会显示彩色图像,单击“灰度转换”按钮,在灰度图像位置会显示转换后的灰度图像,在“设定阈值”框输入0.1,选择“检测方向”为both,再在“检测方法”菜单中选择Canny,即可在“检测图像”的位置显示边缘检测后的图像,最后在“文件”菜单中选择“保存”,即可保存最终分割后的边缘检测图。

 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/1805715.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

【java、lucene、python】互联网搜索引擎课程报告二:建立搜索引擎

一、项目要求 建立并实现文本搜索功能 对经过预处理后的500个英文和中文文档/网页建立搜索并实现搜索功能对文档建立索引,然后通过前台界面或者已提供的界面,输入关键字,展示搜索结果前台可通过网页形式、应用程序形式、或者利用已有的界面…

SQLserver通过CLR调用TCP接口

一、SQLserver启用CLR 查看是否开启CRL,如果run_value1,则表示开启 EXEC sp_configure clr enabled; GO RECONFIGURE; GO如果未启用,则执行如下命令启用CLR sp_configure clr enabled, 1; GO RECONFIGURE; GO二、创建 CLR 程序集 创建新项…

【Java】单例设计模式

单例设计模式简介 目录 1.单例设计模式是什么?2.单例设计模式设计方法饿汉式懒汉式 3.单例设计模式的应用任务管理器(仅有一个页面,不可多开)Runtime运行环境 1.单例设计模式是什么? 设计模式 是解决 特定问题的优秀设计方式之一。 单例设计…

mathematica中针对三维图中的颜色和填充透明度进行指定

颜色指定使用的命令为:PlotStyle 填充的透明度使用的命令为:FillingStyle 示例代码: Clear["Global*"] Plot3D[{Sin[x^2 y], Sin[x^2 - y]}, {x, -2, 2}, {y, -2, 2}, PlotStyle -> {Directive[Red, Specularity[White, 100…

人体部位眼耳手腿分类数据集4376张4类别

数据集类型:图像分类用,不可用于目标检测无标注文件 数据集格式:仅仅包含jpg图片,每个类别文件夹下面存放着对应图片 图片数量(jpg文件个数):4376 分类类别数:4 类别名称:["Ears","Eyes&quo…

win设置ftp服务器~java通过ftp下载文件

1.先设置ftp 2.打开服务 3.设置站点 4.起名字 这样就可以了 5.剩下的就是设置权限和账号了,找到对应的按钮就可以了 6.下载文件的代码 public byte[] downloadFile(File file) throws IOException{ByteArrayOutputStream out new ByteArrayOutputStream();toDi…

算法家族之一——二分法

目录 算法算法的打印效果如果算法里的整型“i”为1如果算法里的整型“i”为11 算法的流程图算法的实际应用总结 大家好&#xff0c;我叫 这是我58&#xff0c;现在&#xff0c;请看下面的算法。 算法 #define _CRT_SECURE_NO_WARNINGS 1//<--预处理指令 #include <stdi…

Netty原理与实战

1.为什么选择Netty&#xff1f; 高性能低延迟 事件分发器&#xff1a; reactor采用同步IO&#xff0c;Proactor采用异步IO 网络框架选型&#xff1a; 2.Netty整体架构设计&#xff08;4.X&#xff09; 三个模块&#xff1a;Core核心层、Protocal Support协议支持层、…

unity3d:GameFramework+xLua+Protobuf+lua-protobuf,与服务器交互收发协议

概述 1.cs收发协议&#xff0c;通过protobuf序列化 2.lua收发协议&#xff0c;通过lua-protobuf序列化 一条协议字节流组成 C#协议基类 CSPacketBase&#xff0c;SCPacketBaseC#用协议基类 proto生成的CS类&#xff0c;基于这两个基类。分别为CSPacketBase是客户端发送至服…

真空衰变,真正的宇宙级灾难,它到底有多可怕?

真空衰变&#xff0c;真正的宇宙级灾难&#xff0c;它到底有多可怕&#xff1f; 真空衰变 真空衰变&#xff08;Vacuum decay&#xff09;是物理学家根据量子场论推测出的一种宇宙中可能会发生的现象&#xff0c;这种现象被称为真正的宇宙级灾难&#xff0c;它到底有多可怕呢…

野火FPGA跟练(四)——串口RS232、亚稳态

目录 简介接口与引脚通信协议亚稳态RS232接收模块模块框图时序波形RTL 代码易错点Testbench 代码仿真 RS232发送模块模块框图时序波形RTL 代码Testbench 代码仿真 简介 UART&#xff1a;Universal Asynchronous Receiver/Transmitter&#xff0c;异步串行通信接口。发送数据时…

sick0s1.1 靶机实战

sick0s1.1 信息收集 nmap存活及端口&#xff1a; nmap服务扫描&#xff1a; web 80和8080都没有开放&#xff0c;&#xff0c;无法访问&#xff0c;gobuster等工具也跑不了&#xff0c;访问一下3128试试 根据端口服务扫描也能得知这是个http的代理服务器&#xff0c;&#x…

机器学习常见知识点 2:决策树

文章目录 决策树算法1、决策树树状图2、选择最优决策条件3、决策树算法过程→白话决策树原理决策树构建的基本步骤常见的决策树算法决策树的优缺点 【五分钟机器学习】可视化的决策过程&#xff1a;决策树 Decision Tree 关键词记忆&#xff1a; 纯度、选择最优特征分裂、熵、基…

SLAM小题目

1、最小二乘题目&#xff1a; 假设有三个WIFI热点&#xff0c;位置分别在(x1,y1), (x2,y2), (x3,y3), 移动端测量到每一个热点的距离L1,L2和L3&#xff0c;要求解移动端的位置. #include <iostream> #include <vector> #include <cmath> class Point { pub…

数据结构笔记 4 树和二叉树

二叉树和完全二叉树的区别&#xff1f; 二叉树和完全二叉树的主要区别在于它们的结构特性和节点排列方式&#xff1a; 1. **二叉树**&#xff1a; - 是一种数据结构&#xff0c;其中每个节点最多有两个子节点&#xff0c;通常称为左子节点和右子节点。 - 节点的子节点数量…

海思SD3403,SS928/926,hi3519dv500,hi3516dv500移植yolov7,yolov8(21)Yolov9s测试

四天前yolov9的作者终于开源了yolov9s和yolov9t模型。这个作者之前一直没开源t,s,只有c开始的,而且onnx转换后数据大小特别大,当时直接就放弃测试了。 另外之前代码有很明显的抄v5的痕迹。所以印象很不好。 现在总算是开源t,s模型,而且这里评估的结果上来看是好于yolov8的…

两款好用的IOS、Android图片处理应用

GIF 小助手 GIF工具包是一个简单实用的GIF动画编辑器&#xff0c;目前仅支持IOS平台。 使用该软件&#xff0c;可以将多个图像、视频和现场照片创建为gif。 主要功能&#xff1a; 多种输入源&#xff1a;用户可以将多个图片、视频或Livephoto转换成GIF动图。 编辑功能&#…

RDK X3(aarch64) 测试激光雷达思岚A1

0. 环境 - 亚博智能的ROSMASTER-X3 - RDK X3 1.0 0.1 资料 文档资料 https://www.slamtec.com/cn/Support#rplidar-a-series SDK https://github.com/slamtec/rplidar_sdk ROS https://github.com/slamtec/rplidar_ros https://github.com/Slamtec/sllidar_ros2 1. robostu…

windows上安装MongoDB,springboot整合MongoDB

上一篇文章已经通过在Ubuntu上安装MongoDB详细介绍了MongoDB的各种命令用法。 Ubuntu上安装、使用MongoDB详细教程https://blog.csdn.net/heyl163_/article/details/133781878 这篇文章介绍一下在windows上安装MongoDB&#xff0c;并通过在springboot项目中使用MongoDB记录用户…

Java:112-SpringMVC的底层原理(下篇)

这里继续续写上一章博客&#xff08;111章博客&#xff09;&#xff1a; Spring MVC 源码深度剖析&#xff1a; 既然我们自行写出了一个&#xff0c;那么我们可以选择看看mvc源码&#xff1a; 前端控制器 DispatcherServlet 继承结构&#xff1a; 前面我们知道mvc是操作同…