您的位置:首页 > 编程语言 > MATLAB

matlab_GUI_2 radiobutton

2015-11-27 09:29 429 查看
<span style="font-family: Arial, Helvetica, sans-serif;">添加按钮 作用:选择图片并且可以退出</span>

function pushbutton3_Callback(hObject, eventdata, handles)

% hObject handle to pushbutton3 (see GCBO)

% eventdata reserved - to be defined in a future version of MATLAB

% handles structure with handles and user data (see GUIDATA)

global im

%选择图片路径

[filename,pathname] = ...

uigetfile(['*.jpg'],'选择图片');

%合成路径

str=[pathname filename];

%读取图片

im=imread(str);

%使用第一个axes

axes(handles.axes1);

%显示图片

<pre><span style="font-size:18px;">imshow</span>(im);

function uipanel1_SelectionChangeFcn(hObject, eventdata, handles)

% hObject    handle to the selected object in uipanel1 

% eventdata  structure with the following fields (see UIBUTTONGROUP)

% EventName: string 'SelectionChanged' (read only)

% OldValue: handle of the previously selected object or empty if none was selected

% NewValue: handle of the currently selected object

% handles    structure with handles and user data (see GUIDATA)

%在此函数中通常会使用 switch case 

global im %使用全局变量im

str=get(hObject,'string');%拿到所选择的按钮的名称

axes(handles.axes1);%从这里开始所有的作图在这个画图板里作图

switch str

    case '原图'

        imshow(im);

    case 'sobel'

        BW = edge(rgb2gray(im),'sobel');%func1:rgb转化为灰色图片 然后边缘检测

        imshow(BW);

    case 'prewitt'

        BW = edge(rgb2gray(im),'prewitt');

        imshow(BW);

    case 'canny'

        BW = edge(rgb2gray(im),'canny');

        imshow(BW);

end;





                                            
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: