我正在研究一个程序,并决定围绕它构建一个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将涉及很多用户与图像的交互)答案 0 :(得分: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。在我的情况下,我使用文本注释和矩形进行ROI选择等等,并且在图像无法正确更新或矩形被卡住方面几乎没有问题...但可能是我没有正确使用它。
希望有所帮助!