How to update the slider when I need to show different series of images (MATLAB GUI, not programmed)

4 次查看(过去 30 天)
Hello. I have a problem when using the slider to update my images. I have a series of images. I first use the slider to update the images. It works. After some crop of the first series of images, I got another series of images. I wonder When I change my images to the series 2. How to update the slider. Because when I push the slider, it still update the first series images. Thank you.
  3 个评论
Image Analyst
Image Analyst 2017-2-24
And show a screenshot. I don't even have any idea if you're just dispalying one image at a time, or the whole series simultaneously. And what does "update" mean? Does it mean you just display one of the images, or does it mean that you use the slider value to apply some mathematical operation on the image data?
Penny
Penny 2017-2-24
编辑:Penny 2017-2-24
Thanks to Geoff, here is my code, where 'Img' is the first series of the images data. Next, I got the second series of the images. The 3 Matrix data was 'Img_2', and I saved the second series images data into the handles structure. The problem is how to use the 'Img_2' in the slider call back. Because I got the 'Img_2' after I callbcak the slider for the first time.
if true
function slider2_Callback(hObject, eventdata, handles)
% hObject handle to slider2 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
Img=handles.Img;
SIZE_Z=handles.SIZE_Z;
set(hObject,'Min',1,'Max',SIZE_Z);
set(hObject,'SliderStep',[1/(SIZE_Z-1),1/(SIZE_Z-1)]);
slider2Val=floor(get(hObject,'Value'));
currentSlice=slider2Val;
imshow(Img(:,:,currentSlice),[752 1512],'Parent',handles.axes6);
handles.currentSlice=currentSlice;
guidata(hObject,handles);
edit12_Callback(hObject, eventdata, handles);
end

请先登录,再进行评论。

采纳的回答

Geoff Hayes
Geoff Hayes 2017-2-25
Pan - since your slider2_Callback uses the images from handles.Img, then either you will need to replace them with the Img_2 set of images or use a different field within handles to manage the images to be used by this callback. For example, when you initialize handles.Img, then also initialize another field as
handles.sliderImages = handles.Img;
Then your slider callback would do
function slider2_Callback(hObject, eventdata, handles)
Img = handles.sliderImages;
% etc.
And when you initialize handles.Img_2, then you would replace the sliderImages too
handles.sliderImages = handles.Img;
Note that each time you update these images for the slider, you would then update the Min, Max, and SliderStep
set(handles.slider2,'Min',1,'Max',SIZE_Z);
set(handles.slider2,'SliderStep',[1/(SIZE_Z-1),1/(SIZE_Z-1)]);
(rather than updating these values within the callback) where SIZE_Z is the number of images in sliderImages.
  3 个评论

请先登录,再进行评论。

更多回答(0 个)

标签

Community Treasure Hunt

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

Start Hunting!

Translated by