当前位置: 首页 > article >正文

MATLAB guide选择图片和全局变量使用

文章目录

  • 前言
  • 一、按键选取文件
  • 二、全局化变量使用
    • 全局化使用
  • 总结


前言

提示:这里可以添加本文要记录的大概内容:

项目需要:


提示:以下是本篇文章正文内容,下面案例可供参考

一、按键选取文件

在这里插入图片描述

[filename,pathname]=uigetfile('*jpg','选择图片');

path=[pathname filename];
I=imread(path);
axes(handles.axes1)
imshow(I);

效果
在这里插入图片描述

二、全局化变量使用

全局化使用

代码如下(示例):

function varargout = untitled(varargin)
% UNTITLED MATLAB code for untitled.fig
%      UNTITLED, by itself, creates a new UNTITLED or raises the existing
%      singleton*.
%
%      H = UNTITLED returns the handle to a new UNTITLED or the handle to
%      the existing singleton*.
%
%      UNTITLED('CALLBACK',hObject,eventData,handles,...) calls the local
%      function named CALLBACK in UNTITLED.M with the given input arguments.
%
%      UNTITLED('Property','Value',...) creates a new UNTITLED or raises the
%      existing singleton*.  Starting from the left, property value pairs are
%      applied to the GUI before untitled_OpeningFcn gets called.  An
%      unrecognized property name or invalid value makes property application
%      stop.  All inputs are passed to untitled_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 untitled

% Last Modified by GUIDE v2.5 29-Sep-2024 11:37:04

% Begin initialization code - DO NOT EDIT
gui_Singleton = 1;
gui_State = struct('gui_Name',       mfilename, ...
                   'gui_Singleton',  gui_Singleton, ...
                   'gui_OpeningFcn', @untitled_OpeningFcn, ...
                   'gui_OutputFcn',  @untitled_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 untitled is made visible.
function untitled_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 untitled (see VARARGIN)

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

% Update handles structure
guidata(hObject, handles);

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


% --- Outputs from this function are returned to the command line.
function varargout = untitled_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 pushbutton1.
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 I
[filename,pathname]=uigetfile('*jpg','选择图片');

path=[pathname filename];
I=imread(path);
axes(handles.axes1)
imshow(I);
    


% --- Executes on button press in pushbutton2.
function pushbutton2_Callback(hObject, eventdata, handles)
% hObject    handle to pushbutton2 (see GCBO)
% eventdata  reserved - to be defined in a future version of MATLAB
% handles    structure with handles and user data (see GUIDATA)
global I

J=rgb2gray(I);
axes(handles.axes1)
imshow(J);



显示图片效果

在这里插入图片描述


总结

123


http://www.kler.cn/news/334757.html

相关文章:

  • 【Android】CarWatchDog I/O监控服务
  • 方法重写与多态
  • 速盾:游戏加速下载可以用cdn吗?
  • 互联网Java工程师面试题及答案整理(2024年最新版)
  • AI正悄然地影响着企业数字化转型
  • JUC高并发编程4:集合的线程安全
  • 30min 的OpenCV learning Note
  • 商城系统难点
  • 05实战篇:667分析题三大基本题型的破解之术
  • 自动化分配客服售后工单的高效策略
  • 【二十八】【QT开发应用】模拟WPS Tab
  • Linux 默认内核版本更改
  • 模型无关的局部解释(LIME)技术原理解析及多领域应用实践
  • SVM及其实践1 --- 概念、理论以及二分类实践
  • 速速收藏!这些2024年上映的AI电影与短剧,申请加入你的国庆假期宅家计划!
  • Flask-3
  • github项目——gpt-pilot自动创建应用
  • 一个真实可用的登录界面!
  • thinkphp6入门(25)-- 分组查询 GROUP_CONCAT
  • C#串口温度读取