2014-08-28 81 views
1

我正在研究一个程序并决定在其周围构建一个GUI。我想从头开始很简单,加载一个电影,并能够滚动浏览。我已经看过很多关于听众的问题,实际上有人问这个问题,但是那里的解决方案似乎对我没有任何作用。在GUI中的我开启功能 我连续滑块侦听器创建一个新的空白图

  handles.output = hObject; 
     handles.sliderListener = addlistener(handles.Image_Slider,'ContinuousValueChange', ... 
               @(hObject, event) Image_Slider_ContValueCallback(... 
               hObject, eventdata, handles)); 
     % Update handles structure 
     guidata(hObject, handles); 

    And then I have the following two call backs : 
    function Image_Slider_Callback(hObject, eventdata, handles) 
    % hObject handle to Image_Slider (see GCBO) 
    % eventdata reserved - to be defined in a future version of MATLAB 
    % handles structure with handles and user data (see GUIDATA) 
    handles=guidata(hObject); 
    current_slice = round(get(handles.Image_Slider,'Value')); 
    %size(handles.Image_Sequence_Data(:,:,current_slice)); 


im =imagesc(handles.Image_Sequence_Data(:,:,current_slice),'Parent',handles.Image_Sequence_Plot); 
colormap('gray'); 

的正常工作(不听者的一切行为会正确)

,然后我也有

function Image_Slider_ContValueCallback(hObject, eventdata, handles) 
% hObject handle to Image_Slider (see GCBO) 
% eventdata reserved - to be defined in a future version of MATLAB 
% handles structure with handles and user data (see GUIDATA) 
handles=guidata(hObject); 
current_slice = round(get(handles.Image_Slider,'Value')); 
%size(handles.Image_Sequence_Data(:,:,current_slice)); 
handles=guidata(hObject); 

%im = 
imagesc(handles.Image_Sequence_Data(:,:,current_slice),'Parent',handles.Image_Sequence_Plot); 
colormap('gray'); 

,我觉得应该叫当滑块连续移动时。我的问题是每次滑块值改变一个空白(“图1”)出现。实际的GUI数据响应正确,但我不明白为什么/这个'流氓'的数字来自哪里..

有人请帮忙。此外,任何意见imshow与imagesc哪个更好(这个GUI将涉及大量的用户与图像交互)

回答

1

我几乎有同样的问题一次!我没有获得Matlab的现在,所以我不能测试工作的例子,但就目前而言,我建议放置这一行:

handles.sliderListener = addlistener(handles.Image_Slider,'ContinuousValueChange', ... 
               @(hObject, event) Image_Slider_ContValueCallback(... 
               hObject, eventdata, handles)); 
在滑块的CreateFcn

。也许每次移动滑块时都会出现一个空白图形,因为它不知道它已链接到侦听器对象,因此会连续创建一个。

如果它不工作,你可以调用一个函数GUI来更新您的轴显示的当前帧,例如外:

handles.sliderListener = addlistener(handles.Image_Slider,'ContinuousValueChange', ... 
               @(a,b) UpdateCurrentFrame); 

,而不是在你的GUI回调。 a和b是虚拟输入参数,例如,UpdateCurrentFrame可以简单地包含对imshow的调用。这可能不是最优雅的方式,但它对我来说非常合适。

哦,至于你关于imagesc和imshow的问题,我个人更喜欢imshow。在我的情况下,我使用文本注释和矩形进行投资回报率选择等等,并且对于imagesc没有正确更新或长方形被卡住的问题,imagec几乎没有问题......但可能是因为我没有正确使用它。

希望有帮助!

+0

谢谢你的工作完美! – 2014-09-04 00:11:48

+0

非常高兴帮助! – 2014-09-05 01:10:36