当前位置:网站首页>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实际修改)
至此从文件夹选择图片的功能已经完成啦!

边栏推荐
- Qt学习06 窗口部件及窗口类型
- Windwos10安装sshd服务
- 普通用户使用vscode登录ssh编辑root文件
- Follow Me Study HCIE-Big Data-Data Mining 第一章 数据挖掘介绍 模块二
- How to test the performance of container platform, including stability, expansion efficiency and component performance
- pod安全策略(PSP)
- [HBZ sharing] the principle of reentrantlock realized by AQS + CAS +locksupport
- Cornerstone of efficient remote office: effective communication | community essay solicitation
- What is the experience of working in an IT company in Japan?
- [HBZ sharing] InnoDB principle of MySQL
猜你喜欢

XML external entity injection vulnerability (I)

win11网页版

稳定币风险状况:USDT 和 USDC 安全吗?
![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

QT learning 15 separation of user interface and business logic

Qt学习16 Qt 对象间的父子关系

pod安全策略(PSP)

软件工程导论——第五章——总体设计

CTO专访:合见工软深化产品布局 加速国产EDA技术革新
![[NLP] text generation topic 1: basic knowledge](/img/cf/2e29e55344ea4cc8ce48777878b867.png)
[NLP] text generation topic 1: basic knowledge
随机推荐
How to identify the exact length and width of the contour
c# 键盘钩子
What are the main factors that affect the heat dissipation of LED packaging?
[VTK] MFC grid editor based on vtk8.2
又拍雲 Redis 的改進之路
ruoyi框架中添加sharding sphere5.0.0分表(通过spi添加自定义分表策略)
地平线开发板配置网段
【毕业季】总结过去,展望未来
Exclusive interview with CTO: the company has deepened the product layout and accelerated the technological innovation of domestic EDA
Nature | biosynthetic potential of global marine microbiome
杰理之关于 TWS 配对方式配置【篇】
2022 question bank and simulation test for documenter post skills (documenter) operation certificate examination
【HBZ分享】Semaphore 与 CountDownLatch原理
杰理之关于 TWS 声道配置【篇】
高效远程办公的基石:有效沟通 |社区征文
How to find out the wrong mobile number when querying MySQL
检查YAML文件安全配置:kubesec
美创入选信通院“业务安全推进计划”首批成员单位
稳定币风险状况:USDT 和 USDC 安全吗?
Information technology application and innovation professionals (database) intermediate training hot enrollment (July 6-10)