首先,我需要能够使用'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
答案 0 :(得分:1)
最简单的方法是将图像存储在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