How to use slider bars to view images from a dataset?

34 ビュー (過去 30 日間)
Divya Priyadarshni
Divya Priyadarshni 2019 年 6 月 21 日
コメント済み: Mikhail Haurylau 2020 年 8 月 8 日
Let's say I have loaded a dataset of 100 images and I want to view those images by scrolling the slide bar. If I set my slide bar to 25%( where min limit of slidebar is 0% and max limit is 100%) then 25 images out of 100 should be displayed likewise if I scroll my slidebar upto 89% then 89 images should be displayed. I tried implementing it by loading an array but it doesnt work.
  7 件のコメント
Rik
Rik 2019 年 6 月 27 日
Did either suggestion solve your problem? If so, please consider marking it as accepted answer. It will make it easier for other people with the same question to find an answer. If neither solved your question, please comment with what problems you are still having.
Mikhail Haurylau
Mikhail Haurylau 2020 年 8 月 8 日
Rik, thank you for your answer. It helped a lot.

サインインしてコメントする。

回答 (2 件)

Rik
Rik 2019 年 6 月 22 日
I didn't implement a case for the 0 position, so I just set the range limits from 1 to 100.
%Load an example image
a=imread('cameraman.tif');
%Replicate 100 times
database=repmat(a,1,1,100);
N_images=size(database,3);
%prepare figure and guidata struct
h=struct;
h.f=figure;
h.ax=axes('Parent',h.f,...
'Units','Normalized',...
'Position',[0.1 0.1 0.6 0.8]);
h.slider=uicontrol('Parent',h.f,...
'Units','Normalized',...
'Position',[0.8 0.1 0.1 0.8],...
'Style','Slider',...
'BackgroundColor',[1 1 1],...
'Min',1,'Max',N_images,'Value',1,...
'Callback',@sliderCallback);
%store image database to the guidata struct as well
h.database=database;
guidata(h.f,h)
%trigger a callback
sliderCallback(h.slider)
function sliderCallback(hObject,eventdata)
h=guidata(hObject);
count=round(get(hObject,'Value'));
IM=h.database(:,:,1:count);
IM=permute(IM,[1 2 4 3]);%montage needs the 3rd dim to be the color channel
montage(IM,'Parent',h.ax);
end

Bjorn Gustavsson
Bjorn Gustavsson 2019 年 6 月 21 日
Perhaps have a look at: Imthumb, it might not be exactly what you want, but it might be close enough for you to easily modify...
HTH

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by