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

30 Ansichten (letzte 30 Tage)
Divya Priyadarshni
Divya Priyadarshni am 21 Jun. 2019
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 Kommentare
Rik
Rik am 27 Jun. 2019
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 am 8 Aug. 2020
Rik, thank you for your answer. It helped a lot.

Melden Sie sich an, um zu kommentieren.

Antworten (2)

Rik
Rik am 22 Jun. 2019
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 am 21 Jun. 2019
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