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

19 views (last 30 days)
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?

Accepted Answer

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

Sign in to comment.

More Answers (0)

Categories

Find more on Migrate GUIDE Apps in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!