Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/image-processing/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Image processing 我想在Matlab中禁用一个按钮_Image Processing_Matlab_Matlab Guide - Fatal编程技术网

Image processing 我想在Matlab中禁用一个按钮

Image processing 我想在Matlab中禁用一个按钮,image-processing,matlab,matlab-guide,Image Processing,Matlab,Matlab Guide,我有一个图像,滑块和一个按钮。 通过移动滑块旋转图像,通过按下按钮保存图像。 还有一个文本框,用于写入旋转角度。 我想禁用按钮,直到用户移动到滑块。 (滑块可以返回到初始状态) 这是密码 function [angle] = rotationGUI() I = imread('frames/001.jpg'); %# c hFig = figure('menu','none'); hAx = axes('Parent',hFig); hTxt = u

我有一个图像,滑块和一个按钮。 通过移动滑块旋转图像,通过按下按钮保存图像。 还有一个文本框,用于写入旋转角度。 我想禁用按钮,直到用户移动到滑块。 (滑块可以返回到初始状态)

这是密码

 function [angle] = rotationGUI()

    I = imread('frames/001.jpg');
    %# c
    hFig = figure('menu','none');
    hAx = axes('Parent',hFig);

    hTxt = uicontrol('Style','text', 'Position',[290 28 20 15], 'String','0');
    uicontrol('Parent',hFig, 'Style','slider', 'Value',0, 'Min',0,...
        'Max',360, 'SliderStep',[1 10]./360, ...
        'Position',[150 5 300 20], 'Callback',{@slider_callback,I,hAx,hTxt,hFig})


    uicontrol(hFig,'Style','pushbutton','String','Save and Close',...
        'Position',[10 20 120 40],'Callback',{@ok_Callback,I,hTxt,hFig,'frames/001.jpg'});



    %# show image
    imshow(I, 'Parent',hAx)
    %# Callback function
    return;
    end
        function slider_callback(hObj, eventdata,I,hAx,hTxt,hFig)
    global angle
    global Irot
    angle = round(get(hObj,'Value'));        %# get rotation angle in degrees

    Irot = imrotate(I,angle);
    imshow(Irot, 'Parent',hAx)  %# rotate image
    if (angle==0) 
        angle=360;
    end
    set(hTxt, 'String',num2str(angle))       %# update text
    end


function ok_Callback(hObj, eventdata,I,hTxt,hFig,path1)

    global Irot
    global angle
    set(hTxt, 'String','save')
    imwrite(Irot,path1);

    delete(hFig);
    end

你应该给你的按钮一个每个功能都可以访问的句柄,就像这样

    h.Button=uicontrol(hFig,'Style','pushbutton',...
然后将句柄赋予其他函数,可以通过将回调设置为{}来停用它,也可以不显示它,而不希望单击它。看起来像这样:

    set(h.Button,'callback',{});

当然,当您希望回调或可见选项再次工作时,必须将其设置为正确的回调或“开”。我认为您可以自己找到在代码中插入它的位置:)


希望这对您有所帮助。

您需要为按钮提供如下手柄:
按钮handle=uicontrol(…)

当您声明按钮时,您需要在按钮的组件中添加一行以禁用按钮:
,“enable”,“off”

然后需要将其作为参数传递给slider函数回调,然后在slider函数中设置一行
(buttonhandle,'enable','on')


您的按钮声明必须位于滑块声明之上,否则滑块回调函数将接收无效参数。

tnx,谢谢您的帮助!!!!! 你帮了我很多

最后的代码是

function [angle] = rotationGUI()

I = imread('frames/001.jpg');
%# c
hFig = figure('menu','none');
hAx = axes('Parent',hFig);
global hButton;


hTxt = uicontrol('Style','text', 'Position',[290 28 20 15], 'String','0');
uicontrol('Parent',hFig, 'Style','slider', 'Value',0, 'Min',0,...
    'Max',360, 'SliderStep',[1 10]./360, ...
    'Position',[150 5 300 20], 'Callback',{@slider_callback,I,hAx,hTxt,hFig})

hButton=uicontrol(hFig,'Style','pushbutton','String','Save and Close',...
    'Position',[10 20 120 40],'Callback',{@ok_Callback,I,hTxt,hFig,'frames/001.jpg'});
set(hButton,'Enable','off');



imshow(I, 'Parent',hAx)
    return;
end
    function slider_callback(hObj, eventdata,I,hAx,hTxt,hFig)
global angle
global Irot
global hButton
set(hButton,'Enable','on');
angle = round(get(hObj,'Value'));        %# get rotation angle in degrees

Irot = imrotate(I,angle);
imshow(Irot, 'Parent',hAx)  %# rotate image
if (angle==0) 
    angle=360;
end
set(hTxt, 'String',num2str(angle))       %# update text
end

function ok_Callback(hObj, eventdata,I,hTxt,hFig,path1)

global Irot
global angle
set(hTxt, 'String','save')
imwrite(Irot,path1);

delete(hFig);
end
function [angle] = rotationGUI()

I = imread('frames/001.jpg');
%# c
hFig = figure('menu','none');
hAx = axes('Parent',hFig);
global hButton;


hTxt = uicontrol('Style','text', 'Position',[290 28 20 15], 'String','0');
uicontrol('Parent',hFig, 'Style','slider', 'Value',0, 'Min',0,...
    'Max',360, 'SliderStep',[1 10]./360, ...
    'Position',[150 5 300 20], 'Callback',{@slider_callback,I,hAx,hTxt,hFig})

hButton=uicontrol(hFig,'Style','pushbutton','String','Save and Close',...
    'Position',[10 20 120 40],'Callback',{@ok_Callback,I,hTxt,hFig,'frames/001.jpg'});
set(hButton,'Enable','off');



imshow(I, 'Parent',hAx)
    return;
end
    function slider_callback(hObj, eventdata,I,hAx,hTxt,hFig)
global angle
global Irot
global hButton
set(hButton,'Enable','on');
angle = round(get(hObj,'Value'));        %# get rotation angle in degrees

Irot = imrotate(I,angle);
imshow(Irot, 'Parent',hAx)  %# rotate image
if (angle==0) 
    angle=360;
end
set(hTxt, 'String',num2str(angle))       %# update text
end

function ok_Callback(hObj, eventdata,I,hTxt,hFig,path1)

global Irot
global angle
set(hTxt, 'String','save')
imwrite(Irot,path1);

delete(hFig);
end