用户界面 - 如何使用 Matlab GUI 滑块显示图像时间帧



首先,我需要能够使用函数'uigetfile'选择和加载多个图像文件。然后,我需要使用滑块在轴上显示加载图像的连续时间范围。所以问题是,如何将多个图像文件加载到 GUI 中,以及如何使用滑块逐个显示多个图像。我有一种感觉,需要使用"dir"函数来选择"uigetfile"中的多个图像,但我不确定如何实现它。我正在使用指南。

这是图像加载按钮代码。

function loadImagePushButton_Callback(hObject,~,handles)
[fileName,pathName] = uigetfile('*.*');
normalImage = imread(fullfile(pathName,fileName));
handles.normalimage = normalImage;
axes(handles.imageDisplay)
imshow(normalImage)
guidata(hObject,handles)
end

这是用于逐个显示图像的滑块。

function imageFrameSlider_Callback(hObject,~,handles)
normalImage = handles.normalimage;
sliderValue = get(hObject,'Value');
nextImage = %?%?%?% Not sure what to code here
axes(handles.imageDisplay)
imshow(nextImage)
end

最简单的方法是将图像存储在handles变量中,然后您可以从滑块回调中访问它们。

function loadImagePushButton_Callback(hObject,~,handles)
    % Load your images
    [fileName, pathName] = uigetfile('*.*', 'MultiSelect', 'on');
    % Cancel if user hit cancel
    if isequal(fileName, 0); return; end
    % Make sure that fileName is a cell
    if ischar(fileName); fileName = {fileName}; end
    % Load all images into a cell array and store it in the handles structure
    filenames = fullfile(pathName, fileName);
    handles.imagedata = cellfun(@imread, filenames, 'uniformoutput', 0);
    % Display the first one and store the graphics handle to the imshow object
    handles.image = imshow(handles.imagedata{1}, 'Parent', handles.imageDisplay);
    % Update the slider to accomodate all of the images
    set(handles.hslider, 'Min', 1, 'Max', numel(filenames), ...
                         'SliderStep', [1 1]/(numel(filenames) - 1), 'Value', 1)
    % Now save guidata
    guidata(hObject, handles);
end
function imageFrameSlider_Callback(hObject,~,handles)
    % Figure out which image to show
    index = get(hObject, 'Value');
    % Update existing image object in the GUI using this image data
    set(handles.image, 'CData', handles.imagedata{index});  
end

相关内容

  • 没有找到相关文章

最新更新