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

조회 수: 16 (최근 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 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