当前位置:网站首页>MATLAB Gui 实现点击按钮,打开文件对话框,导入图片功能
MATLAB Gui 实现点击按钮,打开文件对话框,导入图片功能
2022-06-29 11:06:00 【鱼 丸】
这就是在MATLAB Gui中搭建的界面,目的是实现图片的读取导入。

在Gui界面中,右击按钮,选择Callback进入回调函数(右击选择图片按钮---单击查看回调----选择Callback),可见代码如下:
由于本人要显示的是图片,所以文件类型只选择了.bmp和.jpg和.png三种格式,当然你可以根据自己的需求自己添加啦!
filename中保存的是文件名,filepath中保存的是路径,注意第二句代码中一定是filepath在前,以便后面可以读取到文件。
function pushbutton1_Callback(hObject, eventdata, handles)
% hObject handle to pushbutton1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
global image;
[filename,filepath]=uigetfile({'*.bmp;*.png;*.jpg;'},'选择图像');%将可导入的文件类型写下来
if(isequal(filename,0)||isequal(filepath,0)) %如果按了取消,则return
return;
end
image = [filepath,filename]; %将文件名保存下来,并作为全局变量,方便后面程序调用
im=imread(image);
axes(handles.axes1);
imshow(im);
title('原始图像'); %显示图像,在axes1
axes(handles.axes2);
imhist(im); %输出图像直方图,在axes2
title('原始图像直方图');命令批注:
1、uigetfile - Open standard dialog box for retrieving files(打开标准对话框检索文件)
[FileName,PathName,FilterIndex] = uigetfile(FilterSpec)
[文件名,路径名,过滤指数]=uigetfile(过滤规范,即过滤的内容)
2、imread - Read image from graphics file(从图形文件中读取图像)
3、Set - Set graphics object properties(设置图形对象属性)
4、Image - Display image object(显示图像对象)
导入成功后,图像显示在axes控件里面啦!(axes控件编号需要根据自己Gui实际修改)
至此从文件夹选择图片的功能已经完成啦!

边栏推荐
- Pytorch - 分布式通信原语(附源码)
- CTO专访:合见工软深化产品布局 加速国产EDA技术革新
- Win11 web version
- 杰理之手动配对方式【篇】
- What are the main factors that affect the heat dissipation of LED packaging?
- 毕业5年,我问遍了身边的大佬,总结了他们的学习方法
- 小白学习MySQL - 增量统计SQL的需求 - 开窗函数的方案
- Is it safe to open a stock account online
- Unity学习笔记--Vector3怎么设置默认参数
- Discussion on QT learning 10 message processing in QT
猜你喜欢

Qt学习05 Qt Creator工程介绍

CTO专访:合见工软深化产品布局 加速国产EDA技术革新

杰理之发起对耳配对、回连、开启可发现、可连接的轮循函数【篇】

ruoyi框架中添加sharding sphere5.0.0分表(通过spi添加自定义分表策略)
![[NLP] text generation topic 1: basic knowledge](/img/cf/2e29e55344ea4cc8ce48777878b867.png)
[NLP] text generation topic 1: basic knowledge

Qt学习15 用户界面与业务逻辑的分离

Exclusive interview with CTO: the company has deepened the product layout and accelerated the technological innovation of domestic EDA
![Leetcode 535 encryption and decryption of tinyurl [map] the leetcode road of heroding](/img/76/709bbbbd8eb01f32683a96c4abddb9.png)
Leetcode 535 encryption and decryption of tinyurl [map] the leetcode road of heroding

启泰观察:职业精英创业必踩巨坑之 --- 学习效果坑

Cornerstone of efficient remote office: effective communication | community essay solicitation
随机推荐
Xuetong denies that the theft of QQ number is related to it: it has been reported; IPhone 14 is ready for mass production: four models are launched simultaneously; Simple and elegant software has long
[NLP] text generation topic 1: basic knowledge
Pull and push ideas behind rxjs observable design principles
The use of Fibonacci sequence and bubble sort in C language
普通用户使用vscode登录ssh编辑root文件
Qt学习08 启航!第一个应用实例
[HBZ sharing] InnoDB principle of MySQL
PyTorch学习之归一化层(BatchNorm、LayerNorm、InstanceNorm、GroupNorm)[通俗易懂]
Opencv4.0 installation of raspberry pie for Xiaobai
Exclusive interview with head of suss NIFT: the future of Web3 is inseparable from the governance of "everyone for me, I for everyone"
基于集群的动态反馈负载均衡策略
After 22 years in office, the father of PowerShell will leave Microsoft: he was demoted by Microsoft for developing PowerShell
Is it safe to open a stock account online
Go 单元测试入门实践
Several types of MySQL index invalidation and their solutions
专访 SUSS NiFT 负责人:Web3 的未来离不开“人人为我,我为人人”的治理
MariaDB的安装与配置
Nature | biosynthetic potential of global marine microbiome
The former security director of Uber faced fraud allegations and concealed the data leakage event
Unity学习笔记--Vector3怎么设置默认参数