Programming Sliders Using Guide

I'm trying to program sliders using guide, and I'm not sure how this will work.
First off, I can't get the slider to become visible when I call a certain function. What I am wanting to do is to allow multiple sliders to become visible for the purpose of iterating through to find the optimal code.
%popupmenu_contrast
str = get(hObject, 'String');
val = get(hObject, 'Value');
% set current contrast operation to the user-selected
switch str{val};
case 'imadjust';
handles.current_contrast = @imadjust;
set(handles.slider1, ...
'Visible', {On},...
'Min', 0, ...
'Max', 1, ...
'Value', 0,...
'SliderStep', [0.05, 0.01]);
set(handles.text_1, 'string', 'low_in')
case 'histeq';
handles.current_contrast = @histeq;
case 'adapthisteq';
handles.current_contrast = @adapthisteq;
case 'imcomplement';
handles.current_contrast = @imcomplement;
end
handles.image2 = handles.current_contrast(handles.image);
imshow(handles.image2, 'Parent', handles.axes2);
% save handles structure
guidata(hObject, handles);
And I'm wondering how I will pass the information from the slider callback function back into this function to properly perform the desired operation.

 Respuesta aceptada

Image Analyst
Image Analyst el 20 de Jul. de 2012

0 votos

It sound like you have a slider where the user can set some kind of parameter. And the parameter means different things depending on what pop-up item is selected. Is that right? So what I'd do is to have a separate function called AdjustImageContrast(), which would take handles as an input argument. Then in the callback for the popup, I'd check the selected item, and if it's "imadjust" I'd first initialize the slider min, max, and value properties since these might be different depending on what popup item was selected. Then after setting up the slider I'd call AdjustImageContrast(handles). Inside AdjustImageContrast, you'd get the slider value via get(handles.slider1, 'value') and do the contrast adjustment code.
Now, what if the user slides the slider instead of selecting a popup item? In that case, you'd do essentially the same thing as the popup callback - check which popup was selected EXCEPT that you don't need to reinitialize the slider since you need to take the current value the user set it to. So if the "imadjust" was already selected, you'd skip the slider initialization and immediately call AdjustImageContrast(handles).
I hope you followed all that.

3 comentarios

Caleb
Caleb el 20 de Jul. de 2012
To your question: yes, that is exactly what I'm trying to do.
I've done switch-case expressions for all of the possible selections in the pop-up menu. Under each case, I have enabled the sliders, text boxes or button groups that I would need and disabled all other objects.
I'm hoping that there is some way to use a global variable for these sliders. I have 4 different dropdown menus (filters, contrast adjusters, morphological operators, edge detectors) and I want to use the same 5 sliders (by re-initializing them depending on which function is called) for the entire program.
Image Analyst
Image Analyst el 20 de Jul. de 2012
I understand. What I said will work. handles is practically a global variable but not quite - that's why you have to pass it into your own functions like AdjustImageContrast() if you want them to access controls like sliders and popup lists. You can use the same 5 sliders for all tasks, just initialize them, or hide them, depending on what popup item was selected.
Caleb
Caleb el 23 de Jul. de 2012
Editada: Caleb el 23 de Jul. de 2012
When using AdjustImageContrast() would I write if-then statements to say the following:
given functions a,b,c,d. User selects (a) and I write an if-then to recognize their pick and then apply the code within AdjustImageContrast(). I'll have four different codes for the four different functions that the user can choose?
Would I even need to code the slider movement functions?

Iniciar sesión para comentar.

Más respuestas (1)

Sean de Wolski
Sean de Wolski el 20 de Jul. de 2012
Editada: Sean de Wolski el 20 de Jul. de 2012
'visible','on',...

9 comentarios

Caleb
Caleb el 20 de Jul. de 2012
Thank you! I knew I was making a simple mistake.
Now how do I get the information from the slider callback to go to the image contrast call back to interactively adjust the image?
Sean de Wolski
Sean de Wolski el 20 de Jul. de 2012
Its value? Are you calling the image contrast callback from within the slider callback? I do not have a good feel for your GUI.
Caleb
Caleb el 20 de Jul. de 2012
Yes. I want to take the value from the slider movement, echo it immediately to the right of the slider, and change the parameters that the sliders are supposed to control.
Sean de Wolski
Sean de Wolski el 20 de Jul. de 2012
Then the easiest and most readable way to do this is to call those callbacks from the end of the slider's callback.
Another way would be to add a listener for 'PostSet' events on the slider but that is sloppy and hard to follow.
Caleb
Caleb el 20 de Jul. de 2012
So when I'm in the adjust contrast callback, I would initialize the sliders. Then I would adjust values, which would be read by the slider callback, and I would be able to call the values from the sliders back to my adjust contrast callback where the values would be implemented as parameters in the code.
Is that right?
No. Just setting the slider value to a new value will not evaluate its callback. It has to be a user interaction to do this.
Instead, adjust the value, and then call the slider callback from within the adjust contrast callback (feed it the necessary inputs etc.).
E.g:
function adjustcontrastcallback(hObject,eventdata,handles)
set(handles.slider,'value',pi)
slider_callback(handles.slider,[],handles)
Caleb
Caleb el 20 de Jul. de 2012
Would I embed the slider callback function into my contrast function?
Sean de Wolski
Sean de Wolski el 20 de Jul. de 2012
I wouldn't.
Caleb
Caleb el 20 de Jul. de 2012
So would I even use the slider callback function automatically generated by guide?

Iniciar sesión para comentar.

Categorías

Más información sobre Creating, Deleting, and Querying Graphics Objects en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 20 de Jul. de 2012

Community Treasure Hunt

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

Start Hunting!

Translated by