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

17 ビュー (過去 30 日間)
Hansel Montuffar
Hansel Montuffar 2018 年 12 月 6 日
コメント済み: Kevin Chng 2018 年 12 月 6 日
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 Center および File ExchangeMigrate GUIDE Apps についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by