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

17 次查看(过去 30 天)
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?

采纳的回答

Kevin Chng
Kevin Chng 2018-12-6
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 个评论
Kevin Chng
Kevin Chng 2018-12-6
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 2018-12-6
could use guidata to handle your output information from the callback.
handles.a = result
guidata(hObject,handles)

请先登录,再进行评论。

更多回答(0 个)

类别

Help CenterFile Exchange 中查找有关 Migrate GUIDE Apps 的更多信息

标签

Community Treasure Hunt

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

Start Hunting!

Translated by