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)
  1. 执行程序后,单击菜单栏中的文件,打开图片,在原图位置会显示彩色图像,单击“灰度转换”按钮,在灰度图像位置会显示转换后的灰度图像,在“设定阈值”框输入0.1,选择“检测方向”为both,再在“检测方法”菜单中选择Canny,即可在“检测图像”的位置显示边缘检测后的图像,最后在“文件”菜单中选择“保存”,即可保存最终分割后的边缘检测图。

 

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

如若内容造成侵权/违法违规/事实不符,请联系长河编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

【Python】解决Python报错:AttributeError: ‘NoneType‘ object has no attribute ‘xxx‘

🧑 博主简介:阿里巴巴嵌入式技术专家,深耕嵌入式人工智能领域,具备多年的嵌入式硬件产品研发管理经验。 📒 博客介绍:分享嵌入式开发领域的相关知识、经验、思考和感悟,欢迎关注。提供嵌入式方向…

【vue】v-for只显示前几个数据,超出显示查看更多

v-for只显示前几个数据&#xff0c;超出显示查看更多 如图 <div v-for"(item,index) in list.slice(0,3)" :key"index"><div class"degreeNo" :class"index0?noOne:index1?noTwo:index2?noThree:"> NO{{index1}}:<…

【蓝桥杯国赛】双指针

适用于以下的情境&#xff1a; ① 数组 / 字符串中&#xff0c;有多少个满足情况的连续区间。 ② 数组 / 字符串&#xff0c;合并。 【第十三届pythonB组试题&#xff1a;近似gcd】 1. 题目描述 2. 难度&#xff1a;⭐⭐⭐⭐ 3. 思考分析&#xff1a; 具体参考&#xff…

Geotools--生成等值线

好久没用geotools去写东西了&#xff0c;因为近几年一直在接触所谓数字孪生和可视化相关项目&#xff0c;个人的重心也往前端可视化去倾斜&#xff0c;在后端的开发上到变得停滞下来。 这次用的是geotools 28.4版本&#xff0c;生成等值线的方法在 <dependency><group…

【源码】多语言H5聊天室/thinkphp多国语言即时通讯/H5聊天室源码/在线聊天/全开源

多语言聊天室系统&#xff0c;可当即时通讯用&#xff0c;系统默认无需注册即可进入群聊天&#xff0c;全开源 【海外聊天室】多语言H5聊天室/thinkphp多国语言即时通讯/H5聊天室源码/在线聊天/全开源 - 吾爱资源网

使用Python库Matplotlib绘制常用图表类型

使用Python库Matplotlib绘图 一、Matplotlib绘图参数设置1.1 设置分辨率和画布大小1.2 保存图片并设置边缘留白为紧凑型1.3 设置坐标轴标签1.4 画直线设置线宽和颜色1.5 画子图1.5.1 通过figure的add_subplot()画子图1.5.2 通过plt的subplots画子图 二、使用Matplotlib中scatte…

JWT-登录后下发令牌

后端 写一个jwt工具类&#xff0c;处理令牌的生成和校验&#xff0c;如&#xff1a; 响应数据样例&#xff1a; 前端要做的&#xff1a;

java多态——向下转型

引入 前面我尝试了一下这个代码 package b;public class main_ {public static void main(String[] args) {//向上转型&#xff0c;父类的引用转向了子类的father_ animalnew graduate();Object objnew graduate();System.out.println(animal.name);System.out.println(obj.n…

三相智能电表通过Modbus转Profinet网关与PLC通讯案例

Modbus转Profinet网关&#xff08;XD-MDPN100/300&#xff09;的主要功能是实现Modbus协议和Profinet协议之间的转换和通信。Modbus转Profinet网关集成了Modbus和Profinet两种协议&#xff0c;支持Modbus RTU主站/从站&#xff0c;并可以与RS485接口的设备&#xff0c;它自带网…

「Java开发指南」如何用MyEclipse搭建Spring安全策略?

本教程将引导您向现有的Web应用程序添加Spring安全策略&#xff0c;在本教程中您将学习如何&#xff1a; 搭建Spring安全策略部署应用程序 注意&#xff1a;搭建Spring需要MyEclipse Spring或Bling授权。 MyEclipse v2023.1.2离线版下载(Q技术交流&#xff1a;742336981&…

python-双胞胎字符串

[问题描述]&#xff1a;给定两个字符串s和t&#xff0c;每次可以任意交换s的奇数位和偶数位的字符&#xff0c;即奇数位的字符可以与任意其它奇数位的字符交换&#xff0c;偶数位的字符同样也可以与任意偶数位的字符的字符交换&#xff0c;问能否在有限的次数的交换下使s变为t?…

基于ELK的日志管理【开发实践】

文章目录 一、ELK简介1.1 ELK的作用与应用1.2 ELK的组成1.3 Elasticsearch1.4 Logstash1.5 Kibana1.6 ELK架构简述1.7 基础知识1.7.1 数据格式1.7.2 正排索引和倒排索引1.7.3 全文搜索 二、ES入门---基于HTTP的使用方式&#xff08;了解&#xff09;2.1 索引操作2.1.1 创建索引…

线性代数|机器学习-P2 A的列向量空间

文章目录 1. Ax矩阵的形式2. ACR 矩阵分解2.1 rank1 矩阵分解2.2 rank2 矩阵分解2.3 ACMR,求M 3. Ax 向量 1. Ax矩阵的形式 假设我们有如下矩阵A&#xff1a; A x [ 2 1 3 3 1 4 5 7 12 ] [ x 1 x 2 x 3 ] \begin{equation} Ax\begin{bmatrix} 2&1&3\\\\ 3&1&am…

开源博客项目Blog .NET Core源码学习(29:App.Hosting项目结构分析-17)

本文学习并分析App.Hosting项目中后台管理页面的按钮管理页面。   按钮管理页面用于显示、新建、编辑、删除页面按钮数据&#xff0c;以便配置后台管理页面中每个页面的工具栏、操作栏、数据列中的按钮的事件及响应url。按钮管理页面附带一新建及编辑页面&#xff0c;以支撑新…

测试:ollama加载羊驼版本llama-3中文大模型

找了一个晚上各种模型&#xff0c;像极了当初找各种操作系统的镜像&#xff0c;雨林木风&#xff0c;深蓝、老毛桃…… 主要是官方的默认7B版本回答好多英文&#xff0c;而且回复的很慢&#xff0c;所以我是在ollama上搜索"chinese"找到了这个羊驼版本的&#xff0c…

前端功能拖拽篇:dragleave拖拽事件穿透子元素的优雅解决方案

文章目录 前情提要应用场景⭐拖拽改变元素位置⭐拖拽改变目标区域的样式⭐dragleave拖拽事件穿透子元素的优雅解决方案 最后 前情提要 在前端工作过程中&#xff0c;避免不了要接触各种技术&#xff0c;拖拽就是其中一个&#xff0c;大部分关于拖拽的基础知识和Demo都在MDN中写…

微服务 feign-gateway

早期微服务跨集群调用 使用的是Eureka 和RestTemplate&#xff0c;这种写法虽然可以解决服务之间的调用问题 ,但是随着服务的增多&#xff0c;实例变动&#xff0c;早期的写法相当于把请求方式&#xff0c;请求地址&#xff0c;参数写死了&#xff0c;耦合度太高&#xff0c;参…

易语言本地IP一键切换程序(附带源码)

易语言本地IP一键切换程序 效果图部分源码源码领取下期更新预报 效果图 部分源码 .判断开始 (单选框1.选中 &#xff1d; 真)标签5.标题 &#xff1d; #换行符 &#xff0b; “正在切换IP.”.如果真 (运行 (“netsh interface ip set address ” &#xff0b; #引号 &#xff…

开发一套家政上门预约服务系统需要运用的关键技术

家政上门预约服务系统开发是指建立一个在线平台或应用程序&#xff0c;用于提供家政服务的预约和管理功能。该系统的目标是让用户能够方便地预约各种家政服务&#xff0c;如保洁、家庭护理、月嫂、家电维修等&#xff0c;并实现服务供应商管理和订单管理等功能。 开发一套家政上…