How to update the value in a function with an uicontrol slider?

18 visualizaciones (últimos 30 días)
So I have a GUI that calls a figure to exectute an image processinge function what I want to know is how to update the image according to the value of the slider in the figure
Here I create the figure
img1 = handles.img1;
f = figure;
c = uicontrol(f,'Style','slider');
title('Bin');
c.Callback(@Bin)
So with that I call the function Bin which should takte the slider value as umbral
function bin(umbral, img1)
[ax, ay, az] = size(img1);
imgRes = zeros(ax, ay, az);
for m = 1:ax
for n = 1:ay
for o = 1:az
if (img1(m, n, o)) > umbral
imgRes(m, n, o) = 1.0;
else
imgRes(m, n, o) = 0;
end
end
end
end
imshow(imgRes);
Since is just this plot I rather avoid creating another GUI just for the slider any ideas to how to make it work?

Respuesta aceptada

Kevin Chng
Kevin Chng el 6 de Dic. de 2018
1st Create GUI with Slider and Axes, Create a call back for slider
f=figure;
ax = axes(f);
ax.Position=[0.1 0.2 0.8 0.7]
c = uicontrol(f,'Style','slider','Position',[120 30 300 20],'Callback',@bin);
2nd Create Callback of slider and get value of slider in the callback
function bin(hObject,evendata,hi)
hObject.Value
end
hObject.Value is the value of your slider, then you may proceed to use the value for your image processing.
  3 comentarios
Kevin Chng
Kevin Chng el 6 de Dic. de 2018
f=figure;
ax = axes(f);
ax.Position=[0.1 0.2 0.8 0.7];
im=imread('your image.png');
c = uicontrol(f,'Style','slider','Position',[120 30 300 20],'Callback',{@(u,v)bin(u,v,im)});
function bin(hObject,evendata,hi,image)
hObject.Value
image %your image information
end
Will it help you?
Kevin Chng
Kevin Chng el 6 de Dic. de 2018
could use guidata to handle your output information from the callback.
handles.a = result
guidata(hObject,handles)

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Migrate GUIDE Apps en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by