matlab GUI界面设计
【实验内容】
用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});
endif nargout[varargout{1:nargout}] = gui_mainfcn(gui_State, varargin{:});
elsegui_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;
elsefile=[pathname,filename];global SS=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);
elsemsgbox('你按了取消键','保存失败');
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)
- 执行程序后,单击菜单栏中的文件,打开图片,在原图位置会显示彩色图像,单击“灰度转换”按钮,在灰度图像位置会显示转换后的灰度图像,在“设定阈值”框输入0.1,选择“检测方向”为both,再在“检测方法”菜单中选择Canny,即可在“检测图像”的位置显示边缘检测后的图像,最后在“文件”菜单中选择“保存”,即可保存最终分割后的边缘检测图。


相关文章:
matlab GUI界面设计
【实验内容】 用MATLAB的GUI程序设计一个具备图像边缘检测功能的用户界面,该设计程序有以下基本功能: (1)图像的读取和保存。 (2)设计图形用户界面,让用户对图像进行彩色图像到灰度图像的转换…...
MyBatis 面试题
一、什么是 Mybatis? 1、Mybatis 是一个半 ORM(对象关系映射)框架,它内部封装了 JDBC,开发时 只需要关注 SQL 语句本身,不需要花费精力去处理加载驱动、创建连接、创建 statement 等繁杂的过程。程序员直接编写原生态 sql,可以严格控制 sql 执行性 能,灵活度高。 …...
C#根据数据量自动排版标签的样例
这是一个C#根据数据量自动排版标签的样例 using System; using System.Collections.Generic; using System.Data.SqlClient; using System.Drawing; using System.Text; using System.Threading; using System.Threading.Tasks; using System.Windows.Forms; using HslCommuni…...
【网络安全】Web安全基础 - 第一节:使用软件及环境介绍
VMware VMware,是全球云基础架构和移动商务解决方案的佼佼者。 VMware可是一个总部位于美国加州帕洛阿尔托的计算机虚拟化软件研发与销售企业呢。简单来说,它就是通过提供虚拟化解决方案,让企业在数据中心改造和公有云整合业务上更加得心应…...
Mac下载docker
先安装homebrew Mac下载Homebrew-CSDN博客 然后输入以下命令安装docker brew install --cask --appdir/Applications docker 期间需要输入密码。输入完等待即可...
k8s_设置dns
配置k8s dns 在 Kubernetes 集群中,CoreDNS 是默认的 DNS 服务器,它负责处理集群内所有的 DNS 请求。 kubectl edit cm coredns -n kube-system (此命令修改coredns 配置) kubectl describe cm coredns -n kube-system(此命令查看coredns 配…...
翻译《The Old New Thing》- What a drag: Dragging a virtual file (HGLOBAL edition)
What a drag: Dragging a virtual file (HGLOBAL edition) - The Old New Thing (microsoft.com)https://devblogs.microsoft.com/oldnewthing/20080318-00/?p23083 Raymond Chen 2008年03月18日 拖拽虚拟文件(HGLOBAL 版本) 现在我们已经对简单的数据…...
SA316系列音频传输模块-传输距离升级音质不打折
SA316是思为无线研发的一款远距离音频传输模块,音频采样率为48K,传输距离可达200M。为了满足更多用户需求,思为无线在SA316基础上进一步增加传输距离推出SA316F30。相比SA316性能,同样其采用48K采样,-96dBm灵敏度&…...
【机器学习】智能选择的艺术:决策树在机器学习中的深度剖析
在机器学习的分类和回归问题中,决策树是一种广泛使用的算法。决策树模型因其直观性、易于理解和实现,以及处理分类和数值特征的能力而备受欢迎。本文将解释决策树算法的概念、原理、应用、优化方法以及未来的发展方向。 🚀时空传送门 &#x…...
电脑缺少运行库,无法启动程序
在我们使用一些软件的时候,由于电脑缺少一些运行库,导致无法启动应用软件,此时需要我们安装缺少的运行库。 比如当电脑提示: Cannot load library Qt5Xlsx.dll 我们就需要下载C得运行库,以满足软件运行需要。 下载链…...
【计算机软考_初级篇】每日十题2
各位老师大家好,软考对于日常的知识储备和企业中的考试,或者说在校大学生来说,那用处是非常大的!!那么下面我们进入正题,软考呢是分两种语言,java和C,对于其他语言目前还没ÿ…...
HR人才测评,如何做营销人员岗位素质测评?
营销人员是企业中的重要角色,他们直接负责企业产品或服务的销售和推广,是企业中最直接影响销售业绩的人才之一。因此,营销人员的基本素质测评非常重要,能够有效评估营销人员的能力和潜力,为企业招聘和培养优秀的营销人…...
LabVIEW调用第三方硬件DLL常见问题及开发流程
在LabVIEW中调用第三方硬件DLL时,除了技术问题,还涉及开发流程、资料获取及与厂家的沟通协调。常见问题包括函数接口不兼容、数据类型转换错误、内存管理问题、线程安全性等。解决这些问题需确保函数声明准确、数据类型匹配、正确的内存管理及线程保护。…...
datax实现MySQL数据库迁移shell自动化脚本
datax实现MySQL数据库迁移 (1)生成python脚本 # codingutf-8 import json import getopt import os import sys import MySQLdb#MySQL相关配置,需根据实际情况作出修改 mysql_host "xxxx" mysql_port "3306" mysql_u…...
PostgreSQL的学习心得和知识总结(一百四十四)|深入理解PostgreSQL数据库之sendTuples的实现原理及功能修改
目录结构 注:提前言明 本文借鉴了以下博主、书籍或网站的内容,其列表如下: 1、参考书籍:《PostgreSQL数据库内核分析》 2、参考书籍:《数据库事务处理的艺术:事务管理与并发控制》 3、PostgreSQL数据库仓库…...
C++数据结构之:链List
摘要: it人员无论是使用哪种高级语言开发东东,想要更高效有层次的开发程序的话都躲不开三件套:数据结构,算法和设计模式。数据结构是相互之间存在一种或多种特定关系的数据元素的集合,即带“结构”的数据元素的集合&am…...
10.Redis之set类型
谈到一个术语,这个术语很可能有多种含义~~ 1.Set 1) 集合. 2)设置 (和 get 相对应) 集合就是把一些有关联的数据放到一起~~ 1.集合中的元素是无序的! 【此处说的无序和 前面list这里的有序 是对应的, 有序: 顺序很重要. 变换一下顺序, 就是不同的 list 了 无序: 顺序不…...
SpringBoot + mongodb 删除集合中的数据
MongoTemplate是Spring Data MongoDB提供的一个工具类,用于与MongoDB进行交互。它提供了许多方法来执行数据库操作,包括删除数据。 本文将介绍如何使用Java MongoTemplate删除集合内的数据,并提供相应的代码示例。 1. 引入MongoTemplate 首…...
【日常记录】【JS】前端预览图片的两种方式,Base64预览和blob预览
文章目录 1、前言1、FileReader3、window.URL.createObjectURL4、参考链接 1、前言 一般来说,都是 后端返回给前端图片的url,前端直接把这个值插入到 img 的src 里面即可还有一种情况是前端需要预览一下图片,比如:上传头像按钮&a…...
每日刷题——杭电2156.分数矩阵和杭电2024.C语言合法标识符
杭电2156.分数矩阵 原题链接:Problem - 2156 题目描述 Problem Description:我们定义如下矩阵: 1/1 1/2 1/3 1/2 1/1 1/2 1/3 1/2 1/1 矩阵对角线上的元素始终是1/1,对角线两边分数的分母逐个递增。请求出这个矩阵的总和。 Input…...
VN5640硬件驱动从11.1升级后必看:Network-base访问模式的完整配置流程与避坑指南
VN5640硬件驱动升级至11.1后的Network-base访问模式全流程配置与实战避坑指南 当车载以太网测试工程师将VN5xxx系列硬件驱动升级到11.1版本后,一个关键但容易被忽视的变化是Network-base访问模式的引入。这种新模式彻底改变了传统channel-base的配置逻辑࿰…...
小白程序员看过来!TS同学半年逆袭AI大模型产品经理,收藏这份转行避坑指南!
TS同学从景观设计转行AI大模型产品经理的经历分享。他经历了离职、脱产学习、国企子公司项目被裁等波折,最终以20%薪资涨幅加入AI公司。文章重点介绍了他的心态调整、求职策略变化以及对“稳定”的新理解,同时探讨了AI时代教育孩子的思考。 本期嘉宾TS同…...
终极指南:使用XNBCLI高效解包打包星露谷物语XNB游戏资源文件
终极指南:使用XNBCLI高效解包打包星露谷物语XNB游戏资源文件 【免费下载链接】xnbcli A CLI tool for XNB packing/unpacking purpose built for Stardew Valley. 项目地址: https://gitcode.com/gh_mirrors/xn/xnbcli XNB文件是星露谷物语等XNA游戏引擎使用…...
别再只会显示字符了!用51单片机和OLED做个简易电子时钟(IIC协议详解)
从零构建51单片机OLED电子时钟:IIC协议深度解析与项目实战 在嵌入式开发领域,51单片机因其稳定性和易用性始终占据一席之地。当基础的点亮OLED屏幕、显示静态文字已经无法满足你的求知欲时,一个融合硬件协议、实时时钟和UI设计的电子时钟项目…...
MacBook远程控制Win10打游戏?聊聊Microsoft Remote Desktop的那些隐藏玩法和限制
MacBook远程控制Win10打游戏?Microsoft Remote Desktop的极限性能测试与实战技巧 当MacBook用户需要临时调用Windows电脑的资源时,远程桌面工具往往成为救急首选。但你是否想过,这类工具能否胜任游戏、视频剪辑甚至3D建模等高图形负载任务&am…...
AI技能实战:本地部署大模型构建智能摘要工具
1. 项目概述:一个面向AI技能实践的开发者工具箱最近在GitHub上看到一个挺有意思的项目,叫inblog-inc/inblog-ai-skills。光看这个名字,你可能会觉得它又是一个关于“AI技能”的教程合集或者理论文档。但点进去之后,我发现它的定位…...
苏峻:一个“产品偏执狂”的20年跨界史,从讲台到造车,他到底在疯什么?icar
苏峻:一个“产品偏执狂”的20年跨界史,从讲台到造车,他到底在疯什么?一个50岁的清华大学设计学博士,当过15年大学老师,做过空气净化器,卖过200万台,现在又跑去造车。有人说他是疯子&…...
从架构到体验:友猫社区平台的全栈技术解析与功能体系详解
一、项目概述 友猫社区平台由宠友信息技术有限公司自主研发,是一套面向社区、社交、电商和即时通讯一体化的综合型系统。 平台采用前后端分离、Java微服务架构,配合VueUniApp多端适配方案,能够支持Web端、Android端与iOS端同步运行。 演示网…...
基于MCP协议构建AI驱动的加密货币数据智能查询系统
1. 项目概述:当加密货币数据需要“智能”起来如果你正在开发一个需要实时加密货币数据的应用,或者你是一个数据分析师,每天需要手动从几十个交易所网站和API里抓取价格、市值、交易量,那么你大概率已经对数据源的分散、格式的不统…...
ARM PMU中断控制寄存器PMINTENCLR/PMINTENSET详解
1. ARM性能监控单元(PMU)架构概述 在现代处理器设计中,性能监控单元(Performance Monitoring Unit, PMU)是实现系统级性能分析和优化的关键组件。ARM架构从v7开始引入标准化的PMU设计,并在v8/v9架构中持续演进。PMU的核心功能是通过一组可编程事件计数器…...
