Hi,
I'm experimenting with GUIDE and was wondering how to create a slider that allows the user to fix the threshold value from 0 - 255 of an image.
% --- Executes on slider movement.
function slider1_Callback(hObject, eventdata, handles)
% hObject handle to slider1 (see GCBO)
% eventdata reserved - to be defined in a future version of MATLAB
% handles structure with handles and user data (see GUIDATA)
% Hints: get(hObject,'Value') returns position of slider
% get(hObject,'Min') and get(hObject,'Max') to determine range of slider
global grayImage;
thresholdValue = uint8(get(handles.sldThreshold, 'Value'));
binaryImage= grayImage > thresholdValue;
axes(handles.axes2);

3 comentarios

Walter Roberson
Walter Roberson el 6 de Dic. de 2015
what does get(handles.slider1, 'Max') return?
kelly123
kelly123 el 6 de Dic. de 2015
It returns:
Undefined variable "handles" or function "handles.slider1".
Varian Adisuryo
Varian Adisuryo el 28 de Jul. de 2016
same here. I have the same eror. what should I do?

Iniciar sesión para comentar.

 Respuesta aceptada

Image Analyst
Image Analyst el 6 de Dic. de 2015

0 votos

After the call to axes() in slider1_Callback, you need to call
imshow(binaryImage);

9 comentarios

kelly123
kelly123 el 6 de Dic. de 2015
I did insert that line earlier as I was tinkering around and it still hadn't worked. Is there anything else I could be missing?
This is the error I get:
Reference to non-existent field 'sldThreshold'.
Error in FinalProject>slider1_Callback (line 253) thresholdValue = uint8(get(handles.sldThreshold, 'Value'));
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in FinalProject (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)FinalProject('slider1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Reference to non-existent field 'sldThreshold'.
Error in FinalProject>slider1_Callback (line 253) thresholdValue = uint8(get(handles.sldThreshold, 'Value'));
Error in gui_mainfcn (line 95) feval(varargin{:});
Error in FinalProject (line 42) gui_mainfcn(gui_State, varargin{:});
Error in @(hObject,eventdata)FinalProject('slider1_Callback',hObject,eventdata,guidata(hObject))
Error while evaluating uicontrol Callback
Image Analyst
Image Analyst el 6 de Dic. de 2015
In GUIDE, you need to make the tag property of the slider "sldThreshold".
Or else (less preferred), change sldThreshold to slider1.
kelly123
kelly123 el 6 de Dic. de 2015
Thank you. I changed sldThreshold to slider1, and received no errors when I ran the program. However, when I move my slider, axes2 does not change.
To see what was happening, I changed my call to axes ( handles . axes2 ) to axes1. Then, when I moved my slider, the loaded image disappeared and was replaced with a blank white axes on axes1.
Image Analyst
Image Analyst el 6 de Dic. de 2015
You don't have spaces around the dots, do you? So it's handles.axes2, not handles . axes2, right? And what do you expect to see happening? You're not doing anything with the binary image you create. Like I said originally, if you want to see the binary image you'll need to call
imshow(binaryImage);
Image Analyst
Image Analyst el 6 de Dic. de 2015
What is the value of thresholdValue?
kelly123
kelly123 el 6 de Dic. de 2015
I'm not sure if I set one? Can you give me an example?
Image Analyst
Image Analyst el 6 de Dic. de 2015
After you do this:
thresholdValue = uint8(get(handles.slider1, 'Value'));
put in these lines:
sliderValue = get(handles.slider1, 'Value')
message = sprintf('\nThe slider value = %f\nThe threshold value = %f', sliderValue , thresholdValue);
uiwait(helpdlg(message));
Varian Adisuryo
Varian Adisuryo el 28 de Jul. de 2016
I just did what you told, but when I run it the slider doesn't show and it become like this: Warning: slider control can not have a Value outside of Min/Max range Control will not be rendered until all of its parameter values are valid
what should I do? please help. I've been struggling with this slider for 3 days :(
Adam
Adam el 28 de Jul. de 2016
You can set the min, max and value all in a single set command if you want e.g.
set( handles.slider1, 'Min', 0, 'Max', 10, 'Value', 5 )
to make sure that the value is always within the min to max range and avoid getting that warning. The warning is pretty self-explanatory though from the point of view of knowing what is wrong.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Interactive Control and Callbacks en Centro de ayuda y File Exchange.

Etiquetas

Aún no se han introducido etiquetas.

Preguntada:

el 6 de Dic. de 2015

Comentada:

el 28 de Jul. de 2016

Community Treasure Hunt

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

Start Hunting!

Translated by