如何使用 Matlab GUI 滑块显示图像时间帧
How to use a Matlab GUI slider to display image timeframes
首先,我需要能够 select 并使用函数 'uigetfile' 加载多个图像文件。然后,我需要使用滑块将加载图像的连续时间帧显示到轴上。那么问题来了,如何将多个图像文件加载到GUI中,以及如何使用滑块将多个图像一张一张地显示出来。我感觉 'dir' 函数需要用于 'uigetfile' 中的 select 多个图像,但我不确定如何实现它。我正在使用 GUIDE。
这是图像加载按钮代码。
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
首先,我需要能够 select 并使用函数 'uigetfile' 加载多个图像文件。然后,我需要使用滑块将加载图像的连续时间帧显示到轴上。那么问题来了,如何将多个图像文件加载到GUI中,以及如何使用滑块将多个图像一张一张地显示出来。我感觉 'dir' 函数需要用于 'uigetfile' 中的 select 多个图像,但我不确定如何实现它。我正在使用 GUIDE。
这是图像加载按钮代码。
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